The example trade included in this code is for TSLA
.
You can have excel generate strings like f_trade(true, 02, 12, 2020, 557, 03, 12, 2020, 596)
for your trades, and paste that into the script.
//@version=4
strategy(title="Trades", overlay=true, backtest_fill_limits_assumption=0, process_orders_on_close=true, pyramiding=0, commission_value=0, slippage=0, calc_on_order_fills=true, close_entries_rule="ANY")
var int[] enter_ts = array.new_int(na)
var float[] enter_price = array.new_float(na)
var int[] exit_ts = array.new_int(na)
var float[] exit_price = array.new_float(na)
var int[] position = array.new_int(na)
f_trade(_long, _enter_d, _enter_m, _enter_y, _enter_price, _exit_d, _exit_m, _exit_y, _exit_price) =>
array.push(enter_ts, timestamp(_enter_y, _enter_m, _enter_d, 0, 0, 0))
array.push(exit_ts, timestamp(_exit_y, _exit_m, _exit_d, 0, 0, 0))
array.push(enter_price, _enter_price)
array.push(exit_price, _exit_price)
array.push(position, _long ? 1 : -1)
if barstate.isfirst
f_trade(false, 27, 11, 2020, 580, 30, 11, 2020, 560)
f_trade(true, 02, 12, 2020, 570, 03, 12, 2020, 596)
ts_today = timestamp(year, month, dayofmonth, 0, 0, 0)
if (array.includes(enter_ts, ts_today)) and strategy.position_size == 0
idx = array.indexof(enter_ts, ts_today)
ts = array.get(enter_ts, idx)
price = array.get(enter_price, idx)
pos = array.get(position, idx)
comm = (pos ? "Long" : "Short") + " at " + tostring(price, "#.##")
if pos == 1
strategy.entry("L", strategy.long, limit=price, comment=comm)
else if pos == -1
strategy.entry("S", strategy.short, limit=price, comment=comm)
else if (array.includes(exit_ts, ts_today)) and strategy.position_size != 0
idx = array.indexof(exit_ts, ts_today)
ts = array.get(exit_ts, idx)
price = array.get(exit_price, idx)
pos = array.get(position, idx)
comm = "TP " + (pos ? "Long" : "Short") + " at " + tostring(price, "#.##")
if strategy.position_size > 0
strategy.exit("L", limit=price, comment=comm)
else if strategy.position_size < 0
strategy.exit("S", limit=price, comment=comm)