Announcement

Collapse
No announcement yet.

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;   a < 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;   a < 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(this, MaximumBarsLookBack.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;   a < 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 Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        574 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        332 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        553 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        551 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X