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

Draw Repeater only on current day

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

    Draw Repeater only on current day

    Hello community,
    I'm trying to edit the custom indicator "Repeater2.2" in a way that it only draws on the current day.
    Basically i'd like to bypass the "Repeat Daily, Repeat Monday, etc..." in order to draw the line/rectangle only on the current day.
    I use Tool type: Opening Range.

    I tried to edit it by myself but i'm not familiar at all with ninjascript and i can't seem to find the solution.

    If someone can point me on the right direction, it would be much appreciated!
    Thanks.

    #2
    Hello YanisR,

    Welcome to the NinjaTrader forums!

    Below I am providing a link to a support article with helpful resources on getting started with C# and NinjaScript.


    You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.


    Are you seeing in the script where the line and rectangle are being drawn in the script?
    Is this from Draw.Rectangle() in OnBarUpdate() or RenderTarget.DrawRectangle() in OnRender()?
    What is the condition statement that the draw method call is in?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea and thanks for the reply.
      The code is:
      Code:
      [Draw.Line(this, label[i]+"Upper", false, Time[CurrentBar - beginBar[i]], startStopPrice[i,1], MySessionIterator.ActualSessionEnd, startStopPrice[i,1], brushColor[i], DashStyleHelper.Dot, 1);
      Draw.Line(this, label[i]+"Lower", false, Time[CurrentBar - beginBar[i]], startStopPrice[i,2], MySessionIterator.ActualSessionEnd, startStopPrice[i,2], brushColor[i], DashStyleHelper.Dot, 1);


      While waiting for the reply i've been doing some researches and discovered the "addDataSeries" and "BarsinProgress" to try to check if we are in the current day before drawing the line.

      I've been trying editing the code made by @NinjaTrader_Kate​ here: https://forum.ninjatrader.com/forum/...98#post1170998 since it's easier to understand:
      Code:
      #region Using declarations
      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.ComponentModel.DataAnnotations;
      using System.Linq;
      using System.Text;
      using System.Threading.Tasks;
      using System.Windows;
      using System.Windows.Input;
      using System.Windows.Media;
      using System.Xml.Serialization;
      using NinjaTrader.Cbi;
      using NinjaTrader.Gui;
      using NinjaTrader.Gui.Chart;
      using NinjaTrader.Gui.SuperDom;
      using NinjaTrader.Gui.Tools;
      using NinjaTrader.Data;
      using NinjaTrader.NinjaScript;
      using NinjaTrader.Core.FloatingPoint;
      using NinjaTrader.NinjaScript.DrawingTools;
      #endregion
      
      //This namespace holds Indicators in this folder and is required. Do not change it.
      namespace NinjaTrader.NinjaScript.Indicators
      {
          public class SessionHighLowLinesExample : Indicator
          {
              private int StartBar;
              private int SessionBarsAgo;
              private int TodayEndBar;
              private double LowestLow;
              private double HighestHigh;
              private DateTime TodayStart;
              protected override void OnStateChange()
              {
                  if (State == State.SetDefaults)
                  {
                      Description                                    = @"Enter the description for your new custom Indicator here.";
                      Name                                        = "SessionHighLowLinesExample";
                      Calculate                                    = Calculate.OnBarClose;
                      IsOverlay                                    = true;
                      DisplayInDataBox                            = true;
                      DrawOnPricePanel                            = true;
                      DrawHorizontalGridLines                        = true;
                      DrawVerticalGridLines                        = true;
                      PaintPriceMarkers                            = true;
                      ScaleJustification                            = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                      //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                      //See Help Guide for additional information.
                      IsSuspendedWhileInactive                    = true;
                      SessionStart                        = DateTime.Parse("00:00", System.Globalization.CultureInfo.InvariantCulture);
                      SessionEnd                        = DateTime.Parse("08:00", System.Globalization.CultureInfo.InvariantCulture);
                  }
                  else if (State == State.Configure)
                  {
                      AddDataSeries(BarsPeriodType.Minute, 1);
                  }
              }
      
              protected override void OnBarUpdate()
              {
                  if(BarsInProgress == 1)
                  {
                      if(Times[1][0].TimeOfDay == SessionStart.TimeOfDay)
                      {
                          StartBar = CurrentBars[1];
                          TodayStart = Times[1][0];
                      }
                      if(Times[1][0].TimeOfDay == SessionEnd.TimeOfDay)
                      {
                          SessionBarsAgo = CurrentBars[1] - StartBar;
                          TodayEndBar = CurrentBars[1];
                          HighestHigh = MAX(Highs[1], SessionBarsAgo)[0];
                          LowestLow = MIN(Lows[1], SessionBarsAgo)[0];
                      }
                      if(Times[1][0].TimeOfDay > SessionEnd.TimeOfDay)
                      {
                          Draw.Line(this, TodayEndBar.ToString()+"High", false, TodayStart, HighestHigh, Times[1][0], HighestHigh, Brushes.Green, DashStyleHelper.Dash, 2);
                          Draw.Line(this, TodayEndBar.ToString()+"Low", false, TodayStart, LowestLow, Times[1][0], LowestLow, Brushes.Red, DashStyleHelper.Dash, 2);
                      }
                  }
              }
      
              #region Properties
              [NinjaScriptProperty]
              [PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKey")]
              [Display(Name="SessionStart", Order=1, GroupName="Parameters")]
              public DateTime SessionStart
              { get; set; }
      
              [NinjaScriptProperty]
              [PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKey")]
              [Display(Name="SessionEnd", Order=2, GroupName="Parameters")]
              public DateTime SessionEnd
              { get; set; }
              #endregion
      
          }
      }
      
      #region NinjaScript generated code. Neither change nor remove.
      
      namespace NinjaTrader.NinjaScript.Indicators
      {
          public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
          {
              private SessionHighLowLinesExample[] cacheSessionHighLowLinesExample;
              public SessionHighLowLinesExample SessionHighLowLinesExample(DateTime sessionStart, DateTime sessionEnd)
              {
                  return SessionHighLowLinesExample(Input, sessionStart, sessionEnd);
              }
      
              public SessionHighLowLinesExample SessionHighLowLinesExample(ISeries<double> input, DateTime sessionStart, DateTime sessionEnd)
              {
                  if (cacheSessionHighLowLinesExample != null)
                      for (int idx = 0; idx < cacheSessionHighLowLinesExample.Length; idx++)
                          if (cacheSessionHighLowLinesExample[idx] != null && cacheSessionHighLowLinesExample[idx].SessionStart == sessionStart && cacheSessionHighLowLinesExample[idx].SessionEnd == sessionEnd && cacheSessionHighLowLinesExample[idx].EqualsInput(input))
                              return cacheSessionHighLowLinesExample[idx];
                  return CacheIndicator<SessionHighLowLinesExample>(new SessionHighLowLinesExample(){ SessionStart = sessionStart, SessionEnd = sessionEnd }, input, ref cacheSessionHighLowLinesExample);
              }
          }
      }
      
      namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
      {
          public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
          {
              public Indicators.SessionHighLowLinesExample SessionHighLowLinesExample(DateTime sessionStart, DateTime sessionEnd)
              {
                  return indicator.SessionHighLowLinesExample(Input, sessionStart, sessionEnd);
              }
      
              public Indicators.SessionHighLowLinesExample SessionHighLowLinesExample(ISeries<double> input , DateTime sessionStart, DateTime sessionEnd)
              {
                  return indicator.SessionHighLowLinesExample(input, sessionStart, sessionEnd);
              }
          }
      }
      
      namespace NinjaTrader.NinjaScript.Strategies
      {
          public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
          {
              public Indicators.SessionHighLowLinesExample SessionHighLowLinesExample(DateTime sessionStart, DateTime sessionEnd)
              {
                  return indicator.SessionHighLowLinesExample(Input, sessionStart, sessionEnd);
              }
      
              public Indicators.SessionHighLowLinesExample SessionHighLowLinesExample(ISeries<double> input , DateTime sessionStart, DateTime sessionEnd)
              {
                  return indicator.SessionHighLowLinesExample(input, sessionStart, sessionEnd);
              }
          }
      }
      
      #endregion
      ​
      I added
      Code:
      AddDataSeries(BarsPeriodType.Day, 1);
      and then below
      Code:
      if(BarsInProgress !=0)
      {
      if (Times[2][0] != Times[2][1])
      {​
      but it doesn't work.

      Comment


        #4
        Hello YanisR,

        In the each of the conditions that call the draw methods, also require the bar date to be equal to today's date.

        For example:
        if(Times[1][0].TimeOfDay == SessionStart.TimeOfDay && Times[1][0].Date == Core.Globals.Now.Date)

        Adding an additional series would not be necessary.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Oh wow that's it!
          It works great.

          Thank you so much for the help, it was driving me crazy

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by AaronKoRn, Today, 09:49 PM
          0 responses
          11 views
          0 likes
          Last Post AaronKoRn  
          Started by carnitron, Today, 08:42 PM
          0 responses
          10 views
          0 likes
          Last Post carnitron  
          Started by strategist007, Today, 07:51 PM
          0 responses
          11 views
          0 likes
          Last Post strategist007  
          Started by StockTrader88, 03-06-2021, 08:58 AM
          44 responses
          3,980 views
          3 likes
          Last Post jhudas88  
          Started by rbeckmann05, Today, 06:48 PM
          0 responses
          9 views
          0 likes
          Last Post rbeckmann05  
          Working...
          X