Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Global method : GetBarsAgo()

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

  • NinjaTrader_PatrickH
    replied
    Hello Shannon,

    Thank you for your update.

    I am still unable to reproduce this on my end. Perhaps we can schedule a time to look into this further on your PC? If so, please send us a note to platformsupport[at]ninjatrader[dot]com with this thread in reference: "http://ninjatrader.com/support/forum/showthread.php?t=76553"

    Leave a comment:


  • Shansen
    replied
    Dave,

    To assist in recreating the error I am experiencing, please amend the Global Methods.cs file to include the below bold code.

    Code:
    namespace NinjaTrader.NinjaScript.Indicators
    {
      public partial class Indicator
      {
        public int GetBarsAgo(int barNumber) 
        {
          Debug.Print(Time[0].ToString("g") + " - CurrentBar = \t" + CurrentBar);
          return CurrentBar - barNumber;
        }
      }
    }
    The addition of above code results in the below excerpt from the VS Output window when a strategy uses an indicator using the GetBarsAgo() method. Please note the strategy was applied to a chart where "Bars to load" = 1850. Please note "..." represents output lines that have been removed for conciseness):
    2015-08-18 06:32:58:328 Indicator - SetDefaults begun
    2015-08-18 06:32:58:335 Indicator - Terminated begun
    2015-08-18 06:32:58:342 Indicator - Configure begun
    2015-08-18 06:32:58:349 Indicator - DataLoaded begun
    2015-08-18 06:32:58:371 Indicator - Historical begun
    2015-08-18 06:32:58:374 10/07/2014 1:30 AM - CurrentBar = 35
    2015-08-18 06:32:58:375 10/07/2014 5:30 AM - CurrentBar = 39
    2015-08-18 06:32:58:376 10/07/2014 5:30 AM - CurrentBar = 39
    ...
    2015-08-18 06:32:58:520 6/09/2014 1:30 AM - CurrentBar = 232
    2015-08-18 06:32:58:520 6/09/2014 1:30 AM - CurrentBar = 232
    2015-08-18 06:32:58:520 Strategy - SetDefaults begun
    2015-08-18 06:32:58:520 6/09/2014 1:30 AM - CurrentBar = 232
    2015-08-18 06:32:58:520 6/09/2014 1:30 AM - CurrentBar = 232
    ...
    2015-08-18 06:32:58:560 13/09/2014 4:30 AM - CurrentBar = 243
    2015-08-18 06:32:58:560 13/09/2014 4:30 AM - CurrentBar = 243
    2015-08-18 06:32:58:560 Strategy - Terminated begun
    2015-08-18 06:32:58:562 16/09/2014 5:30 AM - CurrentBar = 251
    2015-08-18 06:32:58:562 17/09/2014 12:30 AM - CurrentBar = 253
    ...
    2015-08-18 06:32:58:621 26/09/2014 4:30 AM - CurrentBar = 306
    2015-08-18 06:32:58:621 26/09/2014 4:30 AM - CurrentBar = 306
    2015-08-18 06:32:58:623 26/09/2014 4:30 AM - CurrentBar = 1849
    2015-08-18 06:32:58:623 26/09/2014 4:30 AM - CurrentBar = 1849
    ...
    2015-08-18 06:32:58:639 Indicator - Transition begun
    2015-08-18 06:32:58:640 Indicator - Realtime begun
    I believe the output highlights two issues
    1. When a Strategy is added using indicators which use the GetBarsAgo() method, midway through calculation CurrentBar has returned the BarNumber of the last BarNumber of the chart (i.e. the chart "Bars to load" = 1850 thus CurrentBar = 1849).
    2. Strategy OnStateChanges appear to be occurring midway through calculation.


    Please assist
    Regards
    Shannon

    Leave a comment:


  • Shansen
    replied
    Dave,

    I have converted the NT8 indicator and strategy (as attached to the 2 August 2015 email) back to NT7 with minor reversions made for code breaking changes.

    The indicator and strategy are stable in NT7. While this is a crude test, I can only deduce the issue is with the implementation of the indicator and strategy in NT8.

    Any ideas are welcome.
    Regards
    Shannon

    Leave a comment:


  • Shansen
    replied
    Dave,

    In the VS debug output window, the below output is produced.
    The thread 0xdf4 has exited with code 259 (0x103).
    The thread 0xdc0 has exited with code 259 (0x103).
    The thread 0xbf8 has exited with code 259 (0x103).
    The thread 0xfac has exited with code 259 (0x103).
    To date, the output does not appear to have a detrimental impact.

    To ensure it not causing any harm, I'd like to address and remove the cause.
    Any ideas on how to investigate what is causing this output?

    Regards
    Shannon

    Leave a comment:


  • Shansen
    replied
    Dave,

    Thank you for the reply.

    Given your testing did not show any issue and your testing started with a blank slate, I rebuilt the indicator from a blank slate. While the incidence of the issue is greatly reduced, one error in approximately 50-100 refreshes, the issue still presents.

    The issue presents in the exact code as attached to the 2 August 2015 email (I am not testing the full code at this time).

    The only event which may account for the reduced frequency of error is an update of Microsoft Visual Studio Professional 2013 to Version 12.0.40629.00 Update 5.

    Any ideas for further investigation would be greatly appreciated.

    Thanks again
    Shannon

    Leave a comment:


  • NinjaTrader_DaveI
    replied
    Hello,

    Unfortunately, I'm not able to reproduce this behavior on my end. I've tried both the Beta 3 build and the most recent build on my side, and each time I reload NinjaScript, the indicator plots the same as before the reload, and the strategy remains enabled.

    Can you think of anything else going on in your full code that may be causing the issue?

    Leave a comment:


  • NinjaTrader_DaveI
    replied
    Sorry for the delay on this one -- I'll post back here with more info soon.

    Leave a comment:


  • Shansen
    replied
    Dave,

    As requested, the scripts with full explanation on how to replicate the issue was sent via email to PlatformSupport on 2 August with the subject line "ATTN: NinjaTrader_Dave RE: NT Forum thread - Global method : GetBarsAgo())".

    Please advise if the communication was received.

    Thanks
    Shannon

    Leave a comment:


  • NinjaTrader_DaveI
    replied
    It seems clear that something is going wrong in the Configure State of the hosted indicator, but we are unable to reproduce the type of results you are seeing. Can you share your script(s) with us, so that we can try to replicate the issue and work with a reproducible scenario?

    Leave a comment:


  • NinjaTrader_DaveI
    replied
    Thank you -- that does seem to confirm that the error is being triggered before OnBarUpdate() executes. I'm going to dig into this one a bit, and I will post back here with any new information.

    Leave a comment:


  • Shansen
    replied
    Dave,

    On your advice, the code has been changed to the below for MyStrategy (and similar for MyIndicator):
    Code:
    public class MyStrategy: Strategy
    {
    
      protected override void OnStateChange()
      {
        Print("Strategy - " + State + " begun");
        //etc
      }
    
      protected override void OnBarUpdate()
      {
        Print("Strategy - OnBarUpdate begun");
        //etc
      }
    }
    This results in:
    Open Strategy window:
    Strategy - SetDefaults begun
    Strategy - Terminated begun
    Strategy - SetDefaults begun
    Add MyStrategy to Configured Strategy frame
    Strategy - SetDefaults begun
    Order Confirmation pops up
    Strategy - SetDefaults begun
    Strategy - Terminated begun
    Strategy - Terminated begun
    Strategy - Terminated begun
    OK Order Confirmation
    Strategy - Configure begun
    Strategy - Configure begun
    Indicator - SetDefaults begun
    Indicator - Configure begun
    Strategy - Terminated begun
    Indicator - Terminated begun
    If I understand this correctly, OnBarUpdate is never executed.
    The error occurs during Strategy State.Configure.

    Regards
    Shannon

    Leave a comment:


  • NinjaTrader_DaveI
    replied
    Hello,

    One thing to note in your code is that you are not necessarily printing those statements when the State completes, but rather just printing them within the state. You may find more insight by printing "State Active" in several States, including State.Historical. This way, you can know for certain whether State.Historical is entered before or after the error.

    Leave a comment:


  • Shansen
    replied
    Mathew,

    Thank you for your response, and thank you for the "Bars.GetHigh(idx)" method. I will look to refactor code to include it.

    On attempting to further debug this issue, I have hit another snag. To better understand when the issue presents, Print commands have been added to MyStrategy and MyIndicator. Print commands are placed at the end of State.Configure and at the start of OnBarUpdate as per the below code:
    Code:
    public class MyStrategy: Strategy
    {
      private MyIndicator _myIndicator;
    
      protected override void OnStateChange()
      {
        if (State == State.Configure)
        {
          _myIndicator = MyIndicator();
          Print("MyStrategy State.Configure complete");
        }
      }
    
      protected override void OnBarUpdate()
      {
        Print("MyStrategy OnBarUpdate begun");
        //etc
      }
    }
    
    public class MyIndicator: Indicator
    {
      
      protected override void OnStateChange()
      {
        if (State == State.Configure)
        {
          Print("MyIndicator State.Configure complete");
        }
      }
    
      protected override void OnBarUpdate()
      {
        Print("MyIndicator OnBarUpdate begun");
        //etc
      }
    }
    Which results in the output:
    MyIndicator State.Configure complete
    MyStrategy State.Configure complete
    The output window appears to show that while State.Configure is completed, OnBarUpdate is not begun before the 'System.ArgumentOutOfRangeException' is encountered.

    Debugging in Visual Studio still shows the 'System.ArgumentOutOfRangeException' as a result of referencing the method GetBarsAgo. However, I do not understand how this code has been hit without passing through the Print commands "MyStrategy OnBarUpdate begun" or "MyIndicator OnBarUpdate begun".

    Any ideas are welcome
    Regards
    Shannon

    Leave a comment:


  • NinjaTrader_Matthew
    replied
    Also, I suppose you could definitely hit an exception if you tried calculating that OnBarUpdate() when the Currentbar is less than the value you passed in, but that would be the same between an indicator or strategy so I would need clarification on why you get that in one class but not the other. Nor has the behavior changed since NinjaTrader 7. Please let me know exactly what you're passing in to your helper method and I'll be happy to review.

    Leave a comment:


  • NinjaTrader_Matthew
    replied
    Hmm, I do not get any errors when I run that from a strategy or indicator. Can you provide the strategy that results in the exception?

    As a side note, are you aware of the Bars.GetHigh(idx) method? There is a method for each bars data point which gets you that value of the absolute index. I.e., If you pass in Bars.GetHigh(0); it will return the high of the very first bar on the chart.

    Leave a comment:

Latest Posts

Collapse

Topics Statistics Last Post
Started by maxbhbreviews, Today, 06:34 AM
0 responses
3 views
0 likes
Last Post maxbhbreviews  
Started by ChainsawDR, Today, 02:40 AM
0 responses
36 views
0 likes
Last Post ChainsawDR  
Started by salevigornowusa, Today, 01:37 AM
0 responses
38 views
0 likes
Last Post salevigornowusa  
Started by salevigornowusa, Today, 01:36 AM
0 responses
36 views
0 likes
Last Post salevigornowusa  
Started by U0000999, Today, 01:30 AM
0 responses
41 views
0 likes
Last Post U0000999  
Working...
X