ny, ny/us
Posts: 3 since Aug 2019
Thanks Given: 1
Thanks Received: 0
|
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.
code:
declare upper;
input price = CLOSE;
input HMA_Length = 8;
input lookback = 2;
input labels=no;
plot HMA = HullMovingAvg(price = price, length = HMA_Length);
def delta = HMA[1] - HMA[lookback + 1];
def delta_per_bar = delta / lookback;
def next_bar = HMA[1] + delta_per_bar;
def concavity = if HMA > next_bar then 1 else -1;
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);
HMA.SetLineWeight(4);
turning_point.SetLineWeight(4);
turning_point.SetPaintingStrategy(paintingStrategy = PaintingStrategy.POINTS);
turning_point.SetDefaultColor(color.white);
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);
def arrow_plots = high-low;
def plothigh = high + arrow_plots * 0.3;
def plotlow = low - arrow_plots * 0.3;
plot arrowUP = if MA_Min then plotlow else double.nan;
ArrowUP.setpaintingStrategy(PaintingStrategy.ARROW_UP);
ArrowUP.SetLineWeight(3);
ArrowUP.SetDefaultColor(Color.ORANGE);
plot arrowdown = if MA_Max then plothigh else double.nan;
ArrowDown.setpaintingStrategy(PaintingStrategy.ARROW_Down);
ArrowDown.SetLineWeight(3);
ArrowDown.SetDefaultColor(Color.BLUE);
def condition1 = if isnan(HMA[-1] > HMA and HMA < HMA[1]) then 1 else 0;
def condition2 = if isnan(HMA[-1] < HMA and HMA > HMA[1]) then 1 else 0;
Alert(condition1, "MA Min Buy", Alert.Bar, Sound.Chimes);
Alert(condition2, "MA Max Sell", Alert.Bar, Sound.Chimes);
|