Mid Daily Range BO Dax mtf

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #79871 quote
    robertogozzi
    Moderator
    Master

    A couple of days ago I replied to a topic by @Mert (https://www.prorealcode.com/topic/median-previous-hour-priceline-in-a-1-minute-chart/#post-79723) about mid range and decided to experiment some code on daily mid range Break Out on a 1-minute charts using the newly supported MTF.

    It simply detects yesterday’s mid range, then waits the 1-minute chart to cross over/under it, provided there’s been a previous crossover/under on 1-hour charts within a few bars (I want to eneter the second break out). This code may lack other indicators and/or trailing stops, but I think it’s a good exercise. I tested it on Dax, Bund and Cac40 and it shows some performance, while it seems not to be working good on fx pairs:

    //                           Mid Daily Range BO Dax mtf
    TIMEFRAME (default)
    DaysForbidden           = OpenDayOfWeek < 1 OR OpenDayOfWeek > 5
    TimeForbidden           = OpenTime < 100000 OR OpenTime > 170000   //10 - 17
    ////////////////////////////////////////////////////////////////////////
    TIMEFRAME (Daily, updateonclose)
    MidRange                = low + (range / 2)
    ////////////////////////////////////////////////////////////////////////
    TIMEFRAME (1 hour, updateonclose)  //a previous BreakOut on H1 within a few bars is required
    ONCE LookBack           = 5                                        //5
    PreviousHI              = summation[LookBack](high[1] >= MidRange)
    PreviousLO              = summation[LookBack](low[1]  <= MidRange)
    ////////////////////////////////////////////////////////////////////////
    TIMEFRAME (default)
    //                           LONG  trades
    a0 = PreviousHI                                                    //previous BO ok
    a1 = close CROSSES OVER MidRange                                   //crossover again
    ax = a0 AND a1
    IF ax AND Not OnMarket AND Not DaysForbidden AND Not TimeForbidden THEN
       BUY 1 CONTRACT AT MARKET
    ENDIF
    //                           SHORT trades
    b0 = PreviousLO                                                    //previous BO ok
    b1 = close CROSSES UNDER MidRange                                  //crossunder again
    bx = b0 AND b1
    IF bx AND Not Onmarket AND Not DaysForbidden AND Not TimeForbidden THEN
       SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    //                           Sl & Tp
    SET TARGET pPROFIT 50                                              //50
    SET STOP   pLOSS   50                                              //50
    Nicolas, Nobody and Berra thanked this post
    #80042 quote
    JR1976
    Participant
    Veteran
    //                           Mid Daily Range BO Dax mtf
    TIMEFRAME (default)
    DaysForbidden           = OpenDayOfWeek < 1 OR OpenDayOfWeek > 5
    TimeForbidden           = OpenTime < 100000 OR OpenTime > 170000   //10 - 17
    ////////////////////////////////////////////////////////////////////////
    TIMEFRAME (Daily, updateonclose)
    MidRange                = low + (range / 2)
    ////////////////////////////////////////////////////////////////////////
    TIMEFRAME (1 hour, updateonclose)  //a previous BreakOut on H1 within a few bars is required
    ONCE LookBack           = 5                                        //5
    PreviousHI              = summation[LookBack](high[1] >= MidRange)
    PreviousLO              = summation[LookBack](low[1]  <= MidRange)
    ////////////////////////////////////////////////////////////////////////
    TIMEFRAME (default)
    //                           LONG  trades
    a0 = PreviousHI                                                    //previous BO ok
    a1 = close CROSSES OVER MidRange                                   //crossover again
    ax = a0 AND a1
    IF ax AND Not OnMarket AND Not DaysForbidden AND Not TimeForbidden THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    //                           SHORT trades
    b0 = PreviousLO                                                    //previous BO ok
    b1 = close CROSSES UNDER MidRange                                  //crossunder again
    bx = b0 AND b1
    IF bx AND Not Onmarket AND Not DaysForbidden AND Not TimeForbidden THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    //                           Sl & Tp
    SET TARGET pPROFIT 50                                              //50
    SET STOP   pLOSS   50                                              //50
    
    //trailing stop
    trailingstop = 7
     
    //resetting variables when no trades are on market
    if not onmarket then
    MAXPRICE = 0
    MINPRICE = close
    priceexit = 0
    endif
     
    //case SHORT order
    if shortonmarket then
    MINPRICE = MIN(MINPRICE,close) //saving the MFE of the current trade
    if tradeprice(1)-MINPRICE>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
    priceexit = MINPRICE+trailingstop*pointsize //set the exit price at the MFE + trailing stop price level
    endif
    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
    

    HiRoberto ,

    congrats for your strategy ,  I added a MFE trailing with DAX 5 Eur

    What do you think ?

    #80133 quote
    robertogozzi
    Moderator
    Master

    Trailing stop is excellent. Experimenting may result in great improvements.

    You may try different values for SL & TP or even change time frames.

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

Mid Daily Range BO Dax mtf


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by robertogozzi
7 years, 5 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 09/06/2018
Status: Active
Attachments: 3 files
Logo Logo
Loading...