Breakout of range Trading Strategy

Category: Strategies By: Nicolas Created: March 16, 2017, 8:00 AM
March 16, 2017, 8:00 AM
Strategies
11 Comments

Trading system “OUT OF THE RANGE”:
The system looks at the last X candles and determines which were the highest and lowest price values during this period. When the system is activated, it automatically add two pending stop orders on market: a long stop order at Y pips above the highest detected; a short stop order at Y pips below the lowest detected.

The idea is to have 2 pending stop orders placed below the detected high / low in order to enter the position if the price goes out of the range formed during the last X candles. If at the candlestick X + 1 one of the input stop order has not been executed, the system does not touch the pending orders.
NB: the system re-calculates the input stop levels according to the new X last candles. If at the candlestick X + 1 the system has executed an input stop, then the system remains inactive during X candles, so as not to re-position input stop commands which would be distorted by the last break of a Last up / down on the X + 1 last candles.
ALSO: the system might not succeed in positioning the new input stop if the candlestick X + 1 was closing at the new high / low.

Stop orders positioned at Y pips above / below the last up / down of the last X candles must be linked; That is, if one of the orders is executed, the other stop order of the waiting entry must be deleted. It is only after executing one of the input halts that the system then waits for the formation of X new candlesticks to reposition two input stop orders. NB: Without this condition, the system would be able to position 2 orders permanently all X candles even though there are already two stop orders of input already waiting …
The system has a time schedule: At the start time, the system starts counting X candles (and not it looks at the previous X). This is to prevent the system from counting candles on Friday one Sunday for example … At the end of the hour, the system no longer counts the candles. If two orders are waiting for execution, they are deleted. And if a trade is open, it remains because it has a fixed SL and TP anyway.

This trading strategy has been coded by a request on the French forum. Please consider that there is no typical settings and it is not dedicated to any instrument or timeframe at all. This strategy is almost like a “sandbox” for studying purpose and to define suitable parameters for your preferred instruments. Current default settings come from optimisation on EURUSD 5 minutes timeframe over last 20.000 bars only.

//PRC_Out of the range TS | strategy
//10.03.2017
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge

defparam cumulateorders = false

// --- parameters
StartHour = 080000
EndHour = 180000
Size = 1 //position size
StopLoss = 60 //stoploss in points
TakeProfit = 10 //takeprofit in points
LookbackPeriod = 10 //lookback period to find highest high and lowest low (price range)
PointsDistance = 5 //distance in points to add/substract from highest high or lowest low to put the pending stop orders
// ------------

tcondition = time>StartHour and EndHour and intradaybarindex>=LookbackPeriod*2

if not onmarket and tcondition and barindex-tradeindex(1)>=LookbackPeriod then
 BUY Size CONTRACTS AT highest[LookbackPeriod](high)+PointsDistance*pointsize STOP
 SELLSHORT Size CONTRACTS AT lowest[LookbackPeriod](low)-PointsDistance*pointsize STOP
endif

SET STOP PLOSS StopLoss
SET TARGET PPROFIT TakeProfit

 

Download
Filename: PRC_BreakOut-of-the-range-TS.itf
Downloads: 620
Nicolas Master
I created ProRealCode because I believe in the power of shared knowledge. I spend my time coding new tools and helping members solve complex problems. If you are stuck on a code or need a fresh perspective on a strategy, I am always willing to help. Welcome to the community!
Author’s Profile

Comments

Logo Logo
Loading...