Hi,

I have coded a very simple strategy here, that is basically saying 'If the last 2 bars closed down then buy the next bar at the open and close/exit trade at the next close up bar'

I feel my script is close but I just can't seem to get it on the chart.

Any ideas what im missing to get this working?

many thanks

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/

//@version=5
strategy(s2,
initial_capital=4000,
default_qty_type=strategy.percent_of_equity,
overlay=true,
use_bar_magnifier=true)

//Get Inputs
CandlesBack = input.int(title=No Of Bars Lookback, defval=2, step=1)
CandlesForward = input.int(title=No of Bars Forward, defval=1, step=1)
i_time = input.time(title=Date From, defval=timestamp(01 Jan 2020))
i_time2 = input.time(title=Date To, defval=timestamp(01 Jan 2099))

//Date Check filter
dateFilter = time >= i_time and time <= i_time2

// Check buy/sell conditions
var float buyPrice = 0
buycondition = close CandlesBack and strategy.position_size == 0 and dateFilter
sellcondition = CandlesForward > open and strategy.position_size >0

// Enter Positions
if buycondition
strategy.entry(id=long, direction=strategy.long)
buyPrice := open

// Exit Positions

if sellcondition
strategy.close(id=long, comment=Exit)
buyPrice := na

//Plot on chart
plot(buyPrice, color=color.green, style=plot.style_linebr)