Gaps or breaks in Indicator line

 

I guess I dont understand this part of building an indicator as well as I thought.

I want to have a single price line, with three different colors, bullish, bearish, or neutral.

In the beginning I thought it was easy, since I had looked at the slopeline indicator as an example, which just sets the opposing buffer to EMPTY_VALUE when it sets a value to the active buffer. There is no gaps

and no problems doing this with slopeline.

So now I'm trying it with 3 buffers, and each time I set a value I set the other two buffers to EMPTY_VALUE, and I have gaps. Comment those lines out, still have gaps.

Try to set the last buffer to the value of the previous bar so they overlap by one, still gaps. I'm losing my mind trying to work this out. I've searched on google looking for good forums for info, no luck. Here I found a couple posts that looked promising but didnt help. MissPips had a similar problem but must've worked it out on her own. If anyone can point me to a post that will help or tell me what I'm doing wrong I'd appreciate it! BTW already downloaded the iFatWorm indi and it didnt work when I loaded it on the chart.

//scenario #1 Price is above both MAs

if (Close[i]>=fMA && Close[i]>= sMA)

//if (Close[i]>=fMA || Close[i]>= sMA)

{ //5A.

//ok so which MA is closest?

if (fastUp)

{ //6A.

upPrice[i]=Close[i]-fMA;

dnPrice[i]=EMPTY_VALUE;

neuPrice[i]=EMPTY_VALUE;

if(neuPrice[i+1]!=EMPTY_VALUE && upPrice[i+1]==EMPTY_VALUE)neuPrice[i]=Close[i]-fMA;

if(i==0&&Bid-fMA< touchWarn)customAlert(alertHeader() + "is about to touch!");

}// 6B END if (fastUp)

else

{ //7A.

upPrice[i]=Close[i]-sMA;

dnPrice[i]=EMPTY_VALUE;

neuPrice[i]=EMPTY_VALUE;

if(neuPrice[i+1]!=EMPTY_VALUE && upPrice[i+1]==EMPTY_VALUE)neuPrice[i]=Close[i]-sMA;

if(i==0&&Bid-sMA< touchWarn)customAlert(alertHeader() + "is about to touch!");

} // 7B END else if fastUp

}//5B END if (Close[i]>fMA && Close[i]> sMA)

//scenario #2 Price is BELOW both MAs

if (Close[i]<=fMA && Close[i]<= sMA)

//if (Close[i]<=fMA || Close[i]<= sMA)

{ //8A.

//ok so which MA is closest?

if (fastUp)

{ //9A.

dnPrice[i]=MathAbs(Close[i]-sMA);

if(neuPrice[i+1]!=EMPTY_VALUE && dnPrice[i+1]==EMPTY_VALUE)neuPrice[i]=MathAbs(Close[i]-sMA);

upPrice[i]=EMPTY_VALUE;

neuPrice[i]=EMPTY_VALUE;

if(i==0&&sMA-Bid < touchWarn)customAlert(alertHeader() + "is about to touch!");

}//9B END if (fastUp)

else

{ //10A.

dnPrice[i]=MathAbs(Close[i]-fMA);

if(neuPrice[i+1]!=EMPTY_VALUE && dnPrice[i+1]==EMPTY_VALUE)neuPrice[i]=MathAbs(Close[i]-fMA);

if(i==0&&fMA-Bid< touchWarn)customAlert(alertHeader() + "is about to touch!");

upPrice[i]=EMPTY_VALUE;

neuPrice[i]=EMPTY_VALUE;

} //10B END else if fastUp

}//8B END if (Close[i]<fMA && Close[i]< sMA)

//scenario #3 Price is in between both MAs

if ((Close[i]>=fMA && Close[i]<= sMA) || (Close[i]<=fMA && Close[i]>= sMA))

