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

Volumetric Bars as Secondary Data Series

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

    #31
    Hello f.saeidi,

    Thanks for your notes.

    Are there any error messages appearing in the Log tab of the Control Center? If so, what do they report?

    I see you only have a CurrentBars check for the primary series and the first added series in the code you shared.

    A CurrentBars check will need to be added to the script for each added series being used in the script.

    Make sure you have enough bars: https://ninjatrader.com/support/help...nough_bars.htm
    CurrentBars: https://ninjatrader.com/support/help...urrentbars.htm

    Attached is an example script demonstrating assigning the Open, Close, and Bid of an added one minute series and added five minute series to variables and drawing those values on the chart when BarsInProgress 1 processes.

    Attached is also a screenshot showing the example script working.
    Attached Files
    Brandon H.NinjaTrader Customer Service

    Comment


      #32
      thnx for your note.
      in below script can i identify trend in 1min and 5 min and 15 min together?

      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 TrendTest : Indicator
      {
      double oneMinOpen;
      double oneMinClose;
      double oneMinBid;

      double fiveMinOpen;
      double fiveMinClose;
      double fiveMinBid;

      double fifteenMinOpen;
      double fifteenMinClose;
      double fifteenMinBid;



      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = @"Enter the description for your new custom Indicator here.";
      Name = "TrendTest";
      Calculate = Calculate.OnPriceChange;
      IsOverlay = false;
      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;
      }
      else if (State == State.Configure)
      {
      AddDataSeries(Data.BarsPeriodType.Minute,1);
      AddDataSeries(Data.BarsPeriodType.Minute,5);
      AddDataSeries(Data.BarsPeriodType.Minute,15);


      }
      }

      protected override void OnBarUpdate()
      {

      if (CurrentBars[0] < 10 || CurrentBars[1] < 10 )
      return;


      if (BarsInProgress ==1)
      {
      oneMinOpen = Open[0];
      oneMinClose = Close[0];
      oneMinBid = GetCurrentBid();


      }

      if (BarsInProgress ==2)
      {
      fiveMinOpen = Open[0];
      fiveMinClose = Close[0];
      fiveMinBid = GetCurrentBid();


      if (BarsInProgress ==3)
      {
      fifteenMinOpen = Open[0];
      fifteenMinClose = Close[0];
      fifteenMinBid = GetCurrentBid();


      }





      if( (oneMinBid > oneMinOpen ) & (fiveMinBid > fiveMinOpen) & (fifteenMinBid > fifteenMinOpen) )
      {

      Draw.TextFixed(this, "", "Trend Up ", TextPosition.TopLeft);

      }




      if( (oneMinBid < oneMinOpen ) & (fiveMinBid < fiveMinOpen ) & (fifteenMinBid < fifteenMinOpen ) )
      {

      Draw.TextFixed(this, "", "Trend Down ", TextPosition.TopLeft);

      }


      }



      //Add your custom indicator logic here.
      }
      }
      }

      region NinjaScript generated code. Neither change nor remove.

      namespace NinjaTrader.NinjaScript.Indicators
      {
      public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
      {
      private TrendTest[] cacheTrendTest;
      public TrendTest TrendTest()
      {
      return TrendTest(Input);
      }

      public TrendTest TrendTest(ISeries<double> input)
      {
      if (cacheTrendTest != null)
      for (int idx = 0; idx < cacheTrendTest.Length; idx++)
      if (cacheTrendTest[idx] != null && cacheTrendTest[idx].EqualsInput(input))
      return cacheTrendTest[idx];
      return CacheIndicator<TrendTest>(new TrendTest(), input, ref cacheTrendTest);
      }
      }
      }

      namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
      {
      public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
      {
      public Indicators.TrendTest TrendTest()
      {
      return indicator.TrendTest(Input);
      }

      public Indicators.TrendTest TrendTest(ISeries<double> input )
      {
      return indicator.TrendTest(input);
      }
      }
      }

      namespace NinjaTrader.NinjaScript.Strategies
      {
      public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
      {
      public Indicators.TrendTest TrendTest()
      {
      return indicator.TrendTest(Input);
      }

      public Indicators.TrendTest TrendTest(ISeries<double> input )
      {
      return indicator.TrendTest(input);
      }
      }
      }

      #endregion


      Last edited by f.saeidi; 03-27-2024, 07:17 AM.

      Comment


        #33
        i guess script doesnot consider 5 min and 15 min condition.
        i use historical data for test.
        may i see your desire script.
        Last edited by f.saeidi; 03-27-2024, 07:18 AM.

        Comment


          #34
          Hello f.saeidi,

          Thanks for your notes.

          In the code you shared, you do not have a CurrentBars check for each added secondary series in the script. You will need to add a CurrentBars check in your script for all the added secondary series.

          See the help guide documentation below for more information.

          CurrentBars - https://ninjatrader.com/support/help...urrentbars.htm
          Make sure you have enough bars - https://ninjatrader.com/support/help...nough_bars.htm

          To see how the logic in the script is behaving it would be necessary to add debugging prints to the strategy to understand exactly how it is behaving.

          Add prints to the script (one line above the conditions) that print out all the values being used for the conditions to understand how they are evaluating. Make sure to add labels and comparison operators to the prints as well so you know what is being compared and how it is being compared.

          Prints will appear in a New > NinjaScript Output window.

          Below is a link to a forum post that demonstrates how to use prints to understand behavior.


          I would suggest testing the script on a New > Chart window while connected to a live data feed connection or the Simulated data feed connection. Or, you could consider using the Playback connection with Market Replay data.

          Note that if you are using Playback, you should make sure to click the 'Play' button in the Playback window so the data is playing when you are testing the script.
          Brandon H.NinjaTrader Customer Service

          Comment


            #35
            I use playback and tick replay for testing.
            But it's not consider 5 and 15 minute condition.
            As well as this when I apply 15 minute condition I don't know why nothing appear in chart. I mean trend up and trend down message. I will send you pics here. It's only give trend up and trend down message only for 1 minute condition.
            Last edited by f.saeidi; 03-27-2024, 09:42 AM.

            Comment


              #36
              Hello f.saeidi,

              Thanks for your notes.

              Have you added a CurrentBars check to the script for each added secondary series to ensure you have enough data for all added series before processing logic as mentioned in post # 34?

              Did you add debugging prints to the script to understand how your logic is behaving as mentioned in post # 34?

              Do you receive an error on screen? Are there errors on the Log tab of the Control Center? If so, what do these errors report?

              We look forward to assisting further.
              Brandon H.NinjaTrader Customer Service

              Comment


                #37
                I will send you pics.
                Best regard

                Comment


                  #38
                  as your advise i applied print command and current bar and this is my result:
                  1) in 1 min and 5 min i can see trend message as well as x ,y value in print .
                  2) in 15 min cant see any trend message when i apply.also i cant see any x , y value in print.
                  main problem exist in 15 minute.
                  i check it in playback and live data.
                  what do you think??

                  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 TrendTest : Indicator
                  {
                  double oneMinOpen;
                  double oneMinClose;
                  double oneMinBid;

                  double fiveMinOpen;
                  double fiveMinClose;
                  double fiveMinBid;

                  double fifteenMinOpen;
                  double fifteenMinClose;
                  double fifteenMinBid;

                  int x,y;



                  protected override void OnStateChange()
                  {
                  if (State == State.SetDefaults)
                  {
                  Description = @"Enter the description for your new custom Indicator here.";
                  Name = "TrendTest";
                  Calculate = Calculate.OnPriceChange;
                  IsOverlay = false;
                  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;
                  }
                  else if (State == State.Configure)
                  {
                  AddDataSeries(null,BarsPeriodType.Minute,1);
                  AddDataSeries(null,BarsPeriodType.Minute,5);
                  AddDataSeries(null,BarsPeriodType.Minute,15);


                  }
                  }

                  protected override void OnBarUpdate()
                  {

                  if (CurrentBars[0] < 30 || CurrentBars[1] < 30 || CurrentBars[2] < 30 )
                  return;



                  if (BarsInProgress ==1)
                  {



                  oneMinOpen = Open[0];
                  oneMinClose = Close[0];
                  oneMinBid = GetCurrentBid();


                  }

                  if (BarsInProgress ==2)
                  {
                  fiveMinOpen = Open[0];
                  fiveMinClose = Close[0];
                  fiveMinBid = GetCurrentBid();


                  if (BarsInProgress ==3)
                  {

                  fifteenMinOpen = Open[0];
                  fifteenMinClose = Close[0];
                  fifteenMinBid = GetCurrentBid();


                  }





                  if( (oneMinBid > oneMinOpen ) & (fiveMinBid > fiveMinOpen) & (fifteenMinBid > fifteenMinOpen) )
                  {
                  x=1;
                  Print("x"+x);
                  Draw.TextFixed(this, "", "Trend Up ", TextPosition.TopLeft);

                  }




                  if( (oneMinBid < oneMinOpen ) & (fiveMinBid < fiveMinOpen ) & (fifteenMinBid < fifteenMinOpen ) )
                  {
                  y=1;
                  Print("y:"+y);
                  Draw.TextFixed(this, "", "Trend Down ", TextPosition.TopLeft);

                  }


                  }



                  //Add your custom indicator logic here.
                  }
                  }
                  }

                  region NinjaScript generated code. Neither change nor remove.

                  namespace NinjaTrader.NinjaScript.Indicators
                  {
                  public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
                  {
                  private TrendTest[] cacheTrendTest;
                  public TrendTest TrendTest()
                  {
                  return TrendTest(Input);
                  }

                  public TrendTest TrendTest(ISeries<double> input)
                  {
                  if (cacheTrendTest != null)
                  for (int idx = 0; idx < cacheTrendTest.Length; idx++)
                  if (cacheTrendTest[idx] != null && cacheTrendTest[idx].EqualsInput(input))
                  return cacheTrendTest[idx];
                  return CacheIndicator<TrendTest>(new TrendTest(), input, ref cacheTrendTest);
                  }
                  }
                  }

                  namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
                  {
                  public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
                  {
                  public Indicators.TrendTest TrendTest()
                  {
                  return indicator.TrendTest(Input);
                  }

                  public Indicators.TrendTest TrendTest(ISeries<double> input )
                  {
                  return indicator.TrendTest(input);
                  }
                  }
                  }

                  namespace NinjaTrader.NinjaScript.Strategies
                  {
                  public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
                  {
                  public Indicators.TrendTest TrendTest()
                  {
                  return indicator.TrendTest(Input);
                  }

                  public Indicators.TrendTest TrendTest(ISeries<double> input )
                  {
                  return indicator.TrendTest(input);
                  }
                  }
                  }

                  #endregion

                  Attached Files
                  Last edited by f.saeidi; 03-28-2024, 03:54 AM.

                  Comment


                    #39
                    in 1 min and 5 min condition i can see trend message
                    but no trend message when i apply 15 min condition.
                    Attached Files

                    Comment


                      #40
                      What is your desire script?

                      Comment


                        #41
                        Hello f.saeidi,

                        Thanks for your notes.

                        You are still not checking if you have data loaded for all added series in the script by adding a CurrentBars check for all added series.

                        Currently, you are only checking if the primary series, the added 1-minute series, and the added 5-minute series had data loaded.

                        You need to add another CurrentBars check to the script to ensure you have data loaded for the added 15-minute series.

                        The CurrentBars condition might look something like this:

                        Code:
                        if (CurrentBars[0] < 30 || CurrentBars[1] < 30 || CurrentBars[2] < 30 || CurrentBars[3] < 30)
                            return;
                        Review this help guide page for more information about CurrentBars: https://ninjatrader.com/support/help...urrentbars.htm

                        Further, I do not see where you have added debugging prints to the script to understand how your logic is evaluating.

                        Add prints to the script (outside the conditions) that print out all the values used in the condition along with labels and the comparison operators being used in the condition. Add prints one line above the Draw methods

                        Below is a link to a forum post that demonstrates how to use prints to understand behavior.

                        ​​
                        Brandon H.NinjaTrader Customer Service

                        Comment


                          #42
                          You mean current bar 3 is for 15 min
                          Current bar 2 is for 5 min
                          Current bar 1 is for 1 min
                          What about current bar 0?
                          Is related for which time frame.
                          You know helps pdf can't help us more since it's complicated and no more explains.

                          Comment


                            #43
                            Hello f.saeidi,

                            Thanks for your notes.

                            CurrentBars[0] refers to the primary data series the script is running on.

                            CurrentBars[1] refers to the added secondary 1-minute series.

                            CurrentBars[2] refers to the added secondary 5-minute series.

                            And, CurrentBars[3] refers to the added secondary 15-minute series.

                            NinjaTrader uses the C# programming language for creating NinjaScripts and arrays/indexes in C# start counting from 0. This is a basic C# concept and I recommend doing a Google search for something like 'working with arrays in C#' or 'working with indexes in C#' to learn more on this topic. Note that we do not provide C# education in our support.

                            Review this help guide documentation which contains examples of creating a CurrentBars condition for all added secondary series and details more information about working with Multi-Timeframe/Multi-Instrument NinjaScripts: https://ninjatrader.com/support/help...nstruments.htm

                            Brandon H.NinjaTrader Customer Service

                            Comment


                              #44
                              Thnx for notes.
                              What about external indicator.
                              For example I use disco trading indicators like time and sale and others features.
                              How can I use that data for my script and strategy?
                              As well as this how can I change for example disco trading indicator features. For instance in disco trading time and sell I want to add other tabs and features for that indicator. Can I edit external indicator and how?
                              Last edited by f.saeidi; 04-02-2024, 09:12 AM.

                              Comment


                                #45
                                Hello f.saeidi,

                                Thanks for your notes.

                                If the third-party indicator contains plots, you could set up Conditions and Actions based on the third-party indicator in the Strategy Builder (New > Strategy Builder) and then click the 'View code' button to see the generated code.

                                You could also reach out to the developer of the third-party indicators directly to request instructions on how to use their indicators in custom NinjaScripts. Since the scripts are not created by NinjaTrader, we do not know exactly how those indicators are programmed to function so you should reach out to the developer regarding specifics about the indicators.
                                Brandon H.NinjaTrader Customer Service

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by fx.practic, 10-15-2013, 12:53 AM
                                5 responses
                                5,404 views
                                0 likes
                                Last Post Bidder
                                by Bidder
                                 
                                Started by Shai Samuel, 07-02-2022, 02:46 PM
                                4 responses
                                95 views
                                0 likes
                                Last Post Bidder
                                by Bidder
                                 
                                Started by DJ888, Yesterday, 10:57 PM
                                0 responses
                                8 views
                                0 likes
                                Last Post DJ888
                                by DJ888
                                 
                                Started by MacDad, 02-25-2024, 11:48 PM
                                7 responses
                                159 views
                                0 likes
                                Last Post loganjarosz123  
                                Started by Belfortbucks, Yesterday, 09:29 PM
                                0 responses
                                8 views
                                0 likes
                                Last Post Belfortbucks  
                                Working...
                                X