Hi all,
I am currently working an a Breakout strategy. It all seams to work fine but I am struggeling with the Stop loss and Take profit. I want the take profit to be set from my “HI” or “LO” in the breakout range instead of from the price that I get when the order is set.
The reason for this is that when there is a slippage, the order price will be different from the HI or LO. I still want to have the same profit target.
// --- settings
rangestart = 092500 //start of premarket schedule
rangeend = 093500 //end of premarket schedule
closeat = 115500 //time schedule to close all pending & atmarket orders
takeprofit = 5 //takeprofit in points
stoploss = 5 //stoploss in points
n = 1 //amount of lots/contracts/shares to open for each new order
// --- end of settings
ONCE LO = CLOSE*1000
if time>=closeat then
sell at market
exitshort at market
endif
if intradaybarindex=0 then
hi=0
lo=close*1000
endif
if time>=rangestart and time<rangeend then
hi=max(high,hi)
lo=min(low,lo)
trade = 0
ENDIF
IF trade = 0 and time>=rangeend THEN
if hi>0 then
BUY n SHARES at HI STOP
endif
if lo>0 then
SELLSHORT n SHARES at lo STOP
ENDIF
endif
if onmarket then
trade=1
endif
SET STOP pLOSS stoploss
SET TARGET pPROFIT takeprofit
Regards
Remove your lines 41 and 42 and replace them with the ones below: (not tested)
if longonmarket then
sell at hi+takeprofit*pointsize stop
sell at hi-stoploss*pointsize limit
endif
if shortonmarket then
exitshort at lo-takeprofit*pointsize stop
exitshort at lo+stoploss*pointsize limit
endif
Thanks Nicolas!
That worked great. I used your code (only changed takeprofit to limit and stoploss to stop entry order) and it worked perfectly.
Thanks!