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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
//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 |
Share this
No information on this site is investment advice or a solicitation to buy or sell any financial instrument. Past performance is not indicative of future results. Trading may expose you to risk of loss greater than your deposits and is only suitable for experienced investors who have sufficient financial means to bear such risk.
ProRealTime ITF files and other attachments :PRC is also on YouTube, subscribe to our channel for exclusive content and tutorials
Hello Nicolas.
Can i ask you for something?
I backtested your strategy in Dax 4H Timeframe in this way
//PRC_Out of the range TS | strategy
//10.03.2017
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge
defparam cumulateorders = false
// --- parameters
Size = 1 //position size
StopLoss = 60 //stoploss in points
TakeProfit = 60 //takeprofit in points
LookbackPeriod = 20 //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
// ------------
if not onmarket 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
The backtest brings around an +/- 0,00 Euro result. Is not really fine, but i see an interesting thing. The max drawdowin by 10.000 units testing is only -720 Euro. The losses in follow only 5 times!
So the code above is likely suitabel to use with an martingale system (dangerous i know).
So i hope you can put the martingale code snippet in the code above?
kind regards
blue
va bene anche france 40, ho modificato stoploss a 50 e takeprofit a 90
a 15m
Bonjour Nicolas,
Merci pour ce code.
L’avez-vous également pour CAC40 ? Ou sinon quels sont paramètres à modifier pour l’adapter au CAC40 ?
Merci d’avance
Tous les paramètres à modifier sont situés entre les lignes 8 et 16.
Hi Nicolas, sorry for the noob question. I want to test the script on stocks. Which are the right parameters to replace Size, StopLoss and TakeProfit assuming i would use the price % and number of shares?
Thanks
Change the stoploss and takeprofit value to percent ones. And change the SET TARGET PROFIT to SET TARGET %PROFIT , same for %LOSS.
bonjour je suis novice dans les strategie, je test un code sur PRT et lorsqu il se declanche il ne precise pas de SL sur mon graph…qq un peu m expliquer? Merci cordialement
si il n’y a pas de stoploss définit dans le code, alors c’est normal 🙂
bonjour merci pour la réponse. Oui b sur … est il possible que le SL soit coder sous une autre forme?
il s agit du code SP500 OPTIMIZER
// Definición de los parámetros del código
DEFPARAM CumulateOrders = true // Acumulación de posiciones desactivada
// Condiciones para entrada de posiciones largas
indicator1 = ExponentialAverage[24](MACDline[21,44,24](close))
indicator2 = MACDline[21,44,24](close)
c1 = (indicator1 = indicator4)
indicator8 = close + 5
ignored, ignored, indicator9 = CALL “MiIndicador(3)”(close)
c6 = (indicator8 = indicator21)
IF c1 AND c2 AND c6 and c11 THEN
BUY 5 CONTRACT AT MARKET
ENDIF
// Condiciones de salida de posiciones largas
ignored, indicator10, ignored = CALL “MiIndicador(3)”(close)
c7 = (close CROSSES under indicator10)
IF c7 THEN
SELL AT MARKET
ENDIF
SET STOP pLOSS 100
SET TARGET pPROFIT 60
ok mais pourquoi poser la question ici ? Pour des questions non spécifique à cette article, il vaudrait mieux utiliser le forum, merci.