Jump to content

Recommended Posts

Posted

can anyone translate this mt4 code to eld

 

 

//+------------------------------------------------------------------+

//| 3x Stochastic.mq4 |

//+------------------------------------------------------------------+

 

 

#property indicator_separate_window

#property indicator_buffers 4

#property indicator_color1 Silver

#property indicator_style1 STYLE_DOT

#property indicator_color2 Yellow //Neutral

#property indicator_color3 Lime //UPPER

#property indicator_color4 Red //LOWER

#property indicator_width2 2

#property indicator_width3 2

#property indicator_width4 2

#property indicator_minimum 0

#property indicator_maximum 100

#property indicator_level1 20

#property indicator_level2 80

 

//---- indicator parameters

extern int Sto_Period = 21;

extern int Smooth = 9;

extern int Signal = 9;

 

//---- indicator buffers

double Sto[];

double Sig[];

double Upper[];

double Lower[];

//----

double tmp[][12];

int draw_begin, pBars, mcnt_bars;

string TF, fast_name;

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

int init()

{

//---- drawing settings

SetIndexStyle(0,DRAW_LINE);

SetIndexStyle(1,DRAW_LINE);

SetIndexStyle(2,DRAW_LINE);

SetIndexStyle(3,DRAW_LINE);

draw_begin=Sto_Period+Smooth+Signal;

//---- indicator name

 

IndicatorShortName("3x Stochastic ("+Sto_Period+","+Smooth+","+Signal+")");

 

 

SetIndexLabel(0,"Sto");

SetIndexLabel(1,"Sig");

SetIndexLabel(2,NULL);

SetIndexLabel(3,NULL);

//---- indicator buffers mapping

SetIndexBuffer(0,Sto);

SetIndexBuffer(1,Sig);

SetIndexBuffer(2,Upper);

SetIndexBuffer(3,Lower);

 

 

SetIndexDrawBegin(0,draw_begin);

SetIndexDrawBegin(1,draw_begin);

SetIndexDrawBegin(2,draw_begin);

SetIndexDrawBegin(3,draw_begin);

//---- initialization done

 

return(0);

}

 

int start()

{

int limit, y, i, shift, cnt_bars=IndicatorCounted();

double K[], mSto[], mSig[];

 

int mBars = iBars(NULL,0);

 

if(mBars != pBars)

{

ArrayResize(K,mBars);

ArrayResize(mSto,mBars);

ArrayResize(mSig,mBars);

ArrayResize(tmp,mBars);

pBars = mBars;

}

 

if(cnt_bars<1)

{

for(i=1;i<=draw_begin;i++) {Sto[bars-i]=0; Sig[bars-i]=0;}

mcnt_bars = 1;

}

 

if(mcnt_bars > 1) mcnt_bars--;

 

for(y=mcnt_bars-1;y<mBars;y++)

{

shift = mBars-y-1;

double aPrice = iMA(NULL,0,1,0,0,0,shift);

double up = 0;

double dn = 10000000000;

for(i=0;i<Sto_Period;i++)

{

up = MathMax(up,iHigh(NULL,0,shift+i));

dn = MathMin(dn,iLow(NULL,0,shift+i));

}

 

if(up-dn > 0) K[y] = 100*(aPrice - dn)/(up - dn); else K[y] = 0;

 

mSto[y] = Ensign(K[y],mSto,Smooth,y);

mSig[y] = Ensign(mSto[y],mSig,Signal,y);

 

Sto[shift] = mSto[y];

Sig[shift] = mSig[y];

 

// Colors

if (Sig[shift] > Sig[shift+1]) { Upper[shift] = Sig[shift]; Upper[shift+1] = Sig[shift+1]; }

else { Upper[shift] = EMPTY_VALUE;

if (Upper[shift+2] == EMPTY_VALUE)

Upper[shift+1] = EMPTY_VALUE; }

if (Sig[shift] < Sig[shift+1]) { Lower[shift] = Sig[shift]; Lower[shift+1] = Sig[shift+1]; }

else { Lower[shift] = EMPTY_VALUE;

if (Lower[shift+2] == EMPTY_VALUE)

Lower[shift+1] = EMPTY_VALUE; }

}

 

mcnt_bars = mBars-1;

 

return(0);

}

 

 

// Ensign smooth !

double Ensign(double price,double array[],int per,int bar)

{

if(bar == 2) double ema = price;

else

if(bar > 2) ema = array[bar-1] + 1.0/(per)*(price - array[bar-1]);

//if(bar > 2) ema = array[bar-1] + 2.0/(1+per)*(price - array[bar-1]); EMA - classic formula

 

return(ema);

}

 

thanks

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...