Auto-adaptive Ergotic Candlestick Oscillator

#1
Im trying to convert this modified (and auto-adaptive) version of the Ergotic Candlestick Oscillator from metastock. Instead the original formula of Ergodic Candlestick oscillator this formula uses the length of a scaled stochastic indicator VRB:= Abs( Stoch(LE,1)-50)/50; and an exponent to obtain the variable moving average.

Im not able to convert the PREV function implemented needed to calculate in metastock the variable moving average useful to calculate the Close-Open variables during each session (fifth line) and consequently the other variables that takes into account the variations of maximum and minimum price (sixth line content) etc. Any help is higly appreciated.

AUTO ADAPTIVE ERGODIC CANDLESTICK OSCILLATOR



LE:=Input("LENGHT",1,200,14);

Exp:=Input("Exponent",1,200,5);

VRB:= Abs( Stoch(LE,1)-50)/50;

MEsp:=2/(Esp+1);

CaMe1:=If(Cum(1)<=((Le+Exp)*2),C-O,PREV+MEsp*VRB*((C-O)-PREV));

CaMe2:=If(Cum(1)<=((Le+Exp)*2),H-L,PREV+MEsp*VRB*((H-L)-PREV));

CaMe11:=If(Cum(1)<=((Le+Exp)*2),CaMe1,PREV+MEsp*VRB*(CaMe1-PREV));

CaMe22:=If(Cum(1)<=((Le+Exp)*2),CaMe2,PREV+MEsp*VRB*(CaMe2-PREV));

ECO:=CaMe11/CaMe22*100;

ECO;

0
 
#2
hi friend

The following line doesnt seem to be ok.
MEsp=2/(Esp+1);
Esp is not defined.

can you check if there is error?

==============================================================================
Regarding PREV function,it is no big deal.
===============================================
quote=I had to read up on the PREV function in MetaStock. That is one of the
strangest coding implementations for a programming language syntax I've ever
seen:



The PREV constant is used in a custom indicator to reference the previous
output of the same formula. The PREV constant represents the value for the
previous time period ONLY FOR THE STATEMENT IN WHICH IT EXISTS.



Since the PREV function needs the previous bar's value of itself it's
actually a recursive function. I suggest you determine the values for the
first condition, fill in the rest of the values with the last good value of
the first condition, then use that array for your second condition values:

//=============example=========
function PREV(arr)
{
if (BarIndex>0) return ref(arr,-1);
else return 0;
}
prc = (H+L+C)/3;
CP = prc + PREV(prc);

===============================================================
cheers
ford
 
Last edited:
#4
hi friend

The following line doesnt seem to be ok.
MEsp=2/(Esp+1);
Esp is not defined.

can you check if there is error?

==============================================================================
Regarding PREV function,it is no big deal.
===============================================
quote=I had to read up on the PREV function in MetaStock. That is one of the
strangest coding implementations for a programming language syntax I've ever
seen:



The PREV constant is used in a custom indicator to reference the previous
output of the same formula. The PREV constant represents the value for the
previous time period ONLY FOR THE STATEMENT IN WHICH IT EXISTS.



Since the PREV function needs the previous bar's value of itself it's
actually a recursive function. I suggest you determine the values for the
first condition, fill in the rest of the values with the last good value of
the first condition, then use that array for your second condition values:

//=============example=========
function PREV(arr)
{
if (BarIndex>0) return ref(arr,-1);
else return 0;
}
prc = (H+L+C)/3;
CP = prc + PREV(prc);

===============================================================
cheers
ford
Dear Ford thanks for your reply. Yes there is an error into the formula. Exp instead esp. (thanks also to extremist).
 

KelvinHand

Well-Known Member
#6
hi friend

The following line doesnt seem to be ok.
MEsp=2/(Esp+1);
Esp is not defined.

can you check if there is error?

==============================================================================
Regarding PREV function,it is no big deal.
===============================================
quote=I had to read up on the PREV function in MetaStock. That is one of the
strangest coding implementations for a programming language syntax I've ever
seen:



The PREV constant is used in a custom indicator to reference the previous
output of the same formula. The PREV constant represents the value for the
previous time period ONLY FOR THE STATEMENT IN WHICH IT EXISTS.



Since the PREV function needs the previous bar's value of itself it's
actually a recursive function. I suggest you determine the values for the
first condition, fill in the rest of the values with the last good value of
the first condition, then use that array for your second condition values:

//=============example=========
function PREV(arr)
{
if (BarIndex>0) return ref(arr,-1);
else return 0;
}
prc = (H+L+C)/3;
CP = prc + PREV(prc);

===============================================================
cheers
ford
PREV is a recursive statement in metastock. Can not implement in such simple as you stated in a function and solve the problem in amibroker. Usually it required looping statements.

The PREV example for Amibroker is here:
http://www.traderji.com/amibroker/73165-need-trend-continuation-factor.html
 
