Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to store last known value greater then 0

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

    #16
    Hello tkaboris,

    Thanks for your notes.

    Yes, that would be the correct way to set up the public variable in the script and that is also the correct way to access the variable in a different script.

    If the scripts are not behaving as expected then you would need to debug your scripts by reducing code and adding prints to understand how your logic in each script is evaluating and behaving.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #17
      HI, maybe you have another idea of why when i copied all the code of one indicator to another and when it two indicators now combined, i get all the HH and LH, instead of only HH.
      Interesting note when i refresh indicator and before market replay, it prints right values, shown below, these are only HHs. as soon as i start market replay live it starts printing HH and LHs....

      hhPriceLevel in fvg ind14802.25
      hhPriceLevel in fvg ind14800.75
      hhPriceLevel in fvg ind14797.5
      hhPriceLevel in fvg ind14804.25
      hhPriceLevel in fvg ind14805.25​

      Comment


        #18
        Hello tkaboris,

        Thanks for your notes.

        Without seeing the full script and debugging it, I cannot say for sure what might be causing the behavior between your scripts.

        In the second script, you might consider using a different variable name so that it is unique and ensure that only the hhPriceLevel public variable from the first script is being assigned to a variable in the second script.

        Also, add prints to the scripts that allow you to tell which indicator the print in the Output window is coming from when debugging.

        Ultimately, you would need to further test, reduce, and debug your script to find the exact line of code causing the behavior in your script.

        Debugging your NinjaScript code: https://ninjatrader.com/support/help...script_cod.htm
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment


          #19
          how to print where value is coming from?
          i only used unique prints like below

          Print("hhPriceLevel1 in Chart Trader:"+hhPriceLevel1 );

          I tried but its still printing both HH and LL
          I attach a script to see maybe you can glance through it to see why its not printing only HH or LL
          I also tried to change private to public hhPriceLevel but still not worked out...
          Last edited by tkaboris; 11-01-2023, 09:56 AM.

          Comment


            #20
            Hello tkaboris,

            Thanks for your notes.

            You could create prints in the each script that state something like Print("hhPriceLevel1 <indicator name> is: + hhPriceLevel1") to differentiate which script the prints are coming from in the Output window if you have not yet done so. Note that the name of the indicator is included in the print to tell which script the print is coming from.

            When testing the script you shared on my end using the Playback connection, I am only seeing prints for hhPriceLevel when the HH text is drawn on the chart. When LL or LH or HL is drawn on the chart, no prints are appearing in the Output window.

            See this demonstration video: https://brandonh-ninjatrader.tinytak...MF8yMjMzMDY1Mg

            I suggest that you run a compile on your script in the Editor window to save any changes made. Then, remove the indicator from the chart and re-add the indicator to the chart to make sure the changes you made took affect.
            <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

            Comment


              #21
              I appriciate it i was able to remove other script(chart trader) and fvgindicator it prints as yours, as it suppose to, but as soon as i add chart indicator it starts pulling both value HH and LL.
              i have renamed varible to hhPriceLevel1 in chart trader..

              Maybe you can glance too? you probably need to delete the previous file...

              Comment


                #22
                Hello tkaboris,

                Thanks for your notes.

                I was able to reproduce the behavior you mentioned and to understand exactly how your script's logic is behaving you would have to further debug the strategy by reducing code.

                I suggest creating a very simple test script that accesses the value of the first indicator and prints the value to the Output window to see how it is behaving. Then, once your confirm is it behaving as expected, you could add another section of logic to the script and retest to see if it is behaving as expected.

                When identifying an issue, it is extremely important to have extremely simple test scripts and very simple steps to reproduce that only have the bare minimum code necessary to reproduce the behavior without any other code and do not require specific market conditions to reproduce (unless the issue is with specific market conditions).

                To truly know what is causing the issue it would be necessary to use prints and debug by looking at all of the information the script is using for decisions.
                <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                Comment


                  #23
                  hi i created simple script but its giving out errors. it doesnt see those values

                  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 MarktStructureShiftTest : Indicator
                      {
                          private NinjaTrader.NinjaScript.Indicators.FVGIndicator fvgInd;
                          private double hhPriceLevel1;
                          protected override void OnStateChange()
                          {
                              if (State == State.SetDefaults)
                              {
                                  Description                                    = @"Enter the description for your new custom Indicator here.";
                                  Name                                        = "MarktStructureShiftTest";
                                  Calculate                                    = Calculate.OnBarClose;
                                  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)
                              {
                              }
                              else if (State == State.DataLoaded)
                              {
                  //                fvgInd = FVGIndicator(UseFVGDataSeries, FVGBarsPeriodType, FVGSeriesPeriod, 50, true, ImpulseFactor, 10, MinimumFVGSize, AllBarsSameDirection, FillType, false, false, false, tsSilverBullet1.Add(tsTZDifference), 60, false, tsSilverBullet2.Add(tsTZDifference), 60, false, tsSilverBullet3.Add(tsTZDifference), 60,12,true,12,14,Brushes.Green,Brushes.Red,2,DashStyleHelper.Solid,true);
                              }
                          }
                  
                          protected override void OnBarUpdate()
                          {
                              fvgInd = FVGIndicator(UseFVGDataSeries, FVGBarsPeriodType, FVGSeriesPeriod, 50, true, ImpulseFactor, 10, MinimumFVGSize, AllBarsSameDirection, FillType, false, false, false, tsSilverBullet1.Add(tsTZDifference), 60, false, tsSilverBullet2.Add(tsTZDifference), 60, false, tsSilverBullet3.Add(tsTZDifference), 60,12,true,12,14,Brushes.Green,Brushes.Red,2,DashStyleHelper.Solid,true);
                  
                          }
                      }
                  }​
                  Click image for larger version

