- ago
Need help to build strategy using base on "The Money Flow Oscillator"
https://www2.wealth-lab.com/wl5wiki/TASCOct2015.ashx

The Money Flow Oscillator - weekly
I like to see the strategy line line drew on chart

Thanks in advance
0
1,002
Solved
16 Replies

Reply

Bookmark

Sort
Glitch8
 ( 13.87% )
- ago
#1
It's already included in our WL7 TASC Indicators. Here I used the Filter to quickly see if we had an indicator with "Money" in the name. There it was, so I drag and dropped it into a chart.

1
- ago
#2
Thanks Glitch, I find it earlier but I'm having difficulty to convert the strategy as posted in: https://www2.wealth-lab.com/wl5wiki/TASCOct2015.ashx to WL 7, I keep getting an error
0
Cone8
 ( 23.86% )
- ago
#3
If you've got a start on it, please post what you got. Then maybe I can finish it off later this week.
0
- ago
#4
Thanks Cone, I have no coding experience.
0
- ago
#5
Hi unrielted, did you ever get this strategy recreated in WL7? I'm glad to see the indicator is included, but I am hoping someone has recreated the strategy and can share it, too.
0
- ago
#6
Here's that system recreated. The idea is to enter on a bullish divergence (MFO has rising troughs while the price has falling troughs) and the MFO is below its centerline. Exit is done when the MFO crosses above the centerline.
CODE:
using WealthLab.Backtest; using WealthLab.Core; using WealthLab.Indicators; using WealthLab.TASC; using System.Drawing; namespace WealthScript1 {    public class MFIDivergence : UserStrategyBase    {       PeakTroughCalculator _ptc, _ptcMfi;       IndicatorBase _mfi;       double swingPct = 5.0;       public override void Initialize(BarHistory bars)       {          _mfi = MoneyFlowOscillator.Series(bars, 10);          PlotIndicatorOscillator(_mfi,default,default,default,default,default,"mfi");          DrawHorzLine(50,Color.Black,2,LineStyles.Dashed,"mfi");          StartIndex = 10;          _ptc = new PeakTroughCalculator(bars, swingPct, PeakTroughReversalTypes.Percent);          _ptcMfi = new PeakTroughCalculator(_mfi, swingPct, PeakTroughReversalTypes.Percent);       }       public override void Execute(BarHistory bars, int idx)       {          if (!HasOpenPosition(bars, PositionType.Long))          {             if (_ptc.HasFallingTroughs(idx) && _ptcMfi.HasRisingTroughs(idx) && _mfi[idx] < 0)             {                PlaceTrade(bars, TransactionType.Buy, OrderType.Market);                SetBackgroundColor(bars, idx, Color.FromArgb(30, Color.Blue));             }                         }          else          {                         Position p = LastPosition;             if(_mfi.CrossesOver(0, idx))                PlaceTrade(bars, TransactionType.Sell, OrderType.Market);          }       }    } }
0
Best Answer
- ago
#7
Please explain why the Money Flow Indicator (MFI) is used in this strategy over the Money Flow Oscillator (MFO), or would it even matter?

Correct me if I'm wrong, but I usually think of an "oscillator" as varying across specific scaled limits (e.g. from -100 to +100); whereas, anything else is free wheeling without specific limits. As a result, it may not matter which one is employed in a strategy.
1
- ago
#8
QUOTE:
Please explain why the Money Flow Indicator (MFI) is used in this strategy over the Money Flow Oscillator (MFO)

My bad. Fixed the code above.
0
- ago
#9
Okay, in that case there's more to do. Please add the using statement below to the solution. You might want to globally change "_mfi" to "_mfo" and "_ptcMfi" to "_ptcMfo" too. My adjustment to the StartIndex makes more sense to me, but I can't speak for others on that. Oops, the HorzLine no longer works. I'll fix that below.

