Trading the 5 Min Bar

Viewing 15 posts - 1 through 15 (of 67 total)
  • Author
    Posts
  • #40591 quote
    GraHal
    Participant
    Master

    Came across the link below … it explains 3 Strategies in detail for trading on 5 Min Timeframe. Would be a good basis for coding 3 separate Bots.

    If the Strategies exist on here already, then it be very useful if you could provide a link?

    https://tradingsim.com/blog/5-minute-bar/

    GraHal

    #40637 quote
    robertogozzi
    Moderator
    Master

    I tried #1, Stochastic+Rsi+TEMA, on DAX 5-min TF (I added Nicolas’ trailing stop code):

    //-------------------------------------------------------------------------
    //                            Stochastic+Rsi+Tema DAX 5 min
    //-------------------------------------------------------------------------
    DEFPARAM CumulateOrders     = False
    DEFPARAM FlatBefore         = 090000                      //no trades before 09:00:00
    DEFPARAM FlatAfter          = 213000                      //no trades after  21:30:00
    
    ONCE nLots                  = 1                           //number of LOTs traded
    
    ONCE TP                     = 30                          //30    pips Take Profit
    ONCE SL                     = 9                           //9     pips Stop Loss
    
    TemaVal                     = Tema[4](close)              //4
    
    ONCE StocLimitBuy           = 22                          //OS   22
    ONCE StocLimitSell          = 100 - StocLimitBuy          //OB  (difference)
    
    ONCE RsiLimitBuy            = 31                          //OS   31
    ONCE RsiLimitSell           = 100 - RsiLimitBuy           //OB   (difference)
    
    StocD                       = Stochastic[8,6](close)      //8, 6
    StocK                       = Average[13](StocD)          //13
    
    RsiVal                      = Rsi[3](close)               //3
    //***************************************************************************************
    IF LongOnMarket THEN
       IF Close < TemaVal THEN
          SELL AT MARKET                                      //Exit LONGs when Bar closes below TEMA
       ENDIF
    ENDIF
    IF ShortOnMarket THEN
       IF Close > TemaVal THEN
          EXITSHORT AT MARKET                                 //Exit SHORTs when Bar closes above TEMA
       ENDIF
    ENDIF
    //***************************************************************************************
    trailingstart = 2      //2     trailing will start @trailinstart points profit
    trailingstep  = 1      //1     trailing step to move the "stoploss"
    //reset the stoploss value
    IF NOT ONMARKET THEN
       newSL=0
    ENDIF
    //manage long positions
    IF LONGONMARKET THEN
       //first move (breakeven)
       IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
          newSL = tradeprice(1)+trailingstep*pipsize
       ENDIF
       //next moves
       IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
          newSL = newSL+trailingstep*pipsize
       ENDIF
    ENDIF
    //manage short positions
    IF SHORTONMARKET THEN
       //first move (breakeven)
       IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THEN
          newSL = tradeprice(1)-trailingstep*pipsize
       ENDIF
    //next moves
       IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
          newSL = newSL-trailingstep*pipsize
       ENDIF
    ENDIF
    //stop order to exit the positions
    IF newSL>0 THEN
       SELL AT newSL STOP
       EXITSHORT AT newSL STOP
    ENDIF
    //***************************************************************************************
    //                                       LONG trades
    //***************************************************************************************
    a1 = close > open                                         //BULLish bar
    a2 = (RsiVal < RsiLimitBuy)  AND (RsiVal > RsiVal[1])     //Rsi   in OS and North bound
    a3 = (StocK < StocLimitBuy) AND (StocK > StocD)           //Stoch in OS and North bound
    IF a1 AND a2 AND a3 THEN
       BUY nLots CONTRACT AT MARKET
    ENDIF
    //***************************************************************************************
    //                                      SHORT trades
    //***************************************************************************************
    b1 = close < open                                         //BEARish bar
    b2 = (RsiVal > RsiLimitSell)  AND (RsiVal < RsiVal[1])    //Rsi   in OB and South bound
    b3 = (StocK > StocLimitSell) AND (StocK < StocD)          //Stoch in OB and South bound
    IF b1 AND b2 AND b3 THEN
       SELLSHORT nLots CONTRACT AT MARKET
    ENDIF
    //
    SET TARGET PPROFIT TP
    SET STOP PLOSS     SL

    It is over optimized, though. I’ll demo it for a while.

    Nicolas thanked this post
    #40676 quote
    GraHal
    Participant
    Master

    Wow Robert that looks great! Would have taken me all next week to get that sorted, if even then! 🙂

    Results stats look healthy … ‘gain to loss ratio’ and % winning trades. Love how your variables and comments line up … I have trouble with lack of ‘text contrast’ on the PRT Coding window and vertical alignment makes it so much easier.

    I’ll check it out further over the weekend.

    Many Thanks for your time, effort and for sharing
    GraHal

    #40789 quote
    robertogozzi
    Moderator
    Master

    Actually the above strategy was Strategy #1 (of group 3).

    #40790 quote
    robertogozzi
    Moderator
    Master

    Here is another one, Strategy #2 (of group 3), still using Nicolas’trailing stop code:

    //-------------------------------------------------------------------------
    //                             Macd-Mfi DAX 5 min
    //-------------------------------------------------------------------------
    DEFPARAM CumulateOrders     = False
    DEFPARAM FlatBefore         = 090000                      //no trades before 09:00:00
    DEFPARAM FlatAfter          = 213000                      //no trades after  21:30:00
     
    ONCE nLots                  = 1                           //number of LOTs traded
     
    ONCE TP                     = 60                          //60    pips Take Profit
    ONCE SL                     = 40                          //40    pips Stop Loss
    
    ONCE Macd1                  = 14                          //14
    ONCE Macd2                  = 32                          //32
    ONCE Macd3                  = 9                           //9
    MacdVal                     = MACD[Macd1,Macd2,Macd3](close)
    MacdSignal                  = MACDline[Macd1,Macd2,Macd3](close)
    
    MfiVal                      = MoneyFlow[23](close)        //23
    //***************************************************************************************
    IF LongOnMarket THEN
       IF MacdSignal CROSSES UNDER MacdVal THEN
          SELL AT MARKET                                      //Exit LONGs when MACD reverses southwards
       ENDIF
    ENDIF
    IF ShortOnMarket THEN
       IF MacdSignal CROSSES OVER MacdVal THEN
          EXITSHORT AT MARKET                                 //Exit SHORTs when MACD reverses northwards
       ENDIF
    ENDIF
    //***************************************************************************************
    trailingstart = 2      //2     trailing will start @trailinstart points profit
    trailingstep  = 8      //8     trailing step to move the "stoploss"
    //reset the stoploss value
    IF NOT ONMARKET THEN
       newSL=0
    ENDIF
    //manage long positions
    IF LONGONMARKET THEN
       //first move (breakeven)
       IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
          newSL = tradeprice(1)+trailingstep*pipsize
       ENDIF
       //next moves
       IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
          newSL = newSL+trailingstep*pipsize
       ENDIF
    ENDIF
    //manage short positions
    IF SHORTONMARKET THEN
       //first move (breakeven)
       IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THEN
          newSL = tradeprice(1)-trailingstep*pipsize
       ENDIF
       //next moves
       IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
          newSL = newSL-trailingstep*pipsize
       ENDIF
    ENDIF
    //stop order to exit the positions
    IF newSL>0 THEN
       SELL AT newSL STOP
       EXITSHORT AT newSL STOP
    ENDIF
    //***************************************************************************************
    //                                       LONG trades
    //***************************************************************************************
    a1 = close > open                                         //BULLish bar
    a2 = MacdSignal CROSSES OVER MacdVal                      //MACD goes North
    a3 = (MfiVal > 3200) AND (MfiVal > MfiVal[1])             //3200 Mfi limit
    IF a1 AND a2 AND a3 THEN
       BUY nLots CONTRACT AT MARKET
    ENDIF
    //***************************************************************************************
    //                                      SHORT trades
    //***************************************************************************************
    b1 = close < open                                         //BEARish bar
    b2 = MacdSignal CROSSES UNDER MacdVal                     //MACD goes South
    b3 = (MfiVal < -3200) AND (MfiVal < MfiVal[1])            //-3200 Mfi limit
    IF b1 AND b2 AND b3 THEN
       SELLSHORT nLots CONTRACT AT MARKET
    ENDIF
    //
    SET TARGET PPROFIT TP
    SET STOP PLOSS     SL
    //GRAPH MfiVal AS "Mfi"
    

    Tested on DAX 5-min TF.

    #40793 quote
    robertogozzi
    Moderator
    Master

    It’s the first time I tackle with MFI and I’d like a confirmation that this is the correct way it should be used.

    Thank you.

    Roberto

    #40836 quote
    GraHal
    Participant
    Master

    Wow you’ve been busy again!

    I knocked 1 hour off the times to change from UTC +2 (Italy) to UTC +1 (UK).

    Attached are the equity curves I get on the DAX at 100k bars.

    Re Strategy #2 (of group 3) … are your results over 200k bars Robert?

    Thank You
    Graham

    #40839 quote
    robertogozzi
    Moderator
    Master

    No, I only started from Jan. 1, 2017 through last friday. Anyway I am using IG, so my limit would be 100k.

    I am planning to try to build the strategy #3 of group 3, but it involves oscillators/indicators not built-in so its execution will be slower, but I still wanna have a try over the next couple of days.

    GraHal thanked this post
    #40846 quote
    GraHal
    Participant
    Master

    Right I’ve got my results for Strategy #2 (of group 3) exact same as yours now … 16 Trades all winners since 4 Jan 17 … see attached.

    I’m on spreadbet with IG so I increased Lot size to 25 to get exact same figures as you (I would only trade £1 per point to see how it goes).

    I love both Strats cos they’re in and out in a few bars (they don’t sit there for hours (while I’m stressing! :)) as losers  hoping ‘all will come right in the end’!) To my logic, this is what a short TF Strat should do … ride the short term cycles!?

    Onward and Upward … looking good!

    Many Thanks for your ongoing work Roberto (apols for Robert in previous)
    GraHal

    robertogozzi thanked this post
    #40851 quote
    robertogozzi
    Moderator
    Master

    As to strategy #3 of group 3, it involves a Relative Vigor Index which I haven’t found around here.

    In a new post I’ll ask Nicolas if he can translate it from a Metastock code I have found over the internet.

    #40866 quote
    AVT
    Participant
    Senior
    #40870 quote
    AVT
    Participant
    Senior

    That’s the code how I understood the description in mql5 page

    // === RVI Relative Vigor Indicator
    
    //VALUE1 = ((CLOSE - OPEN) + 2 * (CLOSE (1)) - OPEN (1)) + 2*(CLOSE (2) - OPEN (2)) + (CLOSE (3) - OPEN (3))) / 6
    //VALUE2 = ((HIGH - LOW) + 2 * (HIGH (1) - LOW (1)) + 2*(HIGH (2)- LOW (2)) + (HIGH (3) - LOW (3))) / 6
    //NUM = SUM (VALUE1, N)
    //DENUM = SUM (VALUE2, N)
    //RVI = NUM / DENUM
    //RVISig = (RVI + 2 * RVI (1) + 2 * RVI (2) + RVI (3)) / 6
    // ..........................
    //OPEN — is the opening price;
    //HIGH — is the maximum price;
    //LOW — is the minimum price;
    //CLOSE — is the closing price;
    //VALUE1 — symmetrically weighted moving average of the differences of the closing and openings prices;
    //VALUE2 — symmetrically weighted moving average of the differences of the maximum and minimum prices;
    //NUM — amount N importances of VALUE1;
    //DENUM —amount N importances of VALUE2;
    //RVI — value of the Relative Vigor Index indicator for the current bar;
    //RVISig — value of the RVI signal line for the current bar;
    //N — period of the smoothing
    // ..............................
    period=10
    VALUE1 = ((CLOSE - OPEN) + 2*(CLOSE[1] - OPEN[1]) + 2*(CLOSE[2] - OPEN[2]) + (CLOSE[3] - OPEN[3])) / 6
    VALUE2 = ((HIGH - LOW) + 2*(HIGH[1] - LOW[1]) + 2*(HIGH[2]- LOW[2]) + (HIGH[3] - LOW[3])) / 6
    NUM = VALUE1 * period
    DENUM = VALUE2 * period
    RVI = NUM / DENUM
    RVISig = (RVI + 2 * RVI[1] + 2 * RVI[2] + RVI[3]) / 6
    
    return RVI as "rvi", RVISig as "rvi signal"
    robertogozzi thanked this post
    #40924 quote
    GraHal
    Participant
    Master

    For info, I got a ‘divide by zero’ error overnight on Strat #02 – Macd-Mfi-DAX-5-min.itf code at Post #40790 . The Strat was Quit / closed due to the error.

    #40938 quote
    robertogozzi
    Moderator
    Master

    I incurred the same error this morning (nighttime) at 02:00 (gmt +0) as from attached pics.

    Pic (1) is just the error; Pic(2) is the screenshot of the DAX 5-min chart at that time; Pic(3) is the screenshot where I outlined variable MFI with a value of -0, which is likely to be the problem.

    I tried to replicate the error with ProBackTest, extending the final time to the last current bar, but it did not work, I don’t know why ProOrder behaves differently from ProBackTest.

    I am afraid the oscillator MFI is not used correctly (it was the first time I used it). Also, this may happen due to overnight closure of DAX, because the strategy keeps running and evaluating each bar continuosly. What’s the data contained in a NON-exixting 5-min bar?

    I hope Nicolas will help when back from his leave.

    GraHal thanked this post
    #40951 quote
    AVT
    Participant
    Senior

    @robertogozzi

    In the Strategy No 2: where do you get these border values from?

    //***************************************************************************************
    //                                       LONG trades
    //***************************************************************************************
    a1 = close > open                                         //BULLish bar
    a2 = MacdSignal CROSSES OVER MacdVal                      //MACD goes North
    a3 = (MfiVal > 3200) AND (MfiVal > MfiVal[1])             //3200 Mfi limit
    IF a1 AND a2 AND a3 THEN
       BUY nLots CONTRACT AT MARKET
    ENDIF
    //***************************************************************************************
    //                                      SHORT trades
    //***************************************************************************************
    b1 = close < open                                         //BEARish bar
    b2 = MacdSignal CROSSES UNDER MacdVal                     //MACD goes South
    b3 = (MfiVal < -3200) AND (MfiVal < MfiVal[1])            //-3200 Mfi limit
    IF b1 AND b2 AND b3 THEN
       SELLSHORT nLots CONTRACT AT MARKET
    ENDIF

    If I open the MFI Indicator in PRT, it has default borders of 20/80 and looking at the picture in the original article, it’s the same there. Thanks.

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

Trading the 5 Min Bar


ProOrder support

New Reply
Author
Summary

This topic contains 66 replies,
has 8 voices, and was last updated by Gertrade
7 years, 11 months ago.

Topic Details
Forum: ProOrder support
Language: English
Started: 07/13/2017
Status: Active
Attachments: 38 files
Logo Logo
Loading...