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

No Luck With Draw Methods

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

    No Luck With Draw Methods

    I simply want a vertical line of specified width and color to appear in the price panel given a certain trend condition. I used the wizard to create a custom indicator with no inputs and no plots. The code I'm using is (for example):
    Code:
    protected override void Initialize()
    
    {
    
    CalculateOnBarClose = true;
    
    Overlay = true;
    
    PriceTypeSupported = false;
    
    }
    
    protected override void OnBarUpdate()
    
    {
    
    if (CrossAbove(EMA(50), EMA(200), 1)) 
    
    {
    
    DrawVerticalLine("UP", 5, Color.Red, DashStyle.Solid, 6);
    
    }
    
    }
    The code compiles but I get no lines. Do I need to add a line object in the initialize() section?

    Thx in advance.

    KD

    #2
    imported post

    Works fine and as you have coded it. Ifyou want a separate line instance for each CrossAbove() condition, then you have to supply unique tag names.
    DrawVerticalLine(Time[0].ToString(), 5, Color.Red, DashStyle.Solid, 6);
    RayNinjaTrader Customer Service

    Comment


      #3
      imported post

      Thanks for the reply.

      It looks as if none of the shared draw items will work for me using this method. They all compile fine, I can apply the indicator to a chart, but nothing appears. I have tried changing the condition to Low[0] > Low[5], and have tried other objects up arrow, dot, etc with nothing appearing on any chart to which I apply the indicator.

      However,the objects draw correctlywhen I use the same logic in a strategy instead of an indicator. What am I missing?

      Complete code follows:
      Code:
      #region Using declarations
      
      using System;
      
      using System.Diagnostics;
      
      using System.Drawing;
      
      using System.Drawing.Drawing2D;
      
      using System.ComponentModel;
      
      using System.Xml.Serialization;
      
      using NinjaTrader.Data;
      
      using NinjaTrader.Gui.Chart;
      
      #endregion
      
      // This namespace holds all indicators and is required. Do not change it.
      
      namespace NinjaTrader.Indicator
      
      {
      
      /// <summary>
      
      /// draw vertical bar with xma crossover
      
      /// </summary>
      
      [Description("draw vertical bar with xma crossover")]
      
      [Gui.Design.DisplayName("vertical bar")]
      
      public class kdtrend1 : Indicator
      
      {
      
      #region Variables
      
      // Wizard generated variables
      
      // User defined variables (add any user defined variables below)
      
      #endregion
      
      /// <summary>
      
      /// This method is used to configure the indicator and is called once before any bar data is loaded.
      
      /// </summary>
      
      protected override void Initialize()
      
      {
      
      CalculateOnBarClose = true;
      
      Overlay = true;
      
      PriceTypeSupported = false;
      
      }
      
      /// <summary>
      
      /// Called on each bar update event (incoming tick)
      
      /// </summary>
      
      protected override void OnBarUpdate()
      
      {
      
      if (CrossAbove(EMA(50), EMA(200), 5))
      
      {
      
      DrawVerticalLine(Time[0].ToString(), 5, Color.Red, DashStyle.Solid, 6);
      
      }
      
      }

      Comment


        #4
        imported post

        OK, that's just too weird. After I applied and un-applied the strategy with the same logic, the indicatordraws properly now.

        Thanks again for your help!

        KD

        Comment


          #5
          imported post

          Any time you re-compile an indicator or strategy, the changed implementation is not automatically loaded in any charts. You can force the reload via right mouse click "Reload NinjaScript"


          Ray
          RayNinjaTrader Customer Service

          Comment


            #6
            imported post

            ninjatrader wrote:
            Any time you re-compile an indicator or strategy, the changed implementation is not automatically loaded in any charts. You can force the reload via right mouse click "Reload NinjaScript"


            Ray
            Indeed, which is what I was doing, until it just worked for some reason. However, now when I change the logic, the draw objects disappear. I can only get any of the objects todrawin strategies, notin indicators. Very frustrating!

            BTW, I'm using 6.0.0.6 Live (ZenFire) version

            KD

            Comment


              #7
              imported post

              I would double check your logic. If you get stuck, build a basic indicatorthat draws an arrow on each bar without any logic to confirm all is well, then build from there.
              RayNinjaTrader Customer Service

              Comment


                #8
                imported post

                Well, what is so frustrating is that some logic seems to work and some doesn't. A simple DrawVerticalLine() with no conditions draws on every bar. However,
                Code:
                protected override void OnBarUpdate()
                
                {
                
                if (MIN(Low, 14)[1] > EMA(50)[1])
                
                {
                
                DrawVerticalLine(Time[0].ToString(), 0, Color.Red, DashStyle.Solid, 6);
                
                }
                
                }
                works only in a strategy. In fact, if I paste this code into an existing indicator, it stopsdrawing the other plots.

                Interestingly if I replace the above condition with
                Code:
                if (MIN(Low, 14)[0] > EMA(50)[0])
                it works as an indicator.

                Changing the reference by one bar breaks it in an indicator - but it stilldraws correctlyin a strategy. Could this be a bug? If it's not, I must bemissing something very basic.

                Thanks for your patience

                KD

                Comment


                  #9
                  imported post

                  You should always check the log tab if stuff does not work since NT will spit out error information. Its very clear why your code is failing. If you check your logs, you will have some sort of "index out of the boundsof the array" error.

                  You are checking for a value of 1 bar ago. On the first bar of a chart, there is no 1 bar agao and thus you get an error. Make sure there are enough bars ago on the chart first.
                  if (CurrentBar > 0)
                  Print(MIN(Low, 14)[1]);
                  Ray




                  RayNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by cre8able, Today, 03:20 PM
                  0 responses
                  5 views
                  0 likes
                  Last Post cre8able  
                  Started by Fran888, 02-16-2024, 10:48 AM
                  3 responses
                  47 views
                  0 likes
                  Last Post Sam2515
                  by Sam2515
                   
                  Started by martin70, 03-24-2023, 04:58 AM
                  15 responses
                  114 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by The_Sec, Today, 02:29 PM
                  1 response
                  7 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by jeronymite, 04-12-2024, 04:26 PM
                  2 responses
                  31 views
                  0 likes
                  Last Post NinjaTrader_BrandonH  
                  Working...
                  X