This is going to be lengthy I think as I reckon I'll need to get a lot of information across in order to solicit the level of help I need. However, I wouldn't be surprised if I'm doing something so obviously wrong that I get an 'obivous' solution but I'll be grateful whichever way.
Background on Me
I've been programming on NinjaTrader 7 for over 2 years and after a false start moved over to NinjaTrader 8 about six months ago.My background is a C programmer a long time ago so I am self taught in C# (and object orientation in general) and so wouldn't be surprised that I make obvious language mistakes.
Background on the Problem
I've written lots of MTF indicators and by and large I've thought they were OK except that I have noticed what I would call inconsistencies on the slightly more convoluted ones i.e. often those that call my or other peoples custom indicators. I have done simple tests on MTF SMA that seem to work fine.
My preferred bar type is BetterRenko. I have considered whether this is an issue but having looked at my stuff on other bar types I still see the problem.
The Problem
So .... I have an indicator that plots trend lines between swing points. These trend lines can be 'high' or 'low' based on joining high or low swings. It also plots a marker on the chart and publishes an integer series when one of these trend lines is crossed.
My MTF indicator looks for the simple published integer series (-1, 0, +1) on each of three timeframes or in my case bar sizes - a 3, 4 and 5 tick. It then plots a marker (red or green hash) below the current 3 tick chart for each timeframe where a trendline cross is detected. The problem I see is that the MTF indicator often plots markers for the 4 or 5 tick integer series where I can see on a separate chart that no cross (and hence an integer 0 would be published) has occurred.
Just to compound this I also detect 'fast' renko bars (shown by a red or green triangle on the main chart) which are occurring on the way toward a trendline (yellow triangle) and publish a similar marker (-1, 0, +1) for these. The MTF indicator looks at these similarly and prints a red or green triangle marker below the 3 tick chart. This also produces similar 'error' prints.
Example
(See attached image of 3 tick chart)
Note that the 3 tick markers are displayed by the MTF indicator on the top two plots of the panel below the chart. The next four plots are for the other two timeframes. The idea is that I can see when these events happen simultaneously or close together.
The problem is that when I look at the 4 tick chart (image also attached), the markers on the middle two rows aren't always correct and are sometimes(often) fake.
The Code
I've attached the full MTF indicator but not the base TrendLine indicator. Happy to do that but compiling them will be fun as they depend on a number of other things. In the first instance I was hoping that someone might comment on the basic MTF OnBarUpdate code to make sure I'm doing it right. The core code is:
protected override void OnBarUpdate() { int TrendLineCross = TrendLine.TrendLineCross[0]; int FastApproach = TrendLine.FastApproach[0]; Brush CrossColor = (TrendLineCross > 0) ? Brushes.Green : Brushes.Red; Brush FastApproachColor = (FastApproach > 0) ? Brushes.Green : Brushes.Red; if (BarsInProgress == 1) { if (TrendLineCross != 0) { PlotBrushes[SlowCrossPlot][0] = CrossColor; SlowCross[0] = 3; } if (FastApproach != 0) { PlotBrushes[SlowFastApproachPlot][0] = FastApproachColor; SlowFastApproach[0] = 2; } } if (BarsInProgress == 2) { if (TrendLineCross != 0) { PlotBrushes[VerySlowCrossPlot][0] = CrossColor; VerySlowCross[0] = 1; } if (FastApproach != 0) { PlotBrushes[VerySlowFastApproachPlot][0] = FastApproachColor; VerySlowFastApproach[0] = 2; } } if (BarsInProgress == 0) { if (TrendLineCross != 0) { PlotBrushes[FastCrossPlot][0] = CrossColor; FastCross[0] = 5; } if (FastApproach != 0) { PlotBrushes[FastFastApproachPlot][0] = FastApproachColor; FastFastApproach[0] = 4; } } }
Anyway, that's it for now - I would be very grateful if someone could look at the basic MTF setup, which I think is straightforward and comment on its correctness or otherwise. This issue has been bugging me for a long time and I have even considered switching to a completely different platform in order to move forward but, as you can imagine, having invested considerable time in NinjaTrader and also considering that it may well be something I am doing wrong, then I come to this forum first.
Yours in anticipation,
Steve
smaTrendLineMTF.cs
Comment