Hey Crew,
I am currently running the following hourly charts however on the ProBackTest it enters into a new contract every hour even if it is already in a position.
I want to limit the strategy to being maximum 1 contract long or short at any given time and not continue to accumulate contracts.
My current code is below. Does anyone know how to help with this?
Cheers, Sam
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Conditions to enter long positions
indicator1 = Average[120](close)
c1 = (close >= indicator1)
IF c1 THEN
BUY 1 CONTRACT AT MARKET
ENDIF
// Conditions to enter short positions
indicator2 = Average[120](close)
c2 = (close <= indicator2)
IF c2 THEN
SELLSHORT 1 CONTRACT AT MARKET
ENDIF
// Stops and targets
SET STOP pTRAILING 30
Always use the ‘Insert PRT Code’ button when putting code in your posts to make it easier for others to read. Thank you 🙂
As to your code, it’s impossible that “it enters into a new contract every hour even if it is already in a position“. To accomplish that you should replace line 2 by:
DEFPARAM CumulateOrders = True
So, did you already backtest it? How could you spot more than 1 position at a time?
append this line to your code to monitor the number of positions accumulated:
graph abs(CountOfPosition)