Last edited:
#7
Hi KELVIN

Thank you for the valuable viewpoint.
I agree as you rightly pointed out,it is not so easy and it involves looping.
We will give a try.sure it may take time.
All this is due to the fact metastock does not have looping FACILITY and they use PREV.

THERE IS WAY TO BYPASS THE LOOPING

There is a second option of using AMA2 oR AMA for PREV.
At this moment no idea how to go with this option.
Actually this area falls into Subroto,s territory.
----------------------------------------------------------
HERE IS A POINTER FROM TOMASZ
---------------------------------------
function

Conversion to loop is pretty straightforward.
1. Create standard loop
2. define temporary variables for PREV "emulation"
3. Re-type the MS line with CC instead of C AND IIf instead of if,

if((C*.97)>PREV,C*.97,if((C*1.03)<PREV,C*1.03,PREV))

to:

result = 0;

for( i = 1; i < BarCount; i++ )
{
PREV = result[ i - 1 ];
CC = C[ i ];
result[ i ] = IIf( (CC*0.97) > PREV, CC*0.97, IIf((CC*1.03) <
PREV, CC*1.03, PREV));
}

// It is longer than MS code but... advantage is that it runs 100 times faster.
 
#8
Hi subroto

please have a look at the looping for PREV .
actually,there is a simpler option of replacing PREV by AMA.
It seems the looping can be easily bypassed by using AMA,
But I am not aware what factors go into AMA
thanks
regards
ford
Here IS A ERGODIC OSCILLATOR CODE in simple terms
---------------------------------------------------------------------------
//ECO - Ergodic Candlestick Oscillator

//ECO =(MOV(MOV(C-O,5,E))26,E)/MOV(MOV(H-L,5,E))26,E))*100
K=C-O; KK =H-L;
ECO1 =(EMA(EMA(K,5),26)/EMA(EMA(KK,5),26))*100 ;

Plot(ECO1,"ECO1",colorCustom12,styleThick);
Plot(0,"ZERO",colorRed,styleLine);
-----------------------------------------------------------------------
 
Last edited:

KelvinHand

Well-Known Member
#9
Sure same as MS.
Code:
//-- Create by KelvinHand ---
LE=Param("LENGHT",14,1,200);
Esp=Param("Exponent",5, 1,200);
//-- for Traderji.com
VRB= abs( StochK(LE,1)-50)/50;

MEsp=2/(Esp+1);

C_O = C-O;
H_L = H-L;

C1 = Cum(1)<=((Le+Esp)*2);

i=0;
CaMe1[i]=0;
CaMe2[i]=0;
i++;
for(;i<BarCount; i++)
{
  prev1 = CaMe1[i-1];
  prev2 = CaMe2[i-1];


  if (C1[i])
  {
      CaMe1[i]=C_O[i];
      CaMe2[i]=H_L[i];

  }
  else
  {
      CaMe1[i]=PREV1+MEsp[i]*VRB[i]*(C_O[i]-PREV1);
      CaMe2[i]=PREV2+MEsp[i]*VRB[i]*(H_L[i]-PREV2);

  }
}


i=0;
CaMe11[i]=0;
CaMe22[i]=0;
i++;

for(;i<BarCount; i++)
{
  prev1 = CaMe11[i-1];
  prev2 = CaMe22[i-1];


  if (C1[i])
  {
      CaMe11[i]=CaMe1[i];
      CaMe22[i]=CaMe2[i];

  }
  else
  {
      CaMe11[i]=PREV1+MEsp[i]*VRB[i]*(CaMe1[i]-PREV1);
      CaMe22[i]=PREV2+MEsp[i]*VRB[i]*(CaMe2[i]-PREV2);

  }
}

ECO=CaMe11/CaMe22*100;

Plot(ECO, "Auto-adaptive Ergotic Candlestick Oscillator", colorRed);
Plot(0, "", colorGrey50);
 
Last edited:

sr114

Well-Known Member
#10
Hi subroto

please have a look at the looping for PREV .
actually,there is a simpler option of replacing PREV by AMA.
It seems the looping can be easily bypassed by using AMA,
But I am not aware what factors go into AMA
thanks
regards
ford
Here IS A ERGODIC OSCILLATOR CODE in simple terms
---------------------------------------------------------------------------
//ECO - Ergodic Candlestick Oscillator

//ECO =(MOV(MOV(C-O,5,E))26,E)/MOV(MOV(H-L,5,E))26,E))*100
K=C-O; KK =H-L;
ECO1 =(EMA(EMA(K,5),26)/EMA(EMA(KK,5),26))*100 ;

Plot(ECO1,"ECO1",colorCustom12,styleThick);
Plot(0,"ZERO",colorRed,styleLine);
-----------------------------------------------------------------------
pleas go thru this posting for the explanation pf ms PREV function to be ported in ami.

http://www.mail-archive.com/[email protected]/msg11911.html

rgds
subroto
 

Similar threads