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

Drawing a line based on double Value

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

    Drawing a line based on double Value

    Dear Sir or Madam,

    Thank you for taking time to consider this,



    double E= (EMA(Close, 100)[0]);
    double W= (WMA(Close,100)[0]);

    double Eu =(E +(W*0.25));
    double El =(E -(W*0.25));


    Now as I defined the values of E, Eu, and El,

    I want simply to plot the values on the chart as new lines to consider in my trading.



    I tried this below but it didn't work.



    if (CurrentBars[0] > 1)

    {

    DrawLine("tag1", false, 0, 0, E ,0, Color.LimeGreen, DashStyle.Dot, 2);
    }


    I tried several other alternative didn't work also as to add to initialize.

    protected override void Initialize()
    {
    Add(new Plot(Color.Blue, "E"));
    Add(new Plot(Color.Red, "Eu"));
    Add(new Plot(Color.Green, "El"));
    }



    Can you help me with the subject to understand how to so.


    Thank you in advance.

    Yassine.

    #2
    Hello Yassine.Chetouani,

    Thanks for your post.

    DrawLine() and Plots are two different methods so I will address each seperately.

    The Drawline() example you provided is: DrawLine("tag1", false, 0, 0, E ,0, Color.LimeGreen, DashStyle.Dot, 2); With reference to the helpguide: https://ninjatrader.com/support/help.../?drawline.htm the overload you are using would draw a single line called "tag1" that would be replaced by the next one drawn because each draw object on the chart must have a unique tag name. To show all lines you would need a tagname of "tag1"+CurrentBar.

    The values of 0,0,E,0 would mean that it would draw a line from the (price) value of 0 on the current bar 0 up to the (price) value of E on the current bar 0, so it would be a vertical line from 0 to E. If you wanted the line to be horizontal you would need to use E for both the "startY and "endY". Using 0 for both the startbar and endbar would likely not show anything as you would need at least one bar difference to draw a horizontal line, so you might try a 1 for the start bar and 0 for the end bar, depending on how far back you want to draw the line based on the current bars value of E.

    A technical issue is that you are using a 100 period EMA and WMA which means that to get accurate results you would need a minimum number of 100 bars for the moving averages to properly produce the values, so you may want to change if (CurrentBars[0] > 1) to if (CurrentBars[0] > 100). You would still get a line if you left it at if (CurrentBars[0] > 1), however, its accuracy at that point would be in question.

    If you draw all of those lines by using "tag1"+CurrentBar it will have some impact on performance as it does take your PC CPU time to draw each of the lines. If you only need the latest value of the line, then please do stay with the non unique tagname of "tag1".


    If you want to use plots, which use less CPU resources than all of the drawlines, then I recommend that you start over and create the indicator using Tools>New Ninjascript>Indicator and use the indicator wizard to create the 3 plots for you using the slightly different name such as "Eplot", Euplot" and "Elplot" as the wizard will then create the complete structure for the plots in the #region properties. Once you have created the structure, then in the OnBarUpdate you can use:

    if (CurrentBar > 100)
    {
    double E= (EMA(Close, 100)[0]);
    double W= (WMA(Close,100)[0]);

    double Eu =(E +(W*0.25));
    double El =(E -(W*0.25));

    Eplot.Set(E);
    Euplot.Set(Eu);
    Elplot.Set(El);
    }


    Which would provide three plots starting at bar 100.
    Paul H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by tsantospinto, 04-12-2024, 07:04 PM
    5 responses
    67 views
    0 likes
    Last Post tsantospinto  
    Started by cre8able, Today, 03:20 PM
    0 responses
    6 views
    0 likes
    Last Post cre8able  
    Started by Fran888, 02-16-2024, 10:48 AM
    3 responses
    49 views
    0 likes
    Last Post Sam2515
    by Sam2515
     
    Started by martin70, 03-24-2023, 04:58 AM
    15 responses
    115 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by The_Sec, Today, 02:29 PM
    1 response
    8 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Working...
    X