Hello,
After closing a trade I would like my system to wait two periods before it can open a new trade in the same market.
At the moment it can open a new trade at the same time it closes the old.
Any help would be appreciated.
To close an open trade to start a new one:
IF MyLongConditions THEN //LONG
IF LongOnMarket THEN
SELL AT MARKET //close any open LONG position
ENDIF
BUY 1 CONTRACT AT MARKET //close any SHORT open position and enter a new LONG one
ENDIF
IF MyShortConditions THEN //SHORT
IF ShortOnMarket THEN
EXITSHORT AT MARKET //close any open SHORT position
ENDIF
SELLSHORT 1 CONTRACT AT MARKET //close any LONG open position and enter a new SHORT one
ENDIF
To make a pause between orders, add a condition with BARINDEX-TRADEINDEX>x , where x is the bars quantity. It has been discussed many times with a lot of examples.
First link I found: Do not take a trade for x bars after trade closed
To count X periods before entering a new trade:
ONCE Count = 0
ONCE MinCount = 2
IF (Not OnMarket AND OnMarket[1]) OR (StrategyProfit <> StrategyProfit[1]) THEN //check thare was a trade open the previous bar and not any longer....
Count = 1 //... to start counting periods (bars)
ELSE
Count = Count + 1 //increment Count at each new period (bar)
ENDIF
IF OnMarket THEN
Count = 0
ENDIF
IF MyLongConditions AND Not OnMarket AND ((Count = 0) OR Count > MinCount)) THEN
BUY 1 CONTRACT AT MARKET //LONG
ENDIF
IF MyShortConditions AND Not OnMarket AND ((Count = 0) OR Count > MinCount)) THEN
SELLSHORT 1 CONTRACT AT MARKET //SHORT
ENDIF
Many thanks Nicolas and robertogozzi for your help.
This is now working correctly in my system