Hi
Please see code below. Basically i am trying to indicate that the position must be closed at the next bar open if the stop and profit targets are not met.
the code i have in there returns zero trades on the backtest.
IF c2 or c3 then
SELL AT MARKET
ELSE
SELL AT MARKET NextBarOpen
ENDIF
NextBarOpen is an obsolete keyword that is ignored, but still prsent to grant older code works, but it’s the default rule as ALL strategies are executed at the closing of each bar and ALL trades are opened and closed after that, that is when the next bar opens.
Your code CAN’T start any trade because you have only used SELL, which is the instruction to close a Long trade.
Here are the 4 keywords involved in opening and closing trades:
- BUY opens a Long positions
- SELL closes a Long position
- SELLSHORT opens a Short position
- EXITSHORT closes a Short position.
there’s the full code
on the backtest over 20 days, it is only taking 8 trades, i want it to take a trade every candle, which is 1 hour
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Prevents the system from placing new orders on specified days of the week
daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
// Conditions to enter long positions
c1 = (Close[1] < Close[2])
IF c1 AND not daysForbiddenEntry THEN
BUY 1 CONTRACT AT MARKET
ENDIF
//Conditions to exit long positions
c2 = ((TRADEPRICE/Close[1])-1) > 0.006
c3 = ((TRADEPRICE/Close[1])-1) > -0.004
IF c2 or c3 THEN
SELL AT MARKET
ENDIF
// Conditions to enter short positions
c4 = (Close[1] > Close[2])
IF c4 AND not daysForbiddenEntry THEN
SELLSHORT 1 CONTRACT AT MARKET
ENDIF
// Conditions to exit short positions
c5 = ((TRADEPRICE/Close[1])-1) > 0.006
c6 = ((TRADEPRICE/Close[1])-1) > -0.004
IF c5 or c6 THEN
EXITSHORT AT MARKET
ENDIF
Hello,
Looking over your code I see that you have set conditions for buying and short selling that I think you should review.
c2 = ((TRADEPRICE/Close[1])-1) > 0.006
c3 = ((TRADEPRICE/Close[1])-1) > -0.004
As you can see, condition c2 or c3 is redundant. It would suffice to put c3 as c2 will always be true.
c2 = ((TRADEPRICE/Close[1])-1) > 0.006
c3 = ((TRADEPRICE/Close[1])-1) < -0.004
The same is true for shorts.
thank you, made an error with the sign.