Trading the 5 Min Bar

Viewing 15 posts - 31 through 45 (of 67 total)
  • Author
    Posts
  • #41295 quote
    robertogozzi
    Moderator
    Master

    Finally the last strategy, Strategy #3 of group 3, along with the 3 indicators:

    //-------------------------------------------------------------------------
    //                       Klinger-Rvi-Lsma 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                     = 23                          //23    pips Take Profit
    ONCE SL                     = 16                          //16    pips Stop Loss
    
    RviVal, RviSignal           = CALL "RVI by John Ehlers"[7]                  //7
    KlingerVal, KlingerTrigger  = CALL "Klinger oscillator"[25,44,55,1]         //25,44,55,1 (ema)
    LeastSquareEMA              = CALL "ELSMA - Least Square EMA"[11,4]         //11,4
    //***************************************************************************************
    IF LongOnMarket THEN
       IF close < LeastSquareEMA THEN
          SELL AT MARKET                                      //Exit LONGs when MACD reverses southwards
       ENDIF
    ENDIF
    IF ShortOnMarket THEN
       IF close > LeastSquareEMA THEN
          EXITSHORT AT MARKET                                 //Exit SHORTs when MACD reverses northwards
       ENDIF
    ENDIF
    //***************************************************************************************
    trailingstart = 10     //10    trailing will start @trailinstart points profit
    trailingstep  = 13     //13    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 = KlingerTrigger CROSSES OVER KlingerVal               //Klinger trigger is going north
    a3 = RviSignal CROSSES OVER RviVal                        //RVI long signal occurred
    IF a1 AND a2 AND a3 THEN
       BUY nLots CONTRACT AT MARKET
    ENDIF
    //***************************************************************************************
    //                                      SHORT trades
    //***************************************************************************************
    b1 = close < open                                         //BEARish bar
    b2 = KlingerTrigger CROSSES UNDER KlingerVal              //Klinger trigger is going south
    b3 = RviSignal CROSSES UNDER RviVal                       //RVI short signal occurred
    IF b1 AND b2 AND b3 THEN
       SELLSHORT nLots CONTRACT AT MARKET
    ENDIF
    //
    SET TARGET PPROFIT TP
    SET STOP PLOSS     SL

    ElSMA indicator:

    //-------------------------------------------------//
    // ELSMA - Exponential Least Square Moving Average //
    //-------------------------------------------------//
    DEFPARAM CalculateOnLastBars = 200
    Period = MAX(Period, 1)
    if NumBars < 1 then
       NumBars = 4
    endif
    LR = LinearRegression[NumBars](close)
    AFR = ExponentialAverage[Period](LR)
    RETURN AFR

    RVI indicator:

    // Relative Vigor Index (RVI) by John Ehlers
    //     Paramètres:
    //         Per = periods for summation (12 as défault)
    
    DEFPARAM CalculateOnLastBars = 200
    
    diff = close - open
    ind1 = (diff  + 2*diff[1]  + 2*diff[2]  + diff[3])  / 6
    ind2 = (Range + 2*Range[1] + 2*Range[2] + Range[3]) / 6
     
    cond = Summation[per](ind2)
    IF cond = 0 THEN
       temp = 0.0001
    
    ELSE
       temp = cond
    ENDIF
     
    RVI     = Summation[per](ind1) / temp
    RVIsig  = (RVI + 2*RVI[1] + 2*RVI[2] + RVI[3]) / 6
     
    RETURN RVI COLOURED (255, 0, 0) AS"Relative Vigor Index", RVIsig COLOURED (0, 0, 255) AS"Relative Vigor Index Signal"

    KLINGER oscillator:

    //                   KLINGER oscillator
    
    // variable AVGTYPE can hold values:
    //
    //       0 = SMA
    //       1 = EMA
    //       2 = WMA
    //       3 = Wilder MA
    //       4 = Triangular MA
    //       5 = End point MA
    //       6 = Time series MA
    //------------------------------------------------
    DEFPARAM CalculateOnLastBars = 200
    
    hlc3= (high + low + close)/3
    
    if(hlc3>hlc3[1]) THEN
       xTrend = volume * 100
    ELSE
       xTrend = -volume * 100
    ENDIF
    
    if (AvgType < 0) OR (AvgType > 6) then     //default to ONE if parameter is
       AvgType = 1                             //               out of range 0-6
    endif
    
    xFast    = average[FastX,AvgType](xTrend)
    xSlow    = average[SlowX,AvgType](xTrend)
    xKvO     = xFast-xSlow
    xTrigger = average[TrigLen,AvgType](xKvO)
    
    RETURN xKvO AS "Klinger oscillator", xTrigger AS "trigger"

    This strategy is not performing like the first two in the group.

    Any suggestion for improvements is highly welcome!

    ELSMA-Least-Square-EMA.itf Klinger-oscillator.itf Klinger-Rvi-Lsma-DAX-5-min.itf RVI-by-John-Ehlers.itf
    #41300 quote
    robertogozzi
    Moderator
    Master
    #41303 quote
    GraHal
    Participant
    Master

    Wow busy again Roberto! Looks good, I’ll try it out later, thank you for sharing.

    I’m ‘licking my wounds’ at the mo as I got on the wrong side of the DAX rout today and I let it run thinking the price drop would pull back! 🙁

    Cheers
    GraHal

    #41304 quote
    robertogozzi
    Moderator
    Master

    Sorry to hear that!

    That’s why I am spending time and efforts on automated trading, I fear my mind… I’ve experienced your same situation several times before and want to find a way to skip over emotions.

    I am just demoing some strategies, some not good, some seem good, but I am waiting for a better engine from PRT, multi timeframe and more data and speed for backtests!

    Roberto

    GraHal and Inertia thanked this post
    #41318 quote
    Nicolas
    Keymaster
    Master

    I just read the whole thread, great work Roberto! How can I help? I read about a zero divide problem? What is the code involved?

    #41330 quote
    robertogozzi
    Moderator
    Master

    Hello Nicolas, welcome back. Hope you enjoyed your leave!

    The code is the one posted here https://www.prorealcode.com/topic/trading-the-5-min-bar/#post-40790

    it uses the Money Flow Index, which I had never used before. When added to a chart it behaves correctly, within the limits (80 – 20), but when referenced in a strategy its values yields odd results, ranging from, say, +20000 to -10000.

    Also, at night the strategy has been always closed due to “divide by zero” error.

    At that point I, and GraHal, did not know what to do. I found an alternate MFI, the Twiggs MFI (post https://www.prorealcode.com/topic/trading-the-5-min-bar/page/2/#post-41060), which has no divide by zero issues and returns very different values.

    The strategy works, but I fear that is not what the original strategy is all about (strategy #2 of group 3 from post https://www.prorealcode.com/topic/trading-the-5-min-bar/#post-40591).

    #41331 quote
    robertogozzi
    Moderator
    Master

    We would like to know about your experience with Money Flow Index, why the “divide by zero” error was returned and what is the difference between the built-in Money Flow Index and the Twiggs MFI I used.

    As for the other two strategies posted, there are being demoed with no error.

    Thank you.

    #41356 quote
    Nicolas
    Keymaster
    Master

    I think it’s because MFI use Volumes in its calculation and no Volumes are sent on DAX before Futures contracts open. So you should restrain the use of the indicator in periods where Volume>0.

    money-flow-index-calculation.png money-flow-index-calculation.png
    #41371 quote
    robertogozzi
    Moderator
    Master

    You mean this way:

    IF time >= 080000 AND time <= 210000 THEN
       .
       .             //my strategy goes here
       .
    ENDIF

    ?

    In this case BARS outside that time range ARE not evaluated by ProOrder?

    Because if they are evaluated nonetheless, so will be the oscillator and the outcome wouldn’t change!!!

    #42168 quote
    JR1976
    Participant
    Veteran

    HI Roberto seems an  interest code

    Do you using just in real account ?

    Regards .

    #42169 quote
    JR1976
    Participant
    Veteran

    Sorry I’am referring  to Stochastic+RSI+TEMA  on DAX 5min  the first strategy in the post

    #42173 quote
    robertogozzi
    Moderator
    Master

    No JR1976, I’ll run it in my demo account till the end of the year!

    Roberto

    JR1976 thanked this post
    #58568 quote
    GraHal
    Participant
    Master

    I’m back on this @robertogozzi

    What is your opinion now (after saying) … I’ll run it in my demo account till the end of the year!

    I got the divide by zero error yesterday (again) … did we ever get a cure to the issue? Do you still get the divide by zero issue?

    What version code incorporates the fix (if any?) please?

    Many Thanks
    GraHal

    #58575 quote
    GraHal
    Participant
    Master

    Mods please could you move this Topic to the ProOrder Support Forum?

    After Roberto kind help the emphasis turned more onto a coded Strat  …  I’m glad to say! 🙂

    #58578 quote
    Vonasi
    Moderator
    Master

    I was getting a ‘divide by zero’ error in one of my strategies the other day and so just threw in a quick fix which seems to have done the job. Just turn the offending variable into something close to zero that is not zero.

    UpBar = close > open
    DownBar = close < open
    
    OL = Open - Low
    HO = High - Open
    
    IF OL <= 0 THEN
    OL = 0.0000001
    ENDIF
    
    IF HO <= 0 THEN
    HO = 0.0000001
    ENDIF
    
    UpTen = OL/HO < Perc
    DownTen = HO/OL < Perc
    GraHal thanked this post
Viewing 15 posts - 31 through 45 (of 67 total)
  • You must be logged in to reply to this topic.

Trading the 5 Min Bar


ProOrder: Automated Strategies & Backtesting

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: Automated Strategies & Backtesting
Language: English
Started: 07/13/2017
Status: Active
Attachments: 38 files
Logo Logo
Loading...