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

Output window and Data box showing different values

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

    #16
    Hello,

    Thank you for the post.

    This looks to be caused becasue the indicator is being set in Initialize. This should be set from OnBarUpdate in bar 0 instead:

    Code:
    private Stochastics stochK; 
    
    protected override void Initialize()
    {
    	Add(new Plot(Color.Blue, "StochK0"));// [0]
    	Add(new Plot(Color.Blue, "StochK1"));// [1]
    	Add(new Plot(Color.Blue, "Stoch42"));// [2]
    	Add(new Plot(Color.Blue, "StochK"));  // [3]
    
    	CalculateOnBarClose = true;
    }
    
    protected override void OnBarUpdate()
    {
    	if(CurrentBar == 0) stochK = Stochastics(7,3,14);
    	StochK[0] = stochK.K[0]; 
    }
    [Browsable(false)] 
    [XmlIgnore()] 
    public DataSeries StochK
    {
    	get { return Values[3]; }
    }
    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #17
      Thanks for the help!
      It all printed properly this time. Unfortunately I am still experiencing the original problem. The indicator line is printing identical to a regular stochastics K(7,15,3) line (that's new) but in Output window the code value is showing a slightly different value. This only happens when the Stochastics(7,15,3).K line in the Data Box value is showing 0. The value of the stochK in the code never reaches 0, it's always 1.89... or 1.34... etc. What is the reasoning behind the discrepancy?

      Code:
      private Stochastics indicator_stoch; 
      double stochK;
      
      protected override void OnBarUpdate()
       {
      if(CurrentBar == 0) 
            indicator_stoch = Stochastics(7,15,3);
            stochK = indicator_stoch.K[0];
            Values[3][0] = stochK;
      }

      Comment


        #18
        Hello,

        Thank you for the reply.

        Could you review the following image, is this what you are seeing or the top line in the Output Window?



        If so, this could be expected due to how floating point numbers are formatted when printed. This is exponential notation and If that is the case and you are just getting an exponentially long 0 number the solution would be to use a Print that formats to account for that:

        Code:
        Print(Time[0] + " " + StochK[0].ToString("#.#######################################"));


        Visually this can be confusing, math-wise the computer will compare the correct value of 0.xxxxxx and not what you see or 1.98xxxxxxE13.


        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by kujista, Today, 06:23 AM
        4 responses
        14 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by traderqz, Yesterday, 09:06 AM
        2 responses
        16 views
        0 likes
        Last Post traderqz  
        Started by traderqz, Today, 12:06 AM
        3 responses
        6 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by RideMe, 04-07-2024, 04:54 PM
        5 responses
        28 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by f.saeidi, Today, 08:13 AM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X