Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Help] MQL4 code translation #25

Open
wangmingming2003-cn opened this issue Jan 25, 2018 · 0 comments
Open

[Help] MQL4 code translation #25

wangmingming2003-cn opened this issue Jan 25, 2018 · 0 comments

Comments

@wangmingming2003-cn
Copy link

Hello, Everyone,

I am trying to translate a index used in stock market, although I also write it in MQL4 language, but it doesn't work.

I made notes for the original syntax, please help.

[code]
RSV:=(CLOSE-LLV(LOW,5))/(HHV(HIGH,5)-LLV(LOW,5))100; --CLOSE is the close price for the period. HHV is the highest value of the "Highest Value" in the timeframe(in this case, the time frame is 5); And LLV is the lowest value of the "lowest Value" in the timeframe.
K0:=SMA(RSV,3,1); --SMA(x,N,M), the M days moving average;M stands for the weight;for example Y=(xM +(N-M)Y'); Y'is the previous period's SMA;
K:=K0;
D:=SMA(K0,2,1);
J1:(3K0-2D),COLORYELLOW;
J2:MA(J1,2),COLORRED;
MAV:=(2C+H+L)/4; ---C is the latest CLose price;H is the latest Highest Price;L is the latest Lowest price.;
VAR1:=LLV(LOW,21); --the smallest price in the past 21 periods' lowest price
VAR2:=HHV(HIGH,21);--the biggest price in the past 21 periods' highest price
SK: EMA((MAV-VAR1)/(VAR2-VAR1)100,8),COLORWHITE; --EMA is the exponential moving average
SD: EMA(0.667REF(SK,1)+0.333*SK,1),COLORCYAN;

SJ:=3SK-2SD;
50,POINTDOT,COLORRED;
70,POINTDOT,COLORRED;
90,COLOR00AA00;
WWW:SJ<20,COLOR00AA00;
IF(WWW,0,20),COLOR00AA00,LINETHICK2;
[/code]

here is what I wrote in MQL4:

[code]
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"

#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 White
#property indicator_color2 Yellow
#property indicator_color3 LightPink
#property indicator_color4 LightGreen

//---- indicator buffers

double MAV[];
double rsv[];
double VAR1[];
double VAR2[];
double k0[];
double sk0[];
double d0[];
double sd0[];
double j1[];
double j2[];
double sk[];
double sd[];
double sj[];

int init()
{
// IndicatorBuffers(4);
SetIndexDrawBegin(0,30);
SetIndexDrawBegin(1,30);
SetIndexDrawBegin(2,30);
SetIndexDrawBegin(3,30);
//----
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1);
SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,1);
SetIndexStyle(3,DRAW_LINE,STYLE_SOLID,1);
//----
SetIndexBuffer(0,j1);
SetIndexLabel(0,"j1");
SetIndexBuffer(1,j2);
SetIndexLabel(1,"j2");
SetIndexBuffer(2,sk);
SetIndexLabel(2,"sk");
SetIndexBuffer(3,sd);
SetIndexLabel(3,"sd");
// ArraySetAsSeries(fastTrigger, true);
//---- name for DataWindow and indicator subwindow label
//---- initialization done
return(0);
}

int start()
{
int limit;
int i;
limit=Bars-IndicatorCounted();
for (i=0; i<limit; i++)
{
rsv[i]=(Close[i]-Low[iLowest(NULL,0,MODE_LOW,5,i)])/
(High[iHighest(NULL,0,MODE_HIGH,5,i)]-Low[iLowest(NULL,0,MODE_LOW,5,i)])100;
MAV[i]=(2Close[i]+High[i]+Low[i])/4;
VAR1[i]=High[iLowest(NULL,0,MODE_LOW,21,i)];
VAR2[i]=Low[iHighest(NULL,0,MODE_HIGH,21,i)];
}
for (i=0; i<limit; i++)
{
k0[i]=iMAOnArray(rsv,0,3,1,MODE_SMMA,i);
sk0[i]=(MAV[i]-VAR1[i])/(VAR2[i]-VAR1[i])100;
}
for (i=0; i<limit; i++)
{
d0[i]=iMAOnArray(k0,0,2,1,MODE_SMMA,i);
sd0[i]=0.667sk[i+1]+0.333sk[i];
}
for (i=0; i<limit; i++)
{
j1[i]=3k0[i]-2d0[i];
}
for (i=0; i<limit; i++)
{
j2[i]=iMAOnArray(j1,0,2,0,MODE_SMA,i);;
}
for (i=0; i<limit; i++)
{
sk[i]=iMAOnArray(sk0,0,8,0,MODE_EMA,i);
sd[i]=iMAOnArray(sd0,0,1,0,MODE_EMA,i);
sj[i]=3sk[i]-2*sd[i];
}
return(0);
}
[/code]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant