{ ***** INPUTs Section *****}
Inputs: BandDays(28), DevConstant(3.500000);
{ ***** VARs Section ***** }
Variables: keltnerTop(0), keltnerMid(0), keltnerBot(0), expSmoothPrice(0);
Variables: expSmoothRange(0);
{ ***** ARRAYs Section *****}
{ ***** CODE Section ***** }
BEGIN
IF (CURRENTBAR = 1) THEN
BEGIN
expSmoothPrice = CLOSE ;
expSmoothRange = HIGH-LOW ;
END ELSE
BEGIN
expSmoothPrice = (expSmoothPrice*(BandDays-1)+CLOSE)/BandDays ;
expSmoothRange = (expSmoothRange*(BandDays-1)+(HIGH-LOW))/BandDays ;
END ;
keltnerTop = expSmoothPrice+(expSmoothRange*DevConstant) ;
keltnerMid = expSmoothPrice ;
keltnerBot = expSmoothPrice-(expSmoothRange*DevConstant) ;
PLOT1 (keltnerTop, "TBand Top") ;
PLOT2 (keltnerMid, "TBand Mid") ;
PLOT3 (keltnerBot, "TBand Bot") ;
END ;
And I convert it like this:
protected override void OnBarUpdate()
{
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
if (CurrentBar == 0)
{
expSmoothPrice = Close[0];
expSmoothRange = High[0] - Low[0];
}
else
{
expSmoothPrice = (expSmoothPrice * (BandDays - 1) + Close[0]) / BandDays;
expSmoothRange = (expSmoothRange * (BandDays - 1) + (High[0] - Low[0])) / BandDays;
}
KeltnerTop.Set(expSmoothPrice + (expSmoothRange * DevConstant));
KeltnerMid.Set(expSmoothPrice);
KeltnerBot.Set(expSmoothPrice - (expSmoothRange * DevConstant));
}
There is a problem first n bars paint. How can i fix it? See the attachment please.
Comment