Here is the link to the indicator from TradingView:
https://www.tradingview.com/script/HfAuYuG6-Strat-Trail-Stop-by-AlexsOptions/
Here is THINKSCRIPT CONVERTED BY CHATGPT: HAS 2 INVALID STATEMENTS:
Invalid statement: def at 18:1
Invalid statement: } at 20:1
Can someone please help fix these two invalid statements?
@halcyonguy @samer800
CODE:
declare lower;
input timeframe = AggregationPeriod.DAY;
input timeframe2 = AggregationPeriod.WEEK;
input use_HTF_open = no;
def htf_open;
def htf1;
def htf2;
def htf3;
def trail1 = Double.NaN;
def trail_color;
def trail2 = Double.NaN;
def trail_color2;
def request_htf_candle(instrument, timeFrame, bar) {
instrument[bar];
}
def pdo1 = request_htf_candle(open, timeframe, 1);
def pdh1 = request_htf_candle(high, timeframe, 1);
def pdl1 = request_htf_candle(low, timeframe, 1);
def pdc1 = request_htf_candle(close, timeframe, 1);
def pdo2 = request_htf_candle(open, timeframe, 2);
def pdh2 = request_htf_candle(high, timeframe, 2);
def pdl2 = request_htf_candle(low, timeframe, 2);
def pdc2 = request_htf_candle(close, timeframe, 2);
if pdh1 > pdh2 and pdl1 > pdl2 {
trail1 = pdl1;
} else if pdh2 > pdh1 and pdl1 < pdl2 {
trail1 = pdh1;
} else {
trail1 = trail1[1];
}
trail_color = if close > trail1 then Color.GREEN
else if close < trail1 then Color.RED
else Color.GRAY;
plot TrailingStop1 = trail1;
TrailingStop1.SetDefaultColor(trail_color);
TrailingStop1.SetLineWeight(2);
def pwo1 = request_htf_candle(open, timeframe2, 1);
def pwh1 = request_htf_candle(high, timeframe2, 1);
def pwl1 = request_htf_candle(low, timeframe2, 1);
def pwc1 = request_htf_candle(close, timeframe2, 1);
def pwo2 = request_htf_candle(open, timeframe2, 2);
def pwh2 = request_htf_candle(high, timeframe2, 2);
def pwl2 = request_htf_candle(low, timeframe2, 2);
def pwc2 = request_htf_candle(close, timeframe2, 2);
if use_HTF_open {
trail2 = htf_open;
} else if pwh1 > pwh2 and pwl1 > pwl2 {
trail2 = pwl1;
} else if pwh2 > pwh1 and pwl1 < pwl2 {
trail2 = pwh1;
} else {
trail2 = trail2[1];
}
trail_color2 = if close > trail2 then Color.GREEN
else if close < trail2 then Color.RED
else Color.GRAY;
plot TrailingStop2 = trail2;
TrailingStop2.SetDefaultColor(trail_color2);
TrailingStop2.SetLineWeight(2);
def long_signal = trail_color2 == Color.GREEN and trail_color == Color.GREEN and GetValue(trail_color, 1) != Color.GREEN;
def short_signal = trail_color2 == Color.RED and trail_color == Color.RED and GetValue(trail_color, 1) != Color.RED;
AddChartBubble(long_signal, high, "Long", Color.GREEN);
AddChartBubble(short_signal, low, "Short", Color.RED);