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

Helps Needed

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

    Helps Needed

    Hi Guys,
    I just started learning NT script.I used the existing NT CurrentDayOHL code and tried to apply DrawRegion to currentHigh, currentLow,and created the 50% Mid points. I got it worked but failed to delete those Plot lines.(I tried to command out but didn't work) Could anyone please give me some advice? Thanks in advance!

    protected override void OnBarUpdate()
    {
    if (currentOpen == double.MinValue)
    currentOpen = Open[0];
    if (Bars.SessionBreak)
    {
    currentOpen = Open[0];
    currentHigh = High[0];
    currentLow = Low[0];
    }
    currentHigh = Math.Max(currentHigh, High[0]);
    currentLow = Math.Min(currentLow, Low[0]);
    if (ShowOpen)
    {
    if (!PlotCurrentValue || !Bars.SessionBreak)
    CurrentOpen.Set(currentOpen);
    else
    for (int idx = 0; idx < CurrentOpen.Count; idx++)
    CurrentOpen.Set(idx, currentOpen);
    }
    if (ShowHigh)
    {
    if (!PlotCurrentValue || currentHigh != High[0])
    CurrentHigh.Set(currentHigh);
    else
    for (int idx = 0; idx < CurrentHigh.Count; idx++)
    CurrentHigh.Set(idx, currentHigh);
    }
    if (ShowLow)
    {
    if (!PlotCurrentValue || currentLow != Low[0])
    CurrentLow.Set(currentLow);
    else
    for (int idx = 0; idx < CurrentLow.Count; idx++)
    CurrentLow.Set(idx, currentLow);
    }

    mid.Set(Instrument.MasterInstrument.Round2TickSize ((currentHigh+currentLow)/2));

    ch1.Set(currentHigh);
    cl1.Set(currentLow);

    mid1.Set (mid[0]+TickSize*1);
    mid2.Set (mid[0]-TickSize*1);

    CH1.Set (ch1[0]-TickSize*2);
    CL1.Set (cl1[0]+TickSize*2);

    DrawRegion("Reg1", CurrentBar, 0, mid1, mid2, Color.Transparent, Color.DarkRed,10);

    DrawRegion("Reg2", CurrentBar, 0, ch1, CH1, Color.Transparent, Color.DarkGreen,10);

    DrawRegion("Reg3", CurrentBar, 0, cl1, CL1, Color.Transparent, Color.DarkGreen,10);
    }

    #region Properties
    [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
    [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
    public DataSeries CurrentOpen
    {
    get { return Values[0]; }
    }

    [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
    [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
    public DataSeries CurrentHigh
    {
    get { return Values[1]; }
    }

    [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
    [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
    public DataSeries CurrentLow
    {
    get { return Values[2]; }
    }

    [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
    [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
    public DataSeries mid
    {
    get { return Values[3]; }
    }

    [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
    [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
    public DataSeries mid1
    {
    get { return Values[4]; }
    }

    [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
    [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
    public DataSeries mid2
    {
    get { return Values[5]; }
    }

    [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
    [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
    public DataSeries CH1
    {
    get { return Values[6]; }
    }

    [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
    [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
    public DataSeries CL1
    {
    get { return Values[7]; }
    }

    [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
    [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
    public DataSeries ch1
    {
    get { return Values[8]; }
    }

    [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
    [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
    public DataSeries cl1
    {
    get { return Values[9]; }
    }
    [Browsable(true)]
    [Gui.Design.DisplayNameAttribute("Show open")]
    public bool ShowOpen
    {
    get { return showOpen; }
    set { showOpen = value; }
    }

    [Browsable(true)]
    [Gui.Design.DisplayNameAttribute("Show high")]
    public bool ShowHigh
    {
    get { return showHigh; }
    set { showHigh = value; }
    }
    [Browsable(true)]
    [Gui.Design.DisplayNameAttribute("Plot current value only")]
    public bool PlotCurrentValue
    {
    get { return plotCurrentValue; }
    set { plotCurrentValue = value; }
    }

    [Browsable(true)]
    [Gui.Design.DisplayNameAttribute("Show low")]
    public bool ShowLow
    {
    get { return showLow; }
    set { showLow = value; }
    }
    #endregion
    }
    }
    Attached Files

    #2
    Hello Kelvin Johnson,

    Thank you for your post.

    What you can do if you don't want plots drawn is to convert the DataSeries that have public properties (plots) into non-plottable DataSeries.

    DataSeries in this manner are used in three places:
    1) Declared in the Variables Region:
    Code:
    private DataSeries mid;
    2) Instantiated in the Initialize() Method:
    Code:
    mid = new DataSeries (this);
    3) Values set in OnBarUpdate() method:
    Code:
    mid.Set(Instrument.MasterInstrument.Round2TickSize ((currentHigh+currentLow)/2));
    The tutorial below can help with using DataSeries that are not plots.


    Your example will require reworking the code for each DataSeries. All the public properties won't be necessary. You'll have to delete them in addition to restructuring DataSeries.

    Code:
     
    [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
    [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
    public DataSeries mid
    {
    get { return Values[3]; }
    }
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Hi Ryan,
      Thank you so much for guiding. I'm one step away from getting what I want. How could I let the mid-point values show on the chat as well?


      {
      #region Variables
      private double currentOpen = double.MinValue;
      private double currentHigh = double.MinValue;
      private double currentLow = double.MaxValue;
      private bool plotCurrentValue = false;
      private bool showOpen = true;
      private bool showHigh = true;
      private bool showLow = true;

      private DataSeries mid;
      private DataSeries mid1;
      private DataSeries mid2;

      #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()
      {
      Add(new Plot(new Pen(Color.Orange, 2), PlotStyle.Square, "Current Open"));
      Add(new Plot(new Pen(Color.Lime, 2), PlotStyle.Square, "Current High"));
      Add(new Plot(new Pen(Color.Cyan, 2), PlotStyle.Square, "Current Low"));

      mid = new DataSeries (this);
      mid1 = new DataSeries (this);
      mid2 = new DataSeries (this);

      Plots[0].Pen.DashStyle = DashStyle.Dash;
      Plots[1].Pen.DashStyle = DashStyle.Dash;
      Plots[2].Pen.DashStyle = DashStyle.Dash;

      AutoScale = false;
      CalculateOnBarClose = false;
      Overlay = true;
      }
      /// <summary>
      /// Called on each bar update event (incoming tick)
      /// </summary>
      protected override void OnBarUpdate()
      {
      if (currentOpen == double.MinValue)
      currentOpen = Open[0];
      if (Bars.SessionBreak)
      {
      currentOpen = Open[0];
      currentHigh = High[0];
      currentLow = Low[0];
      }
      currentHigh = Math.Max(currentHigh, High[0]);
      currentLow = Math.Min(currentLow, Low[0]);

      if (ShowOpen)
      {
      if (!PlotCurrentValue || !Bars.SessionBreak)
      CurrentOpen.Set(currentOpen);
      else
      for (int idx = 0; idx < CurrentOpen.Count; idx++)
      CurrentOpen.Set(idx, currentOpen);
      }
      if (ShowHigh)
      {
      if (!PlotCurrentValue || currentHigh != High[0])
      CurrentHigh.Set(currentHigh);
      else
      for (int idx = 0; idx < CurrentHigh.Count; idx++)
      CurrentHigh.Set(idx, currentHigh);
      }
      if (ShowLow)
      {
      if (!PlotCurrentValue || currentLow != Low[0])
      CurrentLow.Set(currentLow);
      else
      for (int idx = 0; idx < CurrentLow.Count; idx++)
      CurrentLow.Set(idx, currentLow);
      }

      mid.Set (Instrument.MasterInstrument.Round2TickSize((curre ntHigh+currentLow)/2));

      mid1.Set (mid[0]+TickSize*1);
      mid2.Set (mid[0]-TickSize*1);


      DrawRegion("Reg1", CurrentBar, 0, mid1, mid2, Color.Transparent, Color.DarkRed,10);

      }
      Attached Files

      Comment


        #4
        Unfortunately they are not shown per default for draw objects (your DrawRegion), you would need to custom code a marker with the DrawText method then.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Hi Bertrand,

          I have added

          DrawText("MID1", true, "MID1", 0, mid1[0] ,1, Color.White, largeFont, StringAlignment.Near, Color.Transparent, Color.Transparent, 0);

          The chart shows text form rather than the price level.(the price level of 50% retracement : 1.5213). Am I using DrawText wrongly?
          Attached Files

          Comment


            #6
            Yes, as it would just DrawText the string input you give it, so it prints your MID1 text...try YourMIDValue.ToString() for example.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Hi,
              Thanks to Ryan's and Bertrand's helps I won't get what I want so shortly.Great appreciation to both of you and the whole NT support team. Last few questions of this thread.
              (1)Can Drawtext displays the price markers as PlotLine does?
              (2)How to make the price markers align with the last price? For the time being ,I set the right margin to 40 from chart properties else the last four decimal digits won't be seen.
              (3)The last decimal digit is not printed if it is zero. It's OK to me,just want the chart to look neat.
              (4)The reflection lines appear on chart by using DrawRegion when you plot in different time ranges.Is it inevitable?Any better solution?
              (5)Am I right to say that Variables,Initialize,onBarUpdate and Properties are the four major areas to look in when you are writing NT scripts? By the way,is there any tutorial about the definition of string,bool,double etc?Have you known any of your certified programmer conduct online courses solely on script writing for NT platform?
              Best Regards.
              Attached Files

              Comment


                #8
                Hi Kelvin,

                1) DrawText doesn't have the same features available as plotting. It's pretty much just an empty slate. You can custom code price markers but draw objects won't have this by default.

                2) Price Markers indicate on the vertical axis where the last visible price/indicator was at.

                3) You can work with the reference sample below for help on string formatting:


                4) See the method signatures available for DrawRegion() You may be able to accomplish what you want by setting colors to transparent.

                5) Those are the main areas to look for when writing indicators. Strategies have some additional items such as OnOrderUpdate(), OnExecution()

                Concepts of Bool, string, double have existed long before NinjaScript. Doing a google search on "Programming data types" may produce what you want.

                We hold a class every other week on building Automated strategies with our strategy wizard. This is a good class for getting started with NinjaScript. I've not heard of our partners offering NinjaScript educational seminars.

                See here for our complete online event schedule.
                See here for our list of NinjaScript partners.
                Ryan M.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by GussJ, 03-04-2020, 03:11 PM
                15 responses
                3,271 views
                0 likes
                Last Post xiinteractive  
                Started by Tim-c, Today, 02:10 PM
                1 response
                8 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by Taddypole, Today, 02:47 PM
                0 responses
                2 views
                0 likes
                Last Post Taddypole  
                Started by chbruno, 04-24-2024, 04:10 PM
                4 responses
                51 views
                0 likes
                Last Post chbruno
                by chbruno
                 
                Started by TraderG23, 12-08-2023, 07:56 AM
                10 responses
                403 views
                1 like
                Last Post beobast
                by beobast
                 
                Working...
                X