I've developed a Murrey Math lines indicator.
It is working fine but I want it to show me the most relevant MML (not historical) and show them as extended horizontal lines.
However I can't do it.
Something with the way I try to draw the lines does not work
Draw.ExtendedLine(this, "MMLExtLine" + j, CurrentBar - 1, Values[j][1], CurrentBar + 20, Values[j][1], Plots[j].Brush);
using System; using NinjaTrader.Cbi; using NinjaTrader.Gui.Tools; using NinjaTrader.NinjaScript; using NinjaTrader.Data; using NinjaTrader.Gui.Chart; using System.Windows.Media; using NinjaTrader.NinjaScript.DrawingTools; namespace NinjaTrader.NinjaScript.Indicators { public class MML : Indicator { private double FrameMultiplier { get; set; } // Made this private for encapsulation private int FrameSize { get; set; } // Made this private for encapsulation protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Draws Murrey Math Lines."; Name = "MML"; IsOverlay = true; // To display on the main chart FrameMultiplier = 1.5; FrameSize = 64; AddPlot(Brushes.Silver, "+3/8 - Imminent Bearish reversal"); AddPlot(Brushes.Red, "+2/8 Extreme Overshot"); AddPlot(Brushes.Red, "+1/8 Overshot"); AddPlot(Brushes.Aqua, "8/8 Ultimate resistance"); AddPlot(Brushes.Orange, "7/8 Weak stop ^ Reverse"); AddPlot(Brushes.Fuchsia, "6/8 Strong pivot reverse"); AddPlot(Brushes.Green, "5/8 Top of trading range"); AddPlot(Brushes.Aqua, "4/8 Major S/R"); AddPlot(Brushes.Green, "3/8 Bottom of trading range"); AddPlot(Brushes.Fuchsia, "2/8 Strong pivot reverse"); AddPlot(Brushes.Orange, "1/8 Weak Stop Reverse"); AddPlot(Brushes.Aqua, "0/8 Ultimate support"); AddPlot(Brushes.Green, "-1/8 Oversold"); AddPlot(Brushes.Green, "-2/8 Extreme Oversold"); AddPlot(Brushes.Silver, "-3/8 Imminent Bullish reversal"); } else if (State == State.Configure) { // Currently Empty - can add configuration code if needed later } } protected override void OnBarUpdate() { if (CurrentBar < FrameSize) return; // Ensure there's enough data double highestHigh = High[HighestBar(High, FrameSize)]; double lowestLow = Low[LowestBar(Low, FrameSize)]; double range = highestHigh - lowestLow; double step = range / 8.0; // Set current values only for the latest bar based on the calculations Values[0][0] = highestHigh + 3 * step; Values[1][0] = highestHigh + 2 * step; Values[2][0] = highestHigh + step; Values[3][0] = highestHigh; Values[4][0] = highestHigh - step; Values[5][0] = highestHigh - 2 * step; Values[6][0] = highestHigh - 3 * step; Values[7][0] = highestHigh - 4 * step; Values[8][0] = lowestLow + 3 * step; Values[9][0] = lowestLow + 2 * step; Values[10][0] = lowestLow + step; Values[11][0] = lowestLow; Values[12][0] = lowestLow - step; Values[13][0] = lowestLow - 2 * step; Values[14][0] = lowestLow - 3 * step; // If it's the last bar on the chart, draw the extended line to the right for all MML if (Bars.IsLastBarOfSession) { for (int j = 0; j <= 14; j++) { // Draw an extended line using the current bar's date and the corresponding MML value // Using the plot's brush for color Draw.ExtendedLine(this, "MMLExtLine" + j, CurrentBar - 1, Values[j][1], CurrentBar + 20, Values[j][1], Plots[j].Brush); } } // Clear previous values from the second last bar onward for (int j = 0; j <= 14; j++) { Values[j][2] = double.NaN; } } } } #region NinjaScript generated code. Neither change nor remove. namespace NinjaTrader.NinjaScript.Indicators { public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase { private MML[] cacheMML; public MML MML() { return MML(Input); } public MML MML(ISeries<double> input) { if (cacheMML != null) for (int idx = 0; idx < cacheMML.Length; idx++) if (cacheMML[idx] != null && cacheMML[idx].EqualsInput(input)) return cacheMML[idx]; return CacheIndicator<MML>(new MML(), input, ref cacheMML); } } } namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns { public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase { public Indicators.MML MML() { return indicator.MML(Input); } public Indicators.MML MML(ISeries<double> input ) { return indicator.MML(input); } } } namespace NinjaTrader.NinjaScript.Strategies { public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase { public Indicators.MML MML() { return indicator.MML(Input); } public Indicators.MML MML(ISeries<double> input ) { return indicator.MML(input); } } } #endregion
As can be seen it is working (btw if you like to see historical MML you can remove the loop that clears old historical data).
The idea is to do it like TradingView indicator
Meaning the MML will extend to the right and also show their text and value.
How can I do it?
Thank you
Comment