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

Loop

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

    Loop

    I have here a simple loop.

    PHP Code:
    if(CurrentBar 11) return;
            
    Rank1nummer 0;    
            
    Rank2nummer 0;    
            
    Rank3nummer 0;    
            
    for (
    int a 1;   11 a++)
    {
        if ( 
    Close[10] >= Close[a] ) { Rank1nummer++;   }
      

    So when Close[10] is the lowest of all closes then it gets rank 1. This works fine

    Now I want also to do this for Close[9]

    But when I change the code into this, the strategy won't be activated anymore in a chart.. What do I wrong?

    PHP Code:
    for (int a 1;   11 a++)
    {
        if ( 
    Close[10] >= Close[a] ) { Rank1nummer++;   }
        if ( 
    Close[9] >= Close[a] ) { Rank2nummer++;   }

    Thanks..

    #2
    Hello no111,
    I could run the strategy without any issues.

    Please make sure you have enabled the strategy.
    • Right click on the chart.
    • In the context menu click on Strategies...
    • In the Strategies dialog please set the field Enabled to true in the parameters box.


    Please let me know if I can assist you any further.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      I got this error in Log:

      Error on calling 'OnBarUpdate' method for strategy 'StrategyX/e586bf237f80403887b0b8acab647c75': Object reference not set to an instance of an object.

      With this code:

      PHP Code:
      protected override void Initialize()
              {
                  
      Rank1 = new DataSeries(thisMaximumBarsLookBack.Infinite);
                  
      CalculateOnBarClose true;
              }

              
      /// <summary>
              /// Called on each bar update event (incoming tick)
              /// </summary>
              
      protected override void OnBarUpdate()
              {if(
      CurrentBar 12) return;
              
      Rank1nummer 0;    
              
      Rank2nummer 0;    
              
      Rank3nummer 0;    
              
      for (
      int a 1;   11 a++)
      {
          if ( 
      Close[10] >= Close[a] ) { Rank1nummer++;   }
          if ( 
      Close[9] >= Close[a] ) { Rank2nummer++;   }
      }

              


              if ( 
      Rank1nummer == 1
              { 
      Rank1.Set(Close[10]); 

              }
                 if ( 
      Rank2nummer == 2
              { 
      Rank2.Set(Close[9]); 
                  
                   
              }
              
                  
              } 
      The problem is, when I select True (for enabling) and press apply/ok it will not activate..

      Comment


        #4
        Found the problem...........
        I forgot.. Rank2 = new DataSeries(this, MaximumBarsLookBack.Infinite);

        thanks for support!

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by andrewtrades, Today, 04:57 PM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by chbruno, Today, 04:10 PM
        0 responses
        6 views
        0 likes
        Last Post chbruno
        by chbruno
         
        Started by josh18955, 03-25-2023, 11:16 AM
        6 responses
        436 views
        0 likes
        Last Post Delerium  
        Started by FAQtrader, Today, 03:35 PM
        0 responses
        9 views
        0 likes
        Last Post FAQtrader  
        Started by rocketman7, Today, 09:41 AM
        5 responses
        20 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X