Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Iteration failure

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

    Iteration failure

    I have the code below and I expected at the beginning of each bar to have " i " increasing by 1, but it is always 0. What am I doing wrong here?
    Thank you

    Code:
    protected override void OnStateChange()
            {
                ....
    
                else if (State == State.Configure)                
                {
                    AddDataSeries(Data.BarsPeriodType.Tick, 1);
                    AddDataSeries(Data.BarsPeriodType.Minute, 5);               
                }    
    protected override void OnBarUpdate()
            {  
    if (BarsInProgress == 2)
                {
    i                       =  0;
    if (IsFirstTickOfBar)
                    {            // Finding Price swings High and Low                    
                                if (Highs[2][i+1] < Highs[2][i+2] && Highs[2][i+2] > Highs[2][i+3] && Math.Abs(Highs[2][i+1] - Highs[2][i+2]) > TickSize && Math.Abs(Highs[2][i+2] - Highs[2][i+3]) > TickSize) 
                                {
                                    HSwPrice[i] = Highs[2][i+2];
                                    HSwPriceBar = CurrentBar - 2;
                                    HSwPriceSeriesBar = i;
                                 }
    ......................
                      }
    i++;
                    }

    #2
    Hi itrader46, thanks for your note.

    It looks like your setting i = 0 on every OnBarUpdate call. Right below BarsInProgress == 2 there is i = 0;

    Set up int i; on the class level to create a class member then increment it in OnBarUpdate. e.g.

    public class MyCustomStrategy4 : Strategy
    {
    int i = 0;
    ...
    OnBarUpdate()
    {
    i++;
    }

    Best regards,

    -ChrisL

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    66 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    141 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    75 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    46 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    51 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X