Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Data.Loaded not working

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

    Data.Loaded not working

    Hello, I am trying to run my custom strategy and the Data.Loaded will not be accessed, or is not working properly, or I have messed something up on my end.
    Code:
    else if (State == State.Configure)
                {
                    Print("State.Configure1");
                }
                else if (State == State.DataLoaded)
                {                
                    Print("State.DataLoaded1");
                    VWMA1                = VWMA(Close, Convert.ToInt32(VWMA_Period));
                    VWMA1.Plots[0].Brush = Brushes.DodgerBlue;
                    AddChartIndicator(VWMA1);
                    SetProfitTarget(@"Long", CalculationMode.Ticks, TP);
                    SetTrailStop(@"Long", CalculationMode.Ticks, TrailingSL, false);
                    SetProfitTarget(@"Short", CalculationMode.Ticks, TP);
                    SetTrailStop(@"Short", CalculationMode.Ticks, TrailingSL, false);
                    Print("State.DataLoaded2");
                }​
    The "State.configure1" prints just fine, however "State.DataLoaded1" does not print ever. I even left it running on a playback last night for 6 hours, nothing. Any idea what could be going on?
    Thank you

    #2
    Looking at post now, the
    Code:
    else if (State == State.Configure)
    is properly indented on my ninjascript editor, sorry for any confusion that may cause

    Comment


      #3
      Hello rbeckmann05,

      From the small portion of the code I cant see a problem, I would suggest uploading the entire OnStateChange override so we can see all of the conditions used.

      Another approach is to generate the code using the strategy builder to make sure you don't have conflicting conditions in OnStateChange. Using the builder make a condition using any indicator and then click View Code. That will produce a State.DataLoaded condition in OnStateChange for you to compare with.

      Keep in mind DataLoaded is only called once when your script first starts up, it won't be called again while running playback or in realtime. DataLoaded is a preparation state which lets you configure items like indicators that need specific data series. If your script is processing bars that means it passed DataLoaded already.

      https://ninjatrader.com/support/help...sub=DataLoaded

      Comment


        #4
        Here is my code since the strategies class is inititalized:
        Code:
        public class BeckFlowsStrategy : Strategy
            {
                private VWMA VWMA1;
        
                protected override void OnStateChange()
                {
                    if (State == State.SetDefaults)
                    {
                        Description                                    = @"Enter the description for your new custom Strategy here.";
                        Name                                        = "BeckFlowsStrategy";
                        Calculate                                    = Calculate.OnEachTick;
                        EntriesPerDirection                            = 1;
                        EntryHandling                                = EntryHandling.AllEntries;
                        IsExitOnSessionCloseStrategy                = true;
                        ExitOnSessionCloseSeconds                    = 30;
                        IsFillLimitOnTouch                            = false;
                        MaximumBarsLookBack                            = MaximumBarsLookBack.TwoHundredFiftySix;
                        OrderFillResolution                            = OrderFillResolution.Standard;
                        Slippage                                    = 0;
                        StartBehavior                                = StartBehavior.WaitUntilFlat;
                        TimeInForce                                    = TimeInForce.Gtc;
                        TraceOrders                                    = false;
                        RealtimeErrorHandling                        = RealtimeErrorHandling.StopCancelClose;
                        StopTargetHandling                            = StopTargetHandling.PerEntryExecution;
                        BarsRequiredToTrade                            = 20;
                        // Disable this property for performance gains in Strategy Analyzer optimizations
                        // See the Help Guide for additional information
                        IsInstantiatedOnEachOptimizationIteration    = true;
                        QTY                                            = 1;
                        TP                                            = 22;
                        TrailingSL                                    = 18;
                        Min_Volume_For_Thin                            = 0;
                        Max_Volume_For_Thin                            = 20;
                        Minimum_Small_Delta_For_Imbalance            = 1;
                        Minimum_Big_Delta_For_Imbalance                = 20;
                        High_Low_Bar_Offset                            = 2;
                        Advanced_Removal_Process                    = true;
                        VWMA_Period                                    = 6;
                        Ticks_Per_Level                                = 4;
                        Use_dPOC                                    = true;
                    }
                    else if (State == State.Configure)
                    {
                        Print("State.Configure1");
                    }
                    else if (State == State.DataLoaded)
                    {                
                        Print("State.DataLoaded1");
                        VWMA1                = VWMA(Close, Convert.ToInt32(VWMA_Period));
                        VWMA1.Plots[0].Brush = Brushes.DodgerBlue;
                        AddChartIndicator(VWMA1);
                        SetProfitTarget(@"Long", CalculationMode.Ticks, TP);
                        SetTrailStop(@"Long", CalculationMode.Ticks, TrailingSL, false);
                        SetProfitTarget(@"Short", CalculationMode.Ticks, TP);
                        SetTrailStop(@"Short", CalculationMode.Ticks, TrailingSL, false);
                        Print("State.DataLoaded2");
                    }
                }​
        I don't see anything wrong with it, however maybe a new set of eyes will see something. A large majority of this was made in the strategy builder, so I don't think there should be any issues with that.

        Comment


          #5
          Hello rbeckmann05,

          That looks correct, are you certain that its not being printed? do you have any prints in OnBarUpdate? If you have prints in OnBarUpdate you would need to scroll up to the top of the output to see the single DataLoaded print. If its not printing at all that could indicate there was an error and the strategy was not enabled or that the data actually was not loaded.

          As a next step I would suggest creating a new empty strategy using the strategy builder and then unlock the code to add your print into State.DataLoaded. Don't add any conditions or actions, just unlock the code and add the print and compile. Then enable the strategy on a chart where you have data. That will help to confirm if there is a problem in your existing code or with the use case. You should see a single print only after you have enabled the strategy and it is running.



          Comment


            #6
            Yes, the only thing showing up in the ninjascript output is "State.Configure1". And unfortunately no, I have a "Print('Update');" in the first line of my "OnBarUpdate()" method, however nothing is happening there either. Could it be a problem with my properties? Here they are:
            Code:
                    [NinjaScriptProperty]
                    [Range(1, int.MaxValue)]
                    [Display(Name="QTY", Order=1, GroupName="Parameters")]
                    public int QTY
                    { get; set; }
            
                    [NinjaScriptProperty]
                    [Range(1, int.MaxValue)]
                    [Display(Name="TP", Order=2, GroupName="Parameters")]
                    public int TP
                    { get; set; }
            
                    [NinjaScriptProperty]
                    [Range(1, int.MaxValue)]
                    [Display(Name="TrailingSL", Order=3, GroupName="Parameters")]
                    public int TrailingSL
                    { get; set; }
            
                    [NinjaScriptProperty]
                    [Range(0, int.MaxValue)]
                    [Display(Name="Min_Volume_For_Thin", Order=4, GroupName="Parameters")]
                    public int Min_Volume_For_Thin
                    { get; set; }
            
                    [NinjaScriptProperty]
                    [Range(1, int.MaxValue)]
                    [Display(Name="Max_Volume_For_Thin", Order=5, GroupName="Parameters")]
                    public int Max_Volume_For_Thin
                    { get; set; }
            
                    [NinjaScriptProperty]
                    [Range(0, int.MaxValue)]
                    [Display(Name="Minimum_Small_Delta_For_Imbalance", Order=6, GroupName="Parameters")]
                    public int Minimum_Small_Delta_For_Imbalance
                    { get; set; }
            
                    [NinjaScriptProperty]
                    [Range(1, int.MaxValue)]
                    [Display(Name="Minimum_Big_Delta_For_Imbalance", Order=7, GroupName="Parameters")]
                    public int Minimum_Big_Delta_For_Imbalance
                    { get; set; }
            
                    [NinjaScriptProperty]
                    [Range(0, int.MaxValue)]
                    [Display(Name="High_Low_Bar_Offset", Order=8, GroupName="Parameters")]
                    public int High_Low_Bar_Offset
                    { get; set; }
            
                    [NinjaScriptProperty]
                    [Display(Name="Advanced_Removal_Process", Description="Check for open close calculation, uncheck for until tested calculation", Order=9, GroupName="Parameters")]
                    public bool Advanced_Removal_Process
                    { get; set; }
            
                    [NinjaScriptProperty]
                    [Range(1, int.MaxValue)]
                    [Display(Name="VWMA_Period", Order=10, GroupName="Parameters")]
                    public int VWMA_Period
                    { get; set; }
            
                    [NinjaScriptProperty]
                    [Range(1, int.MaxValue)]
                    [Display(Name="Ticks_Per_Level", Order=11, GroupName="Parameters")]
                    public int Ticks_Per_Level
                    { get; set; }
            
                    [NinjaScriptProperty]
                    [Display(Name="Use_dPOC", Order=12, GroupName="Parameters")]
                    public bool Use_dPOC
                    { get; set; }​

            Comment


              #7
              Hello rbeckmann05,

              That would indicate there is a problem loading data or that the strategy is not being enabled. Please try the steps that I had suggested previously using the strategy builder to make a new empty strategy. If your current strategy has problematic code that may be the issue.

              Comment


                #8
                Alright, I will try that out. Thank you for the help, hopefully that fixes it.

                Comment


                  #9
                  NinjaTrader_Jesse Just created a new strategy purely with the strategy builder, with the only thing me changing being a "Print("Done")" in the DataLoaded storage, and it still does not work, no print or anything

                  Comment


                    #10
                    Hello rbeckmann05,

                    Can you list the steps that you are doing to enable the strategy? That would include the connection being used an if you are using the chart or control center.

                    Comment


                      #11
                      Hi Jesse,

                      I was able to figure it out. While I was testing in playback, the strategy was connected to a different account connection. However this is still weird, because usually being connected to a disconnected account in the strategy menu would disable the strategy no? Anyways, thank you for the help, much appreciated

                      Comment


                        #12
                        Hello rbeckmann05,

                        When you connect to the playback connection you need to apply new instances of the strategy. The same applies to strategies you used in playback, if you want to use them live you need to re apply them so the correct account can be selected.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by NullPointStrategies, Today, 05:17 AM
                        0 responses
                        53 views
                        0 likes
                        Last Post NullPointStrategies  
                        Started by argusthome, 03-08-2026, 10:06 AM
                        0 responses
                        130 views
                        0 likes
                        Last Post argusthome  
                        Started by NabilKhattabi, 03-06-2026, 11:18 AM
                        0 responses
                        70 views
                        0 likes
                        Last Post NabilKhattabi  
                        Started by Deep42, 03-06-2026, 12:28 AM
                        0 responses
                        44 views
                        0 likes
                        Last Post Deep42
                        by Deep42
                         
                        Started by TheRealMorford, 03-05-2026, 06:15 PM
                        0 responses
                        49 views
                        0 likes
                        Last Post TheRealMorford  
                        Working...
                        X