Dax / UT 2mn / Long only.

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #39966 quote
    Inertia
    Participant
    Master

    Dear Nicolas,

    I am pleased to share the following strategy.

    The trade is triggered by the MACD histo / TF – 2mn / Instrument: DAX, 1eur.

    I stand ready for your kind feedback.

    IMPORTANT: Great forum, thx to Nicolas, Maz, Ale, Maverick 😉 , and everyone else for your ideas and bit of codes !

    DJ

     

    //
    
    // Définition des paramètres du code
    DEFPARAM CumulateOrders = False
    // Cumul des positions désactivé
    // Annule tous les ordres en attente et ferme toutes les positions à 0:00, puis empêche toute création d'ordre avant l'heure "FLATBEFORE".
    DEFPARAM FLATBEFORE = 091500
    // Annule tous les ordres en attente et ferme toutes les positions à l'heure "FLATAFTER"
    DEFPARAM FLATAFTER = 220000
    
    // Empêche le système de placer des ordres pour entrer sur le marché ou augmenter la taille d'une position avant l'heure spécifiée
    noEntryBeforeTime = 091500
    timeEnterBefore = time >= noEntryBeforeTime
    
    // Empêche le système de placer des ordres pour entrer sur le marché ou augmenter la taille d'une position après l'heure spécifiée
    noEntryAfterTime = 220000
    timeEnterAfter = time < noEntryAfterTime
    
    // Empêche le système de placer de nouveaux ordres sur les jours de la semaine spécifiés
    daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
    
    // Conditions pour ouvrir une position acheteuse
    indicator1 = MACDline[16,26,9](close)
    c1 = (indicator1 > 0)
    indicator2 = MACD[16,26,9](close)
    c2 = (indicator2 CROSSES OVER 0)
    
    IF (c1 AND c2) AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    
    //trailing stop
    trailingstop = 28
    
    //resetting variables when no trades are on market
    if not onmarket then
    MAXPRICE = 0
    priceexit = 0
    endif
    
    //case LONG order
    if longonmarket then
    MAXPRICE = MAX(MAXPRICE,close) //saving the MFE of the current trade
    if MAXPRICE-tradeprice(1)>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
    priceexit = MAXPRICE-trailingstop*pointsize //set the exit price at the MFE - trailing stop price level
    endif
    endif
    
    //exit on trailing stop price levels
    if onmarket and priceexit>0 then
    EXITSHORT AT priceexit STOP
    SELL AT priceexit STOP
    endif
    
    SET STOP ploss 120
    SET TARGET pPROFIT 200
    Nicolas thanked this post
    WF.png WF.png No-Zero-Bars.png No-Zero-Bars.png Tick-by-Tick.png Tick-by-Tick.png Resumé.png Resumé.png
    #39973 quote
    Inertia
    Participant
    Master

    The code. 😉

    5.itf
    #40010 quote
    Nicolas
    Keymaster
    Master

    Thanks Inertia. I moved the topic to ProOrder section and add the code with the correct button to insert code 🙂

    It’s great you made the walk forward analysis! So the only setting you optimized is the “trailingstop” variable? Any change to get a short version to see how it goes?

    #40052 quote
    Inertia
    Participant
    Master

    Thank you Nicolas. Yes for the “trailingstop”, and replaced the MACD 12 26 9 by 16 26 9…Is that the correct way to do a WF ?

    Attached the short version…How does this sounds like ?

    DJ

    //Dax 15mn / short only 
    // Définition des paramètres du code
    DEFPARAM CumulateOrders = False // Cumul des positions désactivé
    // Annule tous les ordres en attente et ferme toutes les positions à 0:00, puis empêche toute création d'ordre avant l'heure "FLATBEFORE".
    DEFPARAM FLATBEFORE = 091500
    // Annule tous les ordres en attente et ferme toutes les positions à l'heure "FLATAFTER"
    DEFPARAM FLATAFTER = 214500
    
    // Empêche le système de placer des ordres pour entrer sur le marché ou augmenter la taille d'une position avant l'heure spécifiée
    noEntryBeforeTime = 091500
    timeEnterBefore = time >= noEntryBeforeTime
    
    // Empêche le système de placer des ordres pour entrer sur le marché ou augmenter la taille d'une position après l'heure spécifiée
    noEntryAfterTime = 214500
    timeEnterAfter = time < noEntryAfterTime
    
    // Empêche le système de placer de nouveaux ordres sur les jours de la semaine spécifiés
    daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
    
    // Conditions pour ouvrir une position en vente à découvert
    indicator1 = MACD[12,26,9](close)
    c1 = (indicator1 CROSSES UNDER 0)
    indicator2 = MACDline[12,26,9](close)
    c2 = (indicator2 < 0)
    indicator3 = ExponentialAverage[2000](close)
    c3 = (close < indicator3)
    indicator4 = ExponentialAverage[2000](close)
    indicator5 = ExponentialAverage[2000](close)
    c4 = (indicator4 < indicator5[1])
    
    IF (c1 AND c2 AND c3 AND c4) AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    
    //trailing stop
    trailingstop = 28
     
    //resetting variables when no trades are on market
    if not onmarket then
    MAXPRICE = 0
    priceexit = 0
    endif
     
    
    //case LONG order
    if longonmarket then
    MAXPRICE = MAX(MAXPRICE,close) //saving the MFE of the current trade
    if MAXPRICE-tradeprice(1)>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
    priceexit = MAXPRICE-trailingstop*pointsize //set the exit price at the MFE - trailing stop price level
    endif
    endif
     
    //exit on trailing stop price levels
    if onmarket and priceexit>0 then
    EXITSHORT AT priceexit STOP
    SELL AT priceexit STOP
    endif
     
    SET STOP ploss 62//
    SET TARGET pPROFIT 250//
    
    5-short-Résumé.png 5-short-Résumé.png 5-short-0-bars-OK.png 5-short-0-bars-OK.png 5-WF.png 5-WF.png 5-short_Tick-by-tick.png 5-short_Tick-by-tick.png
    #40068 quote
    Inertia
    Participant
    Master

    Dear Nicolas,

    Attached is the best I can do: => Stop Loss set to 45 and No target (No Limits !!)

    OK?

    Francesco78 thanked this post
    INERTIA-Dax-TF-15_SHORT.png INERTIA-Dax-TF-15_SHORT.png
    #40094 quote
    T-rader
    Participant
    Average

    Thanks for sharing! Is it really possible to have both trailing an stop loss in the same code?

    #40097 quote
    Inertia
    Participant
    Master

    Hi T-rader.

    Yes at first. Then it works roughly like a OCO order. Once the value of the trailing stop gain in profit, the original stop will be cxl’d to be moved to the trailing value.

    Hope this is clear. 😉

    https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/

    Tx.

    #40110 quote
    Nicolas
    Keymaster
    Master

    I made videos in French to explain the WFA. If you made a backtest for the whole history with optimized variables of one of your OOS period, I think you did not understand how it should work 🙂

    Anyway, I think we should be careful with the result of the WF test you made for a main reason, most of the Out Of Sample results have huge WFE (>200%).

    Why did you made the test of the short version on a 15 minutes timeframe? While the long one is designed for the 2 minutes one?

    #40115 quote
    Inertia
    Participant
    Master

    Thank you Nicolas. WF’s feedback much appreciated. I’ll have a look asap.

    Short version: It doesn’t work well with the TF 2mn. The 15TF works much better for this kind of signal.

    The idea would be to start both strategies at once and one may partially cover the losses of the other.

    But, agree, it is not a perfect TF match Long Short…

    Based on your experience, don’t you think that these 2 strategies, despite their different TF deserve a try ?

    Tx again for your time and kind help on it.

    DJ

    #40118 quote
    Nicolas
    Keymaster
    Master

    Well, the spread is not the same after 170000, you should reduce the schedules of the strategy or add at least 1 point to the spread in backtests.

    I just realized that your short version can’t work effectively because your trailing stop function doesn’t include the short orders but only the long ones!

    #40139 quote
    Inertia
    Participant
    Master

    OMG 🙁 – but thank you…

    1 pts added (total of 2).

    Attached the versions with and without trailing stop.

    Same amount of draw downs in both case … My choice goes logically to the most profitable one.

    I will WF it and put them in a demo account see how it goes.

    Thank you Nicolas.

    2-pts-spread.png 2-pts-spread.png No-trailing-stop.png No-trailing-stop.png With-trailing-stop.png With-trailing-stop.png
    #40155 quote
    Nicolas
    Keymaster
    Master

    The trailing stop version for short orders can be easily found in forums or directly into comments of the blog post related to it.

    Inertia thanked this post
Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.

Dax / UT 2mn / Long only.


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Inertia @inertia Participant
Summary

This topic contains 11 replies,
has 3 voices, and was last updated by Nicolas
8 years, 8 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 07/06/2017
Status: Active
Attachments: 13 files
Logo Logo
Loading...