Hey everyone,
I have this code:
if Time>163000 and Time<230000 and signal=1 and low<=BuyLine and not longonmarket then
buy 10 contract at market
endif
set target profit 10
set stop loss SellLine
if Time>163000 and Time<230000 and signal=-1 and high>=SellLine and not shortonmarket then
sell 10 contracts at market
endif
set target profit 5
set stop loss BuyLine
Basically what I want to do is if the open is above the BuyLine (signal=1) to buy a hit of that line with stop at the SellLine and vice versa, if the open is below the SellLine (signal=-1) to sell a hit of the SellLine with stop at the BuyLine.
The problem is that the backtest gives trades at wrong places. Can you help me spot the problem in the code please?
John
Try below … does it give you what you want?
if Time>163000 and Time<230000 and signal=1 and low<=BuyLine and not longonmarket then
buy 10 contract at market
set target profit 10
set stop loss SellLine
endif
if Time>163000 and Time<230000 and signal=-1 and high>=SellLine and not shortonmarket then
sellShort 10 contracts at market
set target profit 5
set stop loss BuyLine
endif
In line 1 you only check the LOW price, not the OPEN, which could also be below BuyLine.
Add
AND open > BuyLine
to that line.
You may want to add a check for OPEN also in line 8.