ProRealCode - Trading & Coding with ProRealTime™
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!!!
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
Doesn’t look good. If other variables are optimised alongside new values for MFI then it might all come good together?
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.
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
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??
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. 😉
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.
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?!
[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
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!
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?
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?
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).
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
Trading the 5 Min Bar
This topic contains 66 replies,
has 8 voices, and was last updated by Gertrade
7 years, 11 months ago.
| Forum: | ProOrder support |
| Language: | English |
| Started: | 07/13/2017 |
| Status: | Active |
| Attachments: | 38 files |
The information collected on this form is stored in a computer file by ProRealCode to create and access your ProRealCode profile. This data is kept in a secure database for the duration of the member's membership. They will be kept as long as you use our services and will be automatically deleted after 3 years of inactivity. Your personal data is used to create your private profile on ProRealCode. This data is maintained by SAS ProRealCode, 407 rue Freycinet, 59151 Arleux, France. If you subscribe to our newsletters, your email address is provided to our service provider "MailChimp" located in the United States, with whom we have signed a confidentiality agreement. This company is also compliant with the EU/Swiss Privacy Shield, and the GDPR. For any request for correction or deletion concerning your data, you can directly contact the ProRealCode team by email at privacy@prorealcode.com If you would like to lodge a complaint regarding the use of your personal data, you can contact your data protection supervisory authority.