Name:	image.png
Views:	125
Size:	93.1 KB
ID:	1275873

                  Comment


                    #24
                    Hello tkaboris,

                    Thanks for your notes.

                    You should be instantiating the indicator in OnStateChange() when the State == State.DataLoaded, not in OnBarUpdate().

                    This error message indicates that you are accessing something in your script that is not defined in the script.

                    For example, the error stating "The name 'ImpulseFactor' does not exist in the current context" indicates that you are using 'ImpulseFactor' in the script but you have not defined what 'ImpuleFactor' is in the script. You would need to define this variable in your script before using it to resolve the error.

                    You are using 'UseFVGDataSeries' when instantiating your indicator but this is not defined in your script.

                    Further, you are using 'FVGBarsPeriodType' in your script but this is also not defined anywhere in the script.

                    See this help guide page for more information about this error: https://ninjatrader.com/support/help...tml?cs0103.htm
                    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                    Comment


                      #25
                      hi my understanding is that it should not behave this way, i am simply referencing an already made indicator and dont need to define those missing values again.

                      right i moved instantiating into dataloaded part and still getting those same errors.

                      Comment


                        #26
                        Hello tkaboris,

                        Thanks for your notes.

                        You have not defined those user-defined input variables in your test script so they do not exist in that specific script but you are trying to access them which is causing the errors.

                        For example, if we replace 'ImpulseFactor' with a value and recompile, the error message no longer appears.

                        From the example above, when we change "ImpulseFactor" in this code:

                        fvgInd = FVGIndicator(UseFVGDataSeries, FVGBarsPeriodType, FVGSeriesPeriod, 50, true, ImpulseFactor, 10, MinimumFVGSize, AllBarsSameDirection, FillType, false, false, false, tsSilverBullet1.Add(tsTZDifference), 60, false, tsSilverBullet2.Add(tsTZDifference), 60, false, tsSilverBullet3.Add(tsTZDifference), 60,12,true,12,14,Brushes.Green,Brushes.Red,2,DashS tyleHelper.Solid,true);

                        To be "1.1" instead of "ImpulseFactor":

                        fvgInd = FVGIndicator(UseFVGDataSeries, FVGBarsPeriodType, FVGSeriesPeriod, 50, true, 1.1, 10, MinimumFVGSize, AllBarsSameDirection, FillType, false, false, false, tsSilverBullet1.Add(tsTZDifference), 60, false, tsSilverBullet2.Add(tsTZDifference), 60, false, tsSilverBullet3.Add(tsTZDifference), 60,12,true,12,14,Brushes.Green,Brushes.Red,2,DashS tyleHelper.Solid,true);

                        When we recompile that error message no longer appears.

                        If you want to have the parameters of the indicator to be user-defined inputs when instantiating it in the test script then you must add those user-defined inputs to that specific test script. Otherwise, you would need to assign specific values to the parameters when instantiating the indicator.

                        A more simple example of this is if you look at the SMA indicator that comes default with NinjaTrader, it contains a user-defined variable called 'Period'. However, if you want to instantiate the SMA indicator in a custom script using a user-defined variable for the Period argument, you would need to create a user-defined variable in the custom script called 'Period' and then pass that into the SMA indicator when instantiating it.
                        Last edited by NinjaTrader_BrandonH; 11-01-2023, 11:56 AM.
                        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                        Comment


                          #27
                          You are absolutely right..
                          my brain fog.
                          i changed it to the value below and its printing values as suppose to, only HH...


                          fvgInd = FVGIndicator(false,FVGPeriodTypes.Second,5,50,fals e,1,10,2,false,FVGFillType.CLOSE_THROUGH,true,true ,false,new TimeSpan(2, 14, 18),60,false,new TimeSpan(2, 14, 18),60,false,new TimeSpan(2, 14, 18),60,12,true,10,14,Brushes.Red,Brushes.Green,2,D ashStyleHelper.Solid,true);

                          well this chart trader(my other script) is 2000 lines of code, its not feasible to strip it down... Any other ideas where i can find an issue?

                          Comment


                            #28
                            Hello tkaboris,

                            Thanks for your notes.

                            No, you would need to reduce your code and debug the logic throughout the script to narrow down wich exact line of code in your script is causing the behavior you are reporting to occur.

                            When working with any issue, it is important to take steps to isolate the issue so that the exact line causing the behavior can be found.

                            This is a process of elimination and a process of debugging by adding prints.

                            First, its great to create a copy of the script so that the original work is kept safe. To create a copy of a script, right-click within the script in the NinjaScript Editor window, select 'Save as', and name the copy of the script.

                            Once the copy is created, the copy can be modified in any way without losing the original work.

                            The next step is to start commenting out code and adding debugging prints throughout the script that prints all the information being used for the scripts logic to understand how specific sections of code are evaluating within the script.

                            <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                            Comment


                              #29
                              i am strippind down alot already but still doing the same thing. i was wondering maybe there is an issue with using section. maybe there is something thats not needed or causing issue in chart trader?

                              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.Controls;
                              using System.Collections.ObjectModel;
                              using System.Collections.Specialized;
                              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.Indicators;
                              using NinjaTrader.NinjaScript.DrawingTools;
                              #endregion​

                              Comment


                                #30
                                Hello tkaboris,

                                Thanks for your notes.

                                I do not see anything specific in the Using declarations you shared that would cause the behavior to occur.

                                If the test script you made printed the values correctly as you noted in post # 27 then it is likely something in the custom logic of your script that is causing the behavior.

                                You could consider moving one section of code over to the test indicator since that script is working as expected and test the script after moving over each individual section of code.

                                If you see the behavior reoccur when testing your test script then the last section of code you moved over is likely causing the unexpected behavior to occur. You could then further debug that section of code to find the exact line of code causing the behavior.
                                <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                636 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                366 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                107 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                568 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                571 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X