Trading the 5 Min Bar

Viewing 15 posts - 16 through 30 (of 67 total)
  • Author
    Posts
  • #40965 quote
    robertogozzi
    Moderator
    Master

    That was the first time I used it. I GRAPHed its value and discovered a rango from, say, -6000 to, say, +8000. So, after some tests I found those values as the most profitable.

    I don’t know why this behaviour, I also tried it on FTSE100 and result were similar, oscillating from +35000 down to -23000.

    On currencies variable MFI is reported as ZERO.

    I really don’t know and I wouldn’t run it on live accounts!!!

    #40992 quote
    GraHal
    Participant
    Master

    If you add MFI / Money Flow Index to the DAX Chart (at the bottom on it’s own) then the value ranges from a max of +100 to a min of -100.

    MFI is zero on currencies as on IG there is no volume on currencies.

    I’ll try optimising between +100 and -100 and let you know.

    GraHal

    #40995 quote
    GraHal
    Participant
    Master

    Doesn’t look good. If other variables are optimised alongside new values for MFI then it might all come good together?

    #40997 quote
    robertogozzi
    Moderator
    Master

    I tried adding MFI at the bottom of the chart, as you suggested, but still I get values from +7000 down to -32000, as from the pic.

    I really don’t know how that oscillator is built, how it is used and whether volume data are accurate.

    #41007 quote
    GraHal
    Participant
    Master

    Volume is only volume generated by IG clients and maybe I guess I’m using spreadbet volume  and you’re using CFD volume.

    See attached, set yours as lines (not histogram) and see if it makes any difference?

    Here’s some info on MFI and a variation … the Twiggs MFI  … might be of use.

    https://www.prorealcode.com/documentation/moneyflowindex/

    https://www.prorealcode.com/prorealtime-indicators/twiggs-money-flow/

    GraHal

    #41017 quote
    GraHal
    Participant
    Master

    Very weird, make sure you tell us what’s going on on your MFI chart when you find out Roberto?

    I can’t think what it could be sorry, but a man who might know may be along soon!? But I heard he’s paddling and eating ice cream in the sun?? 🙂

    PS does the format of your Y axis scale need changing and the horizontal line isn’t 56,545 but it is 56.45??

    #41032 quote
    AVT
    Participant
    Senior

    Guess this MFI thing is just left to be a matter of “solving ambition”. I don’t see any real use in it with such different results and decided to forget about it. But that’s just my decision because I don’t robot and there’s enough stuff I can use – so why waste time on it which I can better use for other things. If you want to continue I wish you THAT inspiration which gets you going. 😉

    #41034 quote
    GraHal
    Participant
    Master

    Roberto is trying to reproduce the 3 strategies detailed in the .pdf in the 1st post.

    The 3 Strats are purported to be very successful / profitable and so it’s worth bottoming out the Issues with the MFI. It is a useful Indicator, I guess genuine / ‘whole market volume’ (if ever available?) would make MFI more meaningful.

    #41039 quote
    robertogozzi
    Moderator
    Master

    Of course it’s “solving ambition” question.

    If I don’t know something, nor how to handle it, I don’t like yo turn my head and let it go. I want to find out why it is not working, how I should use/code it and whether there are better options (like GraHal wrote above).

    Afterwards I’ll pass on to the last strategy still in the works!

    I know there are many good strategies out there, but how can you say this is not the best one until it’s working as expected?!

    GraHal thanked this post
    #41060 quote
    robertogozzi
    Moderator
    Master

    [attachment file=”41061″]

    Hi @GraHal, I modified the code replacing the built-in MFI with the oscillator you suggested, it seems to work correctly. We’ll see tonight what’s gonna happen after DAX closes!

    Here’s the code for the strategy:

    //-----------------------------------------------------------------------------------------
    // Jul 19, 2017                             Macd-Mfi DAX 5 min
    //
    // Version 2:  modified to replace built-in MFI (Money Flow Index) with
    //             external Twiggs Money Flow
    //             (link https://www.prorealcode.com/prorealtime-indicators/twiggs-money-flow/)
    //-----------------------------------------------------------------------------------------
    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                     = 53                          //53    pips Take Profit
    ONCE SL                     = 14                          //14    pips Stop Loss
    
    ONCE Macd1                  = 22                          //22
    ONCE Macd2                  = 32                          //32
    ONCE Macd3                  = 9                           //9
    MacdVal                     = MACD[Macd1,Macd2,Macd3](close)
    MacdSignal                  = MACDline[Macd1,Macd2,Macd3](close)
    
    //MfiVal                      = MoneyFlow[9](close)       //9
    //ONCE MfiLimitBuy            = 3200                      //3200
    //ONCE MfiLimitSell           = -MfiLimitBuy
    MfiVal, ignored, ignored, ignored = CALL "Twiggs Money Flow"[2, 21]      //2=Wma      21=bars
    ONCE MfiLimitBuy            = -0.02                                      //-0.02
    ONCE MfiLimitSell           = -MfiLimitBuy
    //***************************************************************************************
    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
    //************************  NICOLAS'trailing stop code  *********************************
    trailingstart = 1      //1     trailing will start @trailinstart points profit
    trailingstep  = 20     //20    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 < MfiLimitBuy)//  AND (MfiVal > MfiVal[1])   //< Mfi limit AND > previous
    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 > MfiLimitSell)// AND (MfiVal < MfiVal[1])   //> Mfi limit AND < previous
    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"

    and the code for the oscillator:

    REM TWIGGS MONEY FLOW
    // adaptación del código de LazyBear en tradingview para PRT
    //        parámetro t (tipo de media en cuadro de variables):
    //
    //       0 = SMA
    //       1 = EMA
    //       2 = WMA
    //       3 = Wilder
    //       4 = Triangular
    //       5 = End point
    //       6 = Time series
    //
    DEFPARAM CalculateOnLastBars = 200
    //
    length=21
    //
    trh=MAX(close[1],high)
    trl=MIN(close[1],low)
    trc=trh-trl
    if trc=0.9999999 then
    trc=trc
    endif
    //
    adv=VOLUME*((close-trl)-(trh-close))/trc
    wv=VOLUME+(VOLUME[1]*0)
    wmV=Average[length,t](wv)
    wmA=Average[length,t](adv)
    //
    if wmV=0 then
    wmV=0
    else
    tmf=wmA/wmV
    endif
    //
    RETURN tmf as "twiggs money flow",0 as "0",0.20 as "0.20",-0.20 as "-0.20"

    As for variables a3 and b3 I commented out the reference to the previous bar, since it’s performing slightly better.

    I attached a wrong picture, the correct one is the one with V2 in the name.

    I still don’t know how to reference a username with a link, sorry for that!!!

    Roberto

    #41067 quote
    robertogozzi
    Moderator
    Master

    Sorry for the mess, when edited my post I clicked the wrong place and added the old pic (the wrong one I wanted to discard) to the text. Sorry again!

    #41100 quote
    GraHal
    Participant
    Master

    No need for sorry, you’re doing a grand job Roberto!

    I just copy a username direct from a post by the user and paste. I don’t know why we copy as a link really? 🙂 Be easier to type username in red text? Oh I know, it saves spelling names wrong as I did a few times with yours, so it’s sorry from me now! 🙂

    I am itching to try your new version, but I keep getting the error attached. Do you know how to fix it please? Do you not get the same error when you try and backtest?

    If I delete the 2 from Twiggs Money Flow[2, 21] then it runs, but that can’t be correct, surely?

    Maybe copy the code for the Twiggs Money Flow direct into the Strat Code as a separate section (at the top or bottom?). This would also reduce backtest time as there would be no CALL out to an indicator?

    Thank You
    GraHal

    PS I just deleted the 2 from Twiggs Money Flow[2, 21] and it ran okay, but that can’t be correct, surely?

    #41104 quote
    GraHal
    Participant
    Master

    Aha …its the 21 that needs deleting cos 21 is built into the Indicator by default, but can be changed externally if the Twiggs Money Flow is added as a separate Indicator (in its own window).

    Results attached for Lot size 1 on IG SBet.  I’ll set it going Live and report back if I get the ‘divide by zero error’.

    Good Work Roberto

    PS It would still be good if the Twiggs Indicator was copied direct into the Strat code as then the Length (21 currently) would be available as a variable for optimising?

    #41121 quote
    robertogozzi
    Moderator
    Master

    I was using the same code but did not receive any error either in baxktest and demo live.

    Anyway I modified the oscillator code as follows:

    REM TWIGGS MONEY FLOW
    // adaptación del código de LazyBear en tradingview para PRT
    // parámetro t (tipo de media en cuadro de variables:) =
    //
    //       0 = SMA
    //       1 = EMA
    //       2 = WMA
    //       3 = Wilder
    //       4 = Triangular
    //       5 = End point
    //       6 = Time series
    //
    DEFPARAM CalculateOnLastBars = 200
    //
    if length = 0 then
       length=21
    endif
    //
    trh=MAX(close[1],high)
    trl=MIN(close[1],low)
    trc=trh-trl
    if trc=0.9999999 then
       trc=trc
    endif
    //
    adv=VOLUME*((close-trl)-(trh-close))/trc
    wv=VOLUME+(VOLUME[1]*0)
    wmV=Average[length,t](wv)
    wmA=Average[length,t](adv)
    //
    if wmV=0 then
       wmV=0
    else
       tmf=wmA/wmV
    endif
    //
    RETURN tmf as "twiggs money flow",0 as "0",0.20 as "0.20",-0.20 as "-0.20"

    so we can now change also the parameter LENGTH (in case it’s ZERO it’ll default it to 21).

    The modified strategy to use a different LENGTH is:

    //-------------------------------------------------------------------------
    //                             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                     = 53                          //53    pips Take Profit
    ONCE SL                     = 14                          //14    pips Stop Loss
    
    ONCE Macd1                  = 22                          //22
    ONCE Macd2                  = 32                          //32
    ONCE Macd3                  = 9                           //9
    MacdVal                     = MACD[Macd1,Macd2,Macd3](close)
    MacdSignal                  = MACDline[Macd1,Macd2,Macd3](close)
    
    //MfiVal                      = MoneyFlow[9](close)       //9
    //ONCE MfiLimitBuy            = 3200                      //3200
    //ONCE MfiLimitSell           = -MfiLimitBuy
    MfiVal, ignored, ignored, ignored = CALL "Twiggs Money Flow"[2,25]      //2=Wma      25=bars
    ONCE MfiLimitBuy            = -0.02                                      //-0.02
    ONCE MfiLimitSell           = -MfiLimitBuy
    //***************************************************************************************
    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 = 1      //1     trailing will start @trailinstart points profit
    trailingstep  = 20     //20    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 < MfiLimitBuy)//  AND (MfiVal > MfiVal[1])   //< Mfi limit AND > previous
    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 > MfiLimitSell)// AND (MfiVal < MfiVal[1])   //> Mfi limit AND < previous
    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"

    I am still eager to see if any error is reported after 090000 (no errors overnight, though).

    #41177 quote
    GraHal
    Participant
    Master

    Looking good Roberto!  I tried optimise Twiggs parameters (even though it’s a CALL by the Strat) it works great!

    For information, I found that Twiggs (2, 40) gave better results (attached – X by 25 to get same as your CFD)?

    Crazy … even after all the volatility today on the DAX the Strat didn’t trigger once, probably good that it didnt’t! 🙂

    Cheers
    GraHal

Viewing 15 posts - 16 through 30 (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...