Good morning forum,
Below is a script that I added an alert that is triggering a buy & sell message at the same time whenever I open a chart which to me doesn't make sense...I thought that the condition would only look at the last met condition and trigger a buy or sell message.
plot turning_point = if concavity[1] != concavity then HMA else double.nan;
HMA.AssignValueColor(Color = if concavity[1] == -1 then
if HMA > HMA[1] then color.black else color.blue else
if HMA < HMA[1] then color.yellow else color.orange);
plot MA_Max = if HMA[-1] < HMA and HMA > HMA[1] then HMA else Double.NaN;
MA_Max.SetDefaultColor(Color.WHITE);
MA_Max.SetPaintingStrategy(PaintingStrategy.SQUARES);
MA_Max.SetLineWeight(3);
plot MA_Min = if HMA[-1] > HMA and HMA < HMA[1] then HMA else Double.Nan;
MA_Min.SetDefaultColor(Color.WHITE);
MA_Min.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
MA_Min.SetLineWeight(3);
plot sell = if turning_point and concavity == -1 then high else double.nan;
sell.SetDefaultColor(Color.blue);
sell.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
sell.SetLineWeight(1);
plot buy = if turning_point and concavity == 1 then low else double.nan;
buy.SetDefaultColor(Color.orange);
buy.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
buy.SetLineWeight(1);
def ROC = HMA - next_bar;
addLabel(yes and labels, concat("ROC: " , ROC), color = if concavity < 0 then if ROC[1] > ROC then Color.blue else color.black else if ROC[1] < ROC then color.orange else color.red);
Looks like the bug is that condition1 and condition2 are always true. I haven't programmed in ThinkScript what does HMA[-1] mean in this context?
I assume HMA is the current value, same as HMA[0] and HMA[1] is the previous value, is HMA[-1] the value in the next time period? If that's the case the next time period does not yet exist at the moment you load the chart so isnan always returns true, which results in the bug you're experiencing.
The following 2 users say Thank You to ivoTrades for this post: