Hi, I needed help with a script that doesn’t make a new buy until the nextday. If it makes a sell, it doesn’t matter if it’s a profit or loss. So after 00.00 it’s fine for it to go into buy again. If it doesn’t make a sell, I want it to continue running until it gets a signal to do so.
Hi,you can handle this easily by checking when a new day starts and using a variable to mark whether a trade has already been made during the current day.
Here’s a working example that does exactly what you described:
ONCE lastTradeDay = 0
newDay = day <> day[1]
// Reset permission to trade when a new day starts
IF newDay THEN
lastTradeDay = 0
ENDIF
// Buy signal: close crosses above 30-period average
setuplong = close CROSSES OVER average[30](close)
// Entry: only if no position is open and no trade has been made today
IF NOT OnMarket AND lastTradeDay = 0 AND setuplong THEN
BUY 1 CONTRACT AT MARKET
ENDIF
// Exit: close crosses below 30-period average
IF OnMarket AND close CROSSES UNDER average[30](close) THEN
SELL AT MARKET
lastTradeDay = 1 // mark that a trade has already been made today
ENDIF
GRAPH lastTradeDay COLOURED("red")
GRAPH newDay COLOURED("blue")
GRAPH setuplong COLOURED("lime")
The link above seems not to work, here is the code:
OTD = Barindex - TradeIndex(1) > IntradayBarIndex // limits the (opening) trades till 1 per day (OTD One Trade per Day)
if time >= StartE And time <= StartL and OTD then //and not onmarket then
IF conditionsmet then
buy N shares AT MARKET
ENDIF
endif