Breakout of range Trading Strategy

Breakout of range Trading Strategy

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.

 

Share this

Risk disclosure:

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 : How to import ITF files into ProRealTime platform?

PRC is also on YouTube, subscribe to our channel for exclusive content and tutorials

  1. bluetime6 • 03/16/2017 #

    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
     
     

  2. Mirko borgna • 03/16/2017 #

    va bene anche france 40, ho modificato stoploss a 50 e takeprofit a 90

  3. Mirko borgna • 03/16/2017 #

    a 15m

  4. David29 • 03/16/2017 #

    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

    • Nicolas • 03/16/2017 #

      Tous les paramètres à modifier sont situés entre les lignes 8 et 16.

  5. carlo__ • 03/16/2017 #

    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

    • Nicolas • 03/16/2017 #

      Change the stoploss and takeprofit value to percent ones. And change the SET TARGET PROFIT to SET TARGET %PROFIT , same for %LOSS.

  6. bertrandpinoy • 03/16/2017 #

    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

    • Nicolas • 03/16/2017 #

      si il n’y a pas de stoploss définit dans le code, alors c’est normal 🙂

  7. bertrandpinoy • 03/16/2017 #

    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

    • Nicolas • 03/16/2017 #

      ok mais pourquoi poser la question ici ? Pour des questions non spécifique à cette article, il vaudrait mieux utiliser le forum, merci.

avatar
Register or

Likes

avatar avatar avatar avatar avatar avatar avatar avatar avatar avatar avatar avatar
Related users ' posts
David Thanks for the explanation Nicolas.
freecat1899 Hello, I wanted to create a percent ADR based on this indicator, so I wrote this code that I...
revstrat At first glance, I see this mistake. You shouldn't average the highs and the lows. You shoul...
GraHal Ooops got that excited I sent that last one twice! ha (and can't delete it, sorry) I got it...
Eric n = 3  dont forget to allow 3 contract in proorder
UkCoopDownUnder Tried EURUSD GMT and GMT -1, as far back as I can go, Nov 2018 on 15mn Tf, 22% loss
hvluthy@sunrise.ch I'm very interested to try out your strategy, but as a bloody newbie I need some help regard...
Scalp Hola Adolfo, tengo una variante de tu estrategia, pero no se programar, me puedes ayudar al ...
ALZ Hi, I tested this strategy and that doesn't work.. strategy is losing.. Does anyone curr...
Doctrading Hello, Someone asked me something (his results seemed to be different) on my email, but it ...
Glen Marquis Not your best..So what is your best strategy? :)
Adolfo Onrubia Ups! Sorry. Variable "S" is to set an specific Spread if needed. Could be "0", or the distan...
GraHal Hi Adolfo, big thank you for your code, but I am a bit confused. Spread is the difference b...
Meta Signals Pro Hi, For me there is a mistake here L32 maxriesgo = round(equity*riesgo) => round(equ...
Dave Hi, I'm new to coding and have been trying to modify the code a little to backtest an idea I...
Nicolas Better use the forums for coding assistance please. You'll get more results there for sure.
Dave Apologies - only just learning the site layout. Maybe you could delete the post?
Nicolas You can try this code for buy and hold curve line: capital = 10000 mylot = 2 i1 = capi...
soukenson Bonjour Nicolas, Je ne comprends pas où ajouter le code que tu as a donné dans le code initi...
Nicolas Tu veux parler du code pour comparer avec le "buy and hold" ? Si oui, tu as tout ce qu'il fa...
Nicolas FR/Bonjour Steftonio, non pas de frais overnight calculé sur la durée du backtest, c'est une...
avatar
Anonymous Any reason why in 2016 this system is doing very bad respect the previous years?
Nicolas "very bad" is relative to the account equity. I do not forward test this strategy since I po...
EAxelsson Hi, shouldn´t it be or instead of and? if FiftyTwoWeekHigh = FiftyTwoWeekHigh[1] OR FiftyTwo...
qigley Line 4 has a redundant term "Close>EMA2." is not necessary as EMA2 will always be less t...
Mike.44 Thanks It a good job !
Nicolas
9 years ago
trabucaire Hello, what does it mean the 20 and 40 number on this code ? Thank you !
robertogozzi I modified it to make parameters customizable and to Draw a Grey candlestick when a range is...
Wisko But the BUY-trigger is below the High of the first two 15min-candels?
Nicolas That's right, because what we want is to enter the market quickly and not wait for the next ...
Wisko Then I don't understand the backtest data. Yesterday (28.9.) range was from ~ 4410,5 - 4450,...

Top