There you go:
ONCE LotSize = 4 //lots to be traded
ONCE Offset = 20 * PipSize //offset fom 8am price
ONCE Distance = 7 //Distance rquired by the broker for pending oifers (to be checked with the broker)
ONCE PriceAt8 = 0
ONCE ExitPrice = 0
IF Not OnMarket AND OnMarket[1] THEN
QUIT
ENDIF
IF IntraDayBarIndex = 0 THEN
PriceAt8 = 0
ENDIF
IF OpenTime = 080000 THEN
PriceAt8 = close
ENDIF
IF OnMarket AND Not OnMarket[1] THEN
Entry = TradePrice
ENDIF
IF Not OnMarket AND PriceAt8 > 0 THEN
IF close >= (PriceAt8 + Offset) THEN
BUY LotSize Contract at Market
ELSIF close <= (PriceAt8 - Offset) THEN
SELLSHORT LotSize Contract at Market
ENDIF
ExitPrice = 0
TrailFlag = 0
TrailBase = 20
SET TARGET pPROFIT 96
SET STOP pLOSS 20
ENDIF
IF OnMarket THEN
MyProfit = PositionPrice * PositionPerf / PipSize
Positions = abs(CountOfPosition)
IF MyProfit >= 44 THEN
IF LongOnMarket THEN
ExitPrice = Entry + TrailBase * PipSize
ELSE
ExitPrice = Entry - TrailBase * PipSize
ENDIF
TrailBase = TrailBase + 1
ELSIF MyProfit > 40 AND TrailFlag = 1 THEN
TrailFlag = 2
IF LongOnMarket THEN
ExitPrice = Entry + 16 * PipSize
SELL (Positions / 2) CONTRACTS at Market
ELSE
ExitPrice = Entry - 16 * PipSize
EXITSHORT (Positions / 2) CONTRACTS at Market
ENDIF
ELSIF MyProfit >= 10 AND TrailFlag = 0 THEN
TrailFlag = 1
IF LongOnMarket THEN
ExitPrice = Entry - 10 * PipSize
SELL (Positions / 2) CONTRACTS at Market
ELSE
ExitPrice = Entry + 10 * PipSize
EXITSHORT (Positions / 2) CONTRACTS at Market
ENDIF
ENDIF
IF ExitPrice > 0 THEN
IF LongOnMarket THEN
IF close >= (ExitPrice + Distance) THEN
SELL AT ExitPrice STOP
ELSIF close <= (ExitPrice - Distance) THEN
SELL AT ExitPrice LIMIT
ELSE
//SELL AT Market
ENDIF
ELSE
IF close <= (ExitPrice - Distance) THEN
EXITSHORT AT ExitPrice STOP
ELSIF close >= (ExitPrice + Distance) THEN
EXITSHORT AT ExitPrice LIMIT
ELSE
//EXITSHORT AT Market
ENDIF
ENDIF
ENDIF
ENDIF
//graphonprice Entry
//graphonprice ExitPrice coloured(255,0,0,255)
//graph MyProfit
I added a DISTANCE as required by the broker (the correct value is to be checked with the broker) for pending orders. If an order is placed at an incorrect price, the oredr is rejected and the strategy stopped (in both demo and real, not in backtest, of course).
As to the DISTANCE I added two commented lines (thus ignored) to exit at MARKET if the distance is not enough. If you wat to use those two lines, simply remove the leading slashes.
To disable the distance, set it to 0.
Thank you very much Roberto, much appreciated.
Roberto is so very kind helping us all out, coding our ideas!
Let us know how you get on Monday please Berwick. I’m going to give it a go also! 🙂
A 20-pip SL is so tight that it almost always is hit and the strategy is stopped immediately.
To test it, I used a 100-pip SL and commented out the QUIT instruction.