{ // 11A.

//ok so which MA is closest?

if (fastUp)

{ //12A.

fPrDelta=MathAbs(Close[i]-fMA);

sPrDelta=Close[i]-sMA;

if (fPrDelta<sPrDelta)

{ //13A.

neuPrice[i]=fPrDelta;

if(dnPrice[i+1]!=EMPTY_VALUE && neuPrice[i+1]==EMPTY_VALUE)dnPrice[i]=fPrDelta;

if(upPrice[i+1]!=EMPTY_VALUE && neuPrice[i+1]==EMPTY_VALUE)upPrice[i]=fPrDelta;

upPrice[i]=EMPTY_VALUE;

dnPrice[i]=EMPTY_VALUE;

if(i==0&&fMA-Bid< touchWarn)customAlert(alertHeader() + "is about to touch!");

}// 13B END if (fPrDelta<sPrDelta)

else

{ //14A.

neuPrice[i]=sPrDelta;

if(dnPrice[i+1]!=EMPTY_VALUE && neuPrice[i+1]==EMPTY_VALUE)dnPrice[i]=sPrDelta;

if(upPrice[i+1]!=EMPTY_VALUE && neuPrice[i+1]==EMPTY_VALUE)upPrice[i]=sPrDelta;

upPrice[i]=EMPTY_VALUE;

dnPrice[i]=EMPTY_VALUE;

if(i==0&&Bid-sMA< touchWarn)customAlert(alertHeader() + "is about to touch!");

} // 14B END ELSE if (fPrDelta<sPrDelta)

}// 12B END if (fastUp)

else // not fastup

{ //15A.

sPrDelta=MathAbs(Close[i]-fMA);

fPrDelta=Close[i]-sMA;

if (fPrDelta<sPrDelta)

{ //16A.

neuPrice[i]=fPrDelta;

if(dnPrice[i+1]!=EMPTY_VALUE && neuPrice[i+1]==EMPTY_VALUE)dnPrice[i]=fPrDelta;

if(upPrice[i+1]!=EMPTY_VALUE && neuPrice[i+1]==EMPTY_VALUE)upPrice[i]=fPrDelta;

upPrice[i]=EMPTY_VALUE;

dnPrice[i]=EMPTY_VALUE;

if(i==0&&Bid-fMA< touchWarn)customAlert(alertHeader() + "is about to touch!");

}//16B END if (fPrDelta<sPrDelta)

else

{// 17A.

neuPrice[i]=sPrDelta;

if(dnPrice[i+1]!=EMPTY_VALUE && neuPrice[i+1]==EMPTY_VALUE)dnPrice[i]=sPrDelta;

if(upPrice[i+1]!=EMPTY_VALUE && neuPrice[i+1]==EMPTY_VALUE)upPrice[i]=sPrDelta;

upPrice[i]=EMPTY_VALUE;

dnPrice[i]=EMPTY_VALUE;

if(i==0&&sMA-Bid< touchWarn)customAlert(alertHeader() + "is about to touch!");

} //17B END ELSE if (fPrDelta<sPrDelta)

} //15B END else if fastUp

Files:
lma_delta.mq4  11 kb
 
MicksMoney:

I guess I dont understand this part of building an indicator as well as I thought.

I want to have a single price line, with three different colors, bullish, bearish, or neutral.

In the beginning I thought it was easy, since I had looked at the slopeline indicator as an example, which just sets the opposing buffer to EMPTY_VALUE when it sets a value to the active buffer. There is no gaps

and no problems doing this with slopeline.

So now I'm trying it with 3 buffers, and each time I set a value I set the other two buffers to EMPTY_VALUE, and I have gaps. Comment those lines out, still have gaps.

Try to set the last buffer to the value of the previous bar so they overlap by one, still gaps. I'm losing my mind trying to work this out. I've searched on google looking for good forums for info, no luck. Here I found a couple posts that looked promising but didnt help. MissPips had a similar problem but must've worked it out on her own. If anyone can point me to a post that will help or tell me what I'm doing wrong I'd appreciate it! BTW already downloaded the iFatWorm indi and it didnt work when I loaded it on the chart.

//scenario #1 Price is above both MAs

if (Close[i]>=fMA && Close[i]>= sMA)

//if (Close[i]>=fMA || Close[i]>= sMA)

{ //5A.

//ok so which MA is closest?

if (fastUp)

{ //6A.

upPrice[i]=Close[i]-fMA;

dnPrice[i]=EMPTY_VALUE;

neuPrice[i]=EMPTY_VALUE;

if(neuPrice[i+1]!=EMPTY_VALUE && upPrice[i+1]==EMPTY_VALUE)neuPrice[i]=Close[i]-fMA;

if(i==0&&Bid-fMA< touchWarn)customAlert(alertHeader() + "is about to touch!");

}// 6B END if (fastUp)

else

{ //7A.

upPrice[i]=Close[i]-sMA;

dnPrice[i]=EMPTY_VALUE;

neuPrice[i]=EMPTY_VALUE;

if(neuPrice[i+1]!=EMPTY_VALUE && upPrice[i+1]==EMPTY_VALUE)neuPrice[i]=Close[i]-sMA;

if(i==0&&Bid-sMA< touchWarn)customAlert(alertHeader() + "is about to touch!");

} // 7B END else if fastUp

}//5B END if (Close[i]>fMA && Close[i]> sMA)

//scenario #2 Price is BELOW both MAs

if (Close[i]<=fMA && Close[i]<= sMA)

//if (Close[i]<=fMA || Close[i]<= sMA)

{ //8A.

//ok so which MA is closest?

if (fastUp)

{ //9A.

dnPrice[i]=MathAbs(Close[i]-sMA);

if(neuPrice[i+1]!=EMPTY_VALUE && dnPrice[i+1]==EMPTY_VALUE)neuPrice[i]=MathAbs(Close[i]-sMA);

upPrice[i]=EMPTY_VALUE;

neuPrice[i]=EMPTY_VALUE;

if(i==0&&sMA-Bid < touchWarn)customAlert(alertHeader() + "is about to touch!");

}//9B END if (fastUp)

else

{ //10A.

dnPrice[i]=MathAbs(Close[i]-fMA);

if(neuPrice[i+1]!=EMPTY_VALUE && dnPrice[i+1]==EMPTY_VALUE)neuPrice[i]=MathAbs(Close[i]-fMA);

if(i==0&&fMA-Bid< touchWarn)customAlert(alertHeader() + "is about to touch!");

upPrice[i]=EMPTY_VALUE;

neuPrice[i]=EMPTY_VALUE;

} //10B END else if fastUp

}//8B END if (Close[i]<fMA && Close[i]< sMA)

//scenario #3 Price is in between both MAs

if ((Close[i]>=fMA && Close[i]<= sMA) || (Close[i]<=fMA && Close[i]>= sMA))

{ // 11A.

//ok so which MA is closest?

if (fastUp)

{ //12A.

fPrDelta=MathAbs(Close[i]-fMA);

sPrDelta=Close[i]-sMA;

if (fPrDelta<sPrDelta)

{ //13A.

neuPrice[i]=fPrDelta;

if(dnPrice[i+1]!=EMPTY_VALUE && neuPrice[i+1]==EMPTY_VALUE)dnPrice[i]=fPrDelta;

if(upPrice[i+1]!=EMPTY_VALUE && neuPrice[i+1]==EMPTY_VALUE)upPrice[i]=fPrDelta;

upPrice[i]=EMPTY_VALUE;

dnPrice[i]=EMPTY_VALUE;

if(i==0&&fMA-Bid< touchWarn)customAlert(alertHeader() + "is about to touch!");

}// 13B END if (fPrDelta<sPrDelta)

else

{ //14A.

neuPrice[i]=sPrDelta;

if(dnPrice[i+1]!=EMPTY_VALUE && neuPrice[i+1]==EMPTY_VALUE)dnPrice[i]=sPrDelta;

if(upPrice[i+1]!=EMPTY_VALUE && neuPrice[i+1]==EMPTY_VALUE)upPrice[i]=sPrDelta;

upPrice[i]=EMPTY_VALUE;

dnPrice[i]=EMPTY_VALUE;

if(i==0&&Bid-sMA< touchWarn)customAlert(alertHeader() + "is about to touch!");

} // 14B END ELSE if (fPrDelta<sPrDelta)

}// 12B END if (fastUp)

else // not fastup

{ //15A.

sPrDelta=MathAbs(Close[i]-fMA);

fPrDelta=Close[i]-sMA;

if (fPrDelta<sPrDelta)

{ //16A.

neuPrice[i]=fPrDelta;

if(dnPrice[i+1]!=EMPTY_VALUE && neuPrice[i+1]==EMPTY_VALUE)dnPrice[i]=fPrDelta;

if(upPrice[i+1]!=EMPTY_VALUE && neuPrice[i+1]==EMPTY_VALUE)upPrice[i]=fPrDelta;

upPrice[i]=EMPTY_VALUE;

dnPrice[i]=EMPTY_VALUE;

if(i==0&&Bid-fMA< touchWarn)customAlert(alertHeader() + "is about to touch!");

}//16B END if (fPrDelta<sPrDelta)

else

{// 17A.

neuPrice[i]=sPrDelta;

if(dnPrice[i+1]!=EMPTY_VALUE && neuPrice[i+1]==EMPTY_VALUE)dnPrice[i]=sPrDelta;

if(upPrice[i+1]!=EMPTY_VALUE && neuPrice[i+1]==EMPTY_VALUE)upPrice[i]=sPrDelta;

upPrice[i]=EMPTY_VALUE;

dnPrice[i]=EMPTY_VALUE;

if(i==0&&sMA-Bid< touchWarn)customAlert(alertHeader() + "is about to touch!");

} //17B END ELSE if (fPrDelta<sPrDelta)

} //15B END else if fastUp


Update:

Got it to work better, although ALL the gaps are not gone, most of them are. The rest might just be regular "drawing" bugs that will go away eventually. Here is a snippet of the code that FINALLY worked

the way I wanted:

//scenario #1 Price is above both MAs

if (Close[i]>=fMA && Close[i]>= sMA)

//if (Close[i]>=fMA || Close[i]>= sMA)

{ //5A.

//ok so which MA is closest?

if (fastUp)

{ //6A.

upPrice[i]=Close[i]-fMA;

//dnPrice[i]=EMPTY_VALUE;

//neuPrice[i]=EMPTY_VALUE;

if(i>0&&neuPrice[i-1]!=EMPTY_VALUE && upPrice[i-1]==EMPTY_VALUE)neuPrice[i]=Close[i]-fMA;

if(i==0&&Bid-fMA< touchWarn)customAlert(alertHeader() + "is about to touch!");

}// 6B END if (fastUp)

else

{ //7A.

upPrice[i]=Close[i]-sMA;

//dnPrice[i]=EMPTY_VALUE;

//neuPrice[i]=EMPTY_VALUE;

if(i>0&&neuPrice[i-1]!=EMPTY_VALUE && upPrice[i-1]==EMPTY_VALUE)neuPrice[i]=Close[i]-sMA;

if(i==0&&Bid-sMA< touchWarn)customAlert(alertHeader() + "is about to touch!");

} // 7B END else if fastUp

}//5B END if (Close[i]>fMA && Close[i]> sMA)