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

Prints not showing

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

    Prints not showing

    Hello
    I have the code below, but the prints for the prints for the second series (5 min) are not showing in the output window and I don't understand why?

    Code:
    else if (State == State.Configure)                
                    {
                        AddDataSeries(Data.BarsPeriodType.Tick, 1);
                        AddDataSeries(Data.BarsPeriodType.Minute, 5);                   
                }
    ...
    protected override void OnBarUpdate()
            {
                // Make sure this strategy does not execute against historical data
                if (State == State.Historical)
                    return;            
    
                if (!strategyStart)
                {
                    if(PrintOutput)
                    {
                        if (BarsInProgress == 0)
                        Print ("Strategy start 1 min bar: " + CurrentBar + " - " + Time[0]);
    
                        if (BarsInProgress == 2)
                        Print ("Strategy start 5 min bar: " + CurrentBar + " - " + Time[0]);                           
                    }
                    strategyStart = true;
                }

    #2
    Hello itrader4,

    Thank you for the post.

    Did you happen to remove/re apply the script after adding the secondary data?

    I otherwise don't see the problem here specifically. you may try a print like the following to better understand if the series is being called at all:

    Code:
    protected override void OnBarUpdate()
            {
    [B]Print(BarsInProgress + " " + Time[0]);[/B]
                // Make sure this strategy does not execute against historical data
                if (State == State.Historical)
                    return;            
    
                if (!strategyStart)
                {
                    if(PrintOutput)
                    {
                        if (BarsInProgress == 0)
                        Print ("Strategy start 1 min bar: " + CurrentBar + " - " + Time[0]);
    
                        if (BarsInProgress == 2)
                        Print ("Strategy start 5 min bar: " + CurrentBar + " - " + Time[0]);                          
                    }
                    strategyStart = true;
                }

    Edit: On a second look I see you have strategyStart = true;, if BIP 0 or 1 called OnBarUpdate and set that to true you would not see the print when BIP 2 eventually calls OBU. I would suggest removing your condition here and just print the value to confirm that is working first.


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

    Comment


      #3
      That's the result: series 2 is called, but it's not printing and I always remove and reapply the script after making changes

      0 18/11/2019 05:15:00
      1 18/11/2019 05:14:37
      1 18/11/2019 05:14:37
      2 18/11/2019 05:15:00
      2 18/11/2019 05:15:00
      Enabling NinjaScript strategy 'ATM2/178978156' : On starting a real-time strategy - StartBehavior=WaitUntilFlat EntryHandling=All entries EntriesPerDirection=1 StopTargetHandling=Per entry execution ErrorHandling=Stop strategy, cancel orders, close positions ExitOnSessionClose=True / triggering 30 seconds before close SetOrderQuantityBy=Strategy ConnectionLossHandling=Recalculate DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=True CancelExitsOnStrategyDisable=True Calculate=On each tick IsUnmanaged=False MaxRestarts=4 in 5 minutes
      0 18/11/2019 05:15:00
      Strategy start 1 min bar: 1753 - 18/11/2019 05:15:00
      1 18/11/2019 05:14:46
      2 18/11/2019 05:15:00
      0 18/11/2019 05:15:00
      1 18/11/2019 05:14:50
      2 18/11/2019 05:15:00
      Last edited by itrader46; 11-22-2019, 11:32 AM.

      Comment


        #4
        Hello itrader46 ,

        Thanks for testing that.

        it looks like this relates to your conditions, you would need to reform the conditions you have. The series is being called so the problem lies later in your code.

        Lets assume BIP 0 called OBU:

        0 18/11/2019 05:15:00
        1. Your logic is run and the print is seen:
          • Strategy start 1 min bar: 1753 - 18/11/2019 05:15:00
        2. You set strategyStart = true;
        3. You surround the prints with a condition if (!strategyStart) if the variable is not true, but you set it to true.
        4. Now the prints should no longer work for the other series based on what you have programmed.
        It seems to be working as it was designed currently.




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

        Comment


          #5
          But I thought that strategyStart bool doesn't become true until after it processed series 2 bar printing?

          Code:
           if (!strategyStart)            
          {                
             if(PrintOutput)                
             {                    
                if (BarsInProgress == 0)                    
                Print ("Strategy start 1 min bar: " + CurrentBar + " - " + Time[0]);                      
                if (BarsInProgress == 2)                    
                Print ("Strategy start 5 min bar: " + CurrentBar + " - " + Time[0]);                                          
             }                
             strategyStart = true;            
          }

          Comment


            #6
            Hello itrader46 ,

            Thanks for the reply.

            Not in this case based on how you formed the logic, pay specific attention to the placement of the variable and your curly braces:

            Code:
            if (!strategyStart)
            {
            [B] if (PrintOutput)
                {[/B]
                    if (BarsInProgress == 0)
                        Print("Strategy start 1 min bar: " + CurrentBar + " - " + Time[0]);
                    if (BarsInProgress == 2)
                        Print("Strategy start 5 min bar: " + CurrentBar + " - " + Time[0]);
            [B]   }
                strategyStart = true;[/B]
            }
            The BarsInProgress checks you have will not all happen in the same OnBarUpdate call, you would see 3 separate OnBarUpdates to see this logic executed fully. As you have it now if this happens one time it will set it to true preventing it going forward unless strategyStart becomes false again at some point. There is nothing in this condition to make the strategyStart set true only for BIP2.

            Did you intend to do:

            Code:
            if (!strategyStart)
            {
                if (PrintOutput)
                {
                    if (BarsInProgress == 0)
                        Print("Strategy start 1 min bar: " + CurrentBar + " - " + Time[0]);
            [B] if (BarsInProgress == 2)
                    {
                        Print("Strategy start 5 min bar: " + CurrentBar + " - " + Time[0]);
                        strategyStart = true;
                    }[/B]
                }
            }
            This would only be set once the BIP 2 has been called once.


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

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by hazylizard, Today, 08:38 AM
            3 responses
            10 views
            0 likes
            Last Post NinjaTrader_Erick  
            Started by geddyisodin, Today, 05:20 AM
            2 responses
            18 views
            0 likes
            Last Post geddyisodin  
            Started by Max238, Today, 01:28 AM
            5 responses
            47 views
            0 likes
            Last Post Max238
            by Max238
             
            Started by giulyko00, Yesterday, 12:03 PM
            3 responses
            13 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by habeebft, Today, 07:27 AM
            1 response
            16 views
            0 likes
            Last Post NinjaTrader_ChristopherS  
            Working...
            X