Hiho all forex traders and fellow MT4 programmers,
lately I was working on an indicator which should show me consolidation lines. Here is how it *should* work:
1.There is a cross of 2 MA's (any type i.e. SMA, EMA, etc.);
2.Right after ther cross we start to draw line.
3.When the price (I am using Close) crosses the line we stop drawing the line.
Here is the code I came up with *BUT* it is working strane however. Sometimes only one dot occurs and the ind. stops to draw more (the line I am talking about is made of dots). Can you tell me what is wrong with my code (Corss func. which is imported from my library is excactly the same as one in developing course in this forum, btw. thanks for this course) ?
Quote:
int start()
{
int counted_bars=IndicatorCounted();
//----
time=Bars;
ArrayResize(tempUPL, time);
for(i=time;i>0;i--){
MA1=NormalizeDouble(iCustom(NULL,0,"Moving_Average ",MA1Period,MA1Price,MA1Type,0,i),4);
MA2=NormalizeDouble(iCustom(NULL,0,"Moving_Average ",MA2Period,MA2Price,MA2Type,0,i),4);
ConsEntry=Cross1(MA1,MA2);
if(ConsEntry!=0){
ConsPrice=iClose(NULL,0,i);
ConsCond=1;
ConsExit = 0;
tempUPL[i]=ConsPrice+(Consolidation/2)*Point;
}
if(ConsCond==1){
if(Cross2(UPL[i],iClose(NULL,0,i))!=0){
ConsExit=1;
ConsCond=0;
}
}
if(ConsCond==1 || ConsExit==1){
tempUPL[i]=ConsPrice+(Consolidation/2)*Point;
}
if(ConsCond!=0 || ConsExit!=0){
UPL[i]=tempUPL[i];
} else if (ConsCond==0 && ConsExit==0) {
UPL[i]=0;
}
ConsEntry=0;
ConsExit=0;
}
|
where Moving_Average is my own version of MA and I know that it is working 100% correctly.
Please help me if you can. Thank you in advance!