good afternoon all,
i need some coding help please.
i would like to add a parameter to the below code which defines how many bars to wait before re-entering a trade – assuming the conditions to trade are still being met.
code is not finalised but being built out bit by bit. will be using 1m bars
// Conditions for Entry of Long Positions
IF CLOSE<EMA(20) AND NOT ONMARKET THEN
BUY 1 CONTRACTS AT MARKET
SET STOP $LOSS StopLoss
ELSIF SHORTONMARKET AND (CLOSE-TRADEPRICE) THEN
BUY 1 CONTRACTS AT MARKET
SET STOP $LOSS StopLoss
ENDIF
Hope it makes sense
thanks in advance
Hi. You could add something like this:
// this will control how many bars your system is not onmarket
if not onmarket then
barsOut=barsOut+1
else
barsOut=0
endif
// You have to define how many bars (X) waiting out of market
if not onmarket and yourconditions and barsOut>x then
buy 1 contract at market
endif
many thanks Ivan, the code works perfectly.
thanks for your help, much appreciated