CODE:
using WealthLab.TASC; ...    _mfo = MoneyFlowOscillator.Series(bars, 10);    StartIndex = _mfo.FirstValidIndex; ...    PlotIndicatorOscillator(mfo, default, default, default, default, default, "mfo pane");    DrawHorzLine(0.0, Color.Salmon, 2, LineStyles.Dashed, "mfo pane");
It makes better money now. :-)
0
- ago
#10
Hi, has anyone updated this strategy for WL8?
0
- ago
#11
Give this a try in WL8:
CODE:
using WealthLab.Backtest; using WealthLab.Core; using WealthLab.Indicators; using WealthLab.TASC; using System.Drawing; namespace WealthScript1 {    public class MFIDivergence : UserStrategyBase    {       PeakTroughCalculator _ptc, _ptcMfi;       IndicatorBase _mfi;       double swingPct = 5.0;       public override void Initialize(BarHistory bars)       {          _mfi = MoneyFlowOscillator.Series(bars, 10);          PlotIndicatorOscillator(_mfi, default, default, default, default, default, "mfi");          DrawHorzLine(50, WLColor.Black, 2,LineStyle.Dashed, "mfi");          StartIndex = 10;          _ptc = new PeakTroughCalculator(bars, swingPct, PeakTroughReversalType.Percent);          _ptcMfi = new PeakTroughCalculator(_mfi, swingPct, PeakTroughReversalType.Percent);       }       public override void Execute(BarHistory bars, int idx)       {          if (!HasOpenPosition(bars, PositionType.Long))          {             if (_ptc.HasFallingTroughs(idx) && _ptcMfi.HasRisingTroughs(idx) && _mfi[idx] < 0)             {                PlaceTrade(bars, TransactionType.Buy, OrderType.Market);                SetBackgroundColor(bars, idx, WLColor.FromArgb(30, WLColor.Blue));             }          }          else          {             Position p = LastPosition;             if(_mfi.CrossesOver(0, idx))                PlaceTrade(bars, TransactionType.Sell, OrderType.Market);          }       }    } }
0
- ago
#12
Hi Eugene, thanks for posting this. It's good to see that the MFO indicator works well in WL8 and has consistent values with WL6. I was initially happy to see this code was returning much better backtest results than in WL6, especially since I never got it to work correctly in WL7. However....I don't think the code is entering the trade correctly. The exits look good (close when MFO crosses above 0), but the entry doesn't seem right to me. It should enter the trade when price and MFO diverge with price making a lower low, but MFO making a higher low. Take a look at the example below on $ZS that the WL8 code wanted to trade. I don't understand the entry at all.
0
Cone8
 ( 23.86% )
- ago
#13
CODE:
if (_ptc.HasFallingTroughs(idx) && _ptcMfi.HasRisingTroughs(idx) && _mfi[idx] < 0)
What's not to understand?
- ZS's last two 5% troughs were falling, and,
- MFI's last two 5% troughs were rising, and,
- MFI was less than 0
== Buy
1
- ago
#14
Cone, thank you for explaining the code, but I don't see the divergence that this strategy is supposedly tracking for entry. The highlighted bar is not a lower low (price). instead, it's the highest high in 5 trading days.
0
- ago
#15
QUOTE:
The highlighted bar is not a lower low (price). instead, it's the highest high in 5 trading days.

Don't get confused by this. There naturally is a delay in determining any peak or trough. They have to move 5% down or up (respectively) to be recognized. The trough 6 bars ago is determined on the highlighted bar, in this case.
0
Cone8
 ( 23.86% )
- ago
#16
To visualize, just plot the ZZs - replace Initialize() with this -

CODE:
      public override void Initialize(BarHistory bars)       {          _mfi = MoneyFlowOscillator.Series(bars, 10);          PlotIndicatorOscillator(_mfi, default, default, default, default, default, "mfi");          DrawHorzLine(50, WLColor.Black, 2, LineStyle.Dashed, "mfi");          StartIndex = 10;          _ptc = new PeakTroughCalculator(bars, swingPct, PeakTroughReversalType.Percent);          ZigZagHL zz1 = new ZigZagHL(bars, swingPct, PeakTroughReversalType.Percent);          PlotIndicator(zz1, WLColor.Blue);                    _ptcMfi = new PeakTroughCalculator(_mfi, swingPct, PeakTroughReversalType.Percent);          ZigZag zz2 = new ZigZag(_mfi, swingPct, PeakTroughReversalType.Percent);          PlotIndicator(zz2, WLColor.Green, PlotStyle.Line, false, "mfi");       }
0

Reply

Bookmark

Sort