I have a pretty basic code that long above SMA200, and short below SMA200, with take profit and stop loss function. It runs fine, but when I want to set an alarm, TV said it uses repaint data, could you please point out where the problem is? TIA
//@version=5
strategy(shorttitle='AVG200', title='AVG200', overlay=true, currency = currency.USDT, initial_capital = 100, default_qty_type = strategy.percent_of_equity, default_qty_value = 100,commission_value = 0.035, calc_on_order_fills=false)
takeprofit = input.float (500, minval=0.1, maxval=500, step=0.1)/100
stoploss = input.float (50, minval=0.1, maxval=50, step=0.1)/100
TP = strategy.position_size == 0 ? na : strategy.position_size > 0 ? strategy.opentrades.entry_price(0)*(1+takeprofit) : strategy.opentrades.entry_price(0)*(1-takeprofit)
SL = strategy.position_size == 0 ? na : strategy.position_size < 0 ? strategy.opentrades.entry_price(0)*(1+stoploss) : strategy.opentrades.entry_price(0)*(1-stoploss)
basis = ta.sma(close, 200)
plot(basis, linewidth=1, color=color.new(color.white,0))
long_entry1 = close > basis
short_entry1 = close < basis
close_long1 = close < basis
close_short1 = close > basis
close_longTP = close > TP
close_longSL = close < SL
close_shortTP = close < TP
close_shortSL = close > SL
if barstate.isconfirmed
if long_entry1
strategy.entry("L", strategy.long, comment="Long")
if short_entry1
strategy.entry("S", strategy.short, comment="Short")
if close_long1
strategy.close("L", "Close Long")
if close_short1
strategy.close("S", "Close Short")
if close_longTP
strategy.close("L", "Long Take Profit")
if close_shortTP
strategy.close("S", "Short Take Profit")
if close_longSL
strategy.close("L", "Long Stop Loss")
if close_shortSL
strategy.close("S", "Short Stop Loss")
Try Different set of if function, but it still have the repaint problem.
New contributor
Ricky Lee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.