Trading the 5 Min Bar
Forums › ProRealTime English forum › ProOrder support › Trading the 5 Min Bar
- This topic has 66 replies, 8 voices, and was last updated 6 years ago by Gertrade.
-
-
07/18/2017 at 1:23 PM #40965
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!!!
07/18/2017 at 3:07 PM #40992If 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
07/18/2017 at 3:46 PM #4099507/18/2017 at 4:00 PM #40997I 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.
07/18/2017 at 4:59 PM #41007Volume 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
07/18/2017 at 5:20 PM #41017Very 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??
07/18/2017 at 7:42 PM #41032Guess 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. 😉
07/18/2017 at 7:52 PM #41034Roberto 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.
07/18/2017 at 11:01 PM #41039Of 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?!
1 user thanked author for this post.
07/19/2017 at 11:35 AM #41060Hi @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:
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495//-----------------------------------------------------------------------------------------// 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 = FalseDEFPARAM FlatBefore = 090000 //no trades before 09:00:00DEFPARAM FlatAfter = 213000 //no trades after 21:30:00ONCE nLots = 1 //number of LOTs tradedONCE TP = 53 //53 pips Take ProfitONCE SL = 14 //14 pips Stop LossONCE Macd1 = 22 //22ONCE Macd2 = 32 //32ONCE Macd3 = 9 //9MacdVal = MACD[Macd1,Macd2,Macd3](close)MacdSignal = MACDline[Macd1,Macd2,Macd3](close)//MfiVal = MoneyFlow[9](close) //9//ONCE MfiLimitBuy = 3200 //3200//ONCE MfiLimitSell = -MfiLimitBuyMfiVal, ignored, ignored, ignored = CALL "Twiggs Money Flow"[2, 21] //2=Wma 21=barsONCE MfiLimitBuy = -0.02 //-0.02ONCE MfiLimitSell = -MfiLimitBuy//***************************************************************************************IF LongOnMarket THENIF MacdSignal CROSSES UNDER MacdVal THENSELL AT MARKET //Exit LONGs when MACD reverses southwardsENDIFENDIFIF ShortOnMarket THENIF MacdSignal CROSSES OVER MacdVal THENEXITSHORT AT MARKET //Exit SHORTs when MACD reverses northwardsENDIFENDIF//************************ NICOLAS'trailing stop code *********************************trailingstart = 1 //1 trailing will start @trailinstart points profittrailingstep = 20 //20 trailing step to move the "stoploss"//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THENnewSL = tradeprice(1)+trailingstep*pipsizeENDIF//next movesIF newSL>0 AND close-newSL>=trailingstep*pipsize THENnewSL = newSL+trailingstep*pipsizeENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THENnewSL = tradeprice(1)-trailingstep*pipsizeENDIF//next movesIF newSL>0 AND newSL-close>=trailingstep*pipsize THENnewSL = newSL-trailingstep*pipsizeENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIF//***************************************************************************************// LONG trades//***************************************************************************************a1 = close > open //BULLish bara2 = MacdSignal CROSSES OVER MacdVal //MACD goes Northa3 = (MfiVal < MfiLimitBuy)// AND (MfiVal > MfiVal[1]) //< Mfi limit AND > previousIF a1 AND a2 AND a3 THENBUY nLots CONTRACT AT MARKETENDIF//***************************************************************************************// SHORT trades//***************************************************************************************b1 = close < open //BEARish barb2 = MacdSignal CROSSES UNDER MacdVal //MACD goes Southb3 = (MfiVal > MfiLimitSell)// AND (MfiVal < MfiVal[1]) //> Mfi limit AND < previousIF b1 AND b2 AND b3 THENSELLSHORT nLots CONTRACT AT MARKETENDIF//SET TARGET PPROFIT TPSET STOP PLOSS SL//GRAPH MfiVal AS "Mfi"and the code for the oscillator:
1234567891011121314151617181920212223242526272829303132333435REM 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-trlif trc=0.9999999 thentrc=trcendif//adv=VOLUME*((close-trl)-(trh-close))/trcwv=VOLUME+(VOLUME[1]*0)wmV=Average[length,t](wv)wmA=Average[length,t](adv)//if wmV=0 thenwmV=0elsetmf=wmA/wmVendif//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
07/19/2017 at 11:47 AM #41067Sorry 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!
07/19/2017 at 6:29 PM #41100No 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
GraHalPS I just deleted the 2 from Twiggs Money Flow[2, 21] and it ran okay, but that can’t be correct, surely?
07/19/2017 at 6:57 PM #41104Aha …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?
07/20/2017 at 7:04 AM #41121I 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:
12345678910111213141516171819202122232425262728293031323334353637REM 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 thenlength=21endif//trh=MAX(close[1],high)trl=MIN(close[1],low)trc=trh-trlif trc=0.9999999 thentrc=trcendif//adv=VOLUME*((close-trl)-(trh-close))/trcwv=VOLUME+(VOLUME[1]*0)wmV=Average[length,t](wv)wmA=Average[length,t](adv)//if wmV=0 thenwmV=0elsetmf=wmA/wmVendif//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:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091//-------------------------------------------------------------------------// Macd-Mfi DAX 5 min//-------------------------------------------------------------------------DEFPARAM CumulateOrders = FalseDEFPARAM FlatBefore = 090000 //no trades before 09:00:00DEFPARAM FlatAfter = 213000 //no trades after 21:30:00ONCE nLots = 1 //number of LOTs tradedONCE TP = 53 //53 pips Take ProfitONCE SL = 14 //14 pips Stop LossONCE Macd1 = 22 //22ONCE Macd2 = 32 //32ONCE Macd3 = 9 //9MacdVal = MACD[Macd1,Macd2,Macd3](close)MacdSignal = MACDline[Macd1,Macd2,Macd3](close)//MfiVal = MoneyFlow[9](close) //9//ONCE MfiLimitBuy = 3200 //3200//ONCE MfiLimitSell = -MfiLimitBuyMfiVal, ignored, ignored, ignored = CALL "Twiggs Money Flow"[2,25] //2=Wma 25=barsONCE MfiLimitBuy = -0.02 //-0.02ONCE MfiLimitSell = -MfiLimitBuy//***************************************************************************************IF LongOnMarket THENIF MacdSignal CROSSES UNDER MacdVal THENSELL AT MARKET //Exit LONGs when MACD reverses southwardsENDIFENDIFIF ShortOnMarket THENIF MacdSignal CROSSES OVER MacdVal THENEXITSHORT AT MARKET //Exit SHORTs when MACD reverses northwardsENDIFENDIF//***************************************************************************************trailingstart = 1 //1 trailing will start @trailinstart points profittrailingstep = 20 //20 trailing step to move the "stoploss"//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THENnewSL = tradeprice(1)+trailingstep*pipsizeENDIF//next movesIF newSL>0 AND close-newSL>=trailingstep*pipsize THENnewSL = newSL+trailingstep*pipsizeENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THENnewSL = tradeprice(1)-trailingstep*pipsizeENDIF//next movesIF newSL>0 AND newSL-close>=trailingstep*pipsize THENnewSL = newSL-trailingstep*pipsizeENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIF//***************************************************************************************// LONG trades//***************************************************************************************a1 = close > open //BULLish bara2 = MacdSignal CROSSES OVER MacdVal //MACD goes Northa3 = (MfiVal < MfiLimitBuy)// AND (MfiVal > MfiVal[1]) //< Mfi limit AND > previousIF a1 AND a2 AND a3 THENBUY nLots CONTRACT AT MARKETENDIF//***************************************************************************************// SHORT trades//***************************************************************************************b1 = close < open //BEARish barb2 = MacdSignal CROSSES UNDER MacdVal //MACD goes Southb3 = (MfiVal > MfiLimitSell)// AND (MfiVal < MfiVal[1]) //> Mfi limit AND < previousIF b1 AND b2 AND b3 THENSELLSHORT nLots CONTRACT AT MARKETENDIF//SET TARGET PPROFIT TPSET STOP PLOSS SL//GRAPH MfiVal AS "Mfi"I am still eager to see if any error is reported after 090000 (no errors overnight, though).
07/20/2017 at 5:03 PM #41177Looking 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 -
AuthorPosts
Find exclusive trading pro-tools on