Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Murrey Math Lines - Can't use Extended Lines

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Murrey Math Lines - Can't use Extended Lines

    Hi

    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);


    Code:
    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
    ​


    Click image for larger version

Name:	MML_NT8.png
Views:	235
Size:	33.9 KB
ID:	1275858

    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

    Click image for larger version

Name:	Tradingview_MML.png
Views:	117
Size:	65.9 KB
ID:	1275860

    Meaning the MML will extend to the right and also show their text and value.
    How can I do it?

    Thank you
    Attached Files

    #2
    Hello zivvv,

    Thank you for your post.

    Is an Extended Line the proper tool for what you are looking to achieve? It seems you are using the same startY and endY value of 'Values[j][1]' - if you want a line that stays at the same y value and extends in both directions, you could use a horizontal line object:


    As for a label with text and the value, you could consider using the custom labeled lines drawing tool, which also includes NinjaScript overloads to draw the lines programmatically. This script is publicly available on our NinjaTrader Ecosystem website:
    Here is a basic guideline of how to import NinjaScript add-ons in NinjaTrader 8:

    Note — To import NinjaScripts you will need the original .zip file.

    To Import:
    1. Download the NinjaScripts to your desktop, keep them in the compressed .zip file.
    2. From the Control Center window select the menu Tools > Import > NinjaScript Add-on...
    3. Select the downloaded .zip file
    4. NinjaTrader will then confirm if the import has been successful.

    Critical - Specifically for some NinjaScripts, it will prompt that you are running newer versions of @SMA, @EMA, etc. and ask if you want to replace, press 'No'

    Once installed, you may add the indicator to a chart by:
    • Right-click your chart > Indicators... > Select the Indicator from the 'Available' list on the left > Add > OK

    Here is a short video demonstration of the import process:
    Please let me know if I can be of further assistance.

    The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      Thank you

      But this didn't help much.
      I've tried all the combinations possible with
      Draw.ExtendedLine(this, "MMLExtLine" + j, CurrentBar - 1, Values[j][1], CurrentBar + 20, Values[j][10], Plots[j].Brush);

      It still stays the same

      I've also tried
      Draw.HorizontalLine(this, "MMLExtLine" + j, Values[j][1], Plots[j].Brush, DashStyleHelper.Solid, 2, true);

      It does produce an horizontal line but it does not extend to the right as I want.



      Comment


        #4
        Hello zivvv,

        Thank you for your reply.

        Drawing tools have limitations, especially when attempting to extend/draw into the future. In order to have more control over how the lines and labels are displayed on your chart, you could also consider using OnRender() to custom render the information onto your chart. For more details, please see the following links:There is also an indicator called "Sample custom render" that comes with NinjaTrader by default. You could review this indicator to see how it achieves custom rendering and the source code is available in the NinjaScript Editor as a learning resource.

        Please let us know if we may be of further assistance.
        Emily C.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by mishhh, 05-25-2010, 08:54 AM
        19 responses
        6,189 views
        0 likes
        Last Post rene69851  
        Started by gwenael, Today, 09:29 AM
        0 responses
        4 views
        0 likes
        Last Post gwenael
        by gwenael
         
        Started by Karado58, 11-26-2012, 02:57 PM
        8 responses
        14,830 views
        0 likes
        Last Post Option Whisperer  
        Started by Option Whisperer, Today, 09:05 AM
        0 responses
        2 views
        0 likes
        Last Post Option Whisperer  
        Started by cre8able, Yesterday, 01:16 PM
        3 responses
        11 views
        0 likes
        Last Post cre8able  
        Working...
        X