Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Refer swings

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

    Refer swings

    hello

    i'm triing to build a strategy were i need to refer some swings highs and lows afer and before crose a level

    I want to make a list of swings higs and lows and then refer to them,

    for example choose the last swing before the 4724 level and the second low after this level and draw a fibonachi.



    till now i did it using the funtion


    if (CrossBelow(Close, K1, 1))
    {
    startbar = CurrentBar;

    }

    an then

    FirstHigh = Swing1.SwingHigh[(CurrentBar - startbar + 2)];

    its working well un 5 min chart but some times give me an error in ticks chart

    Error on calling 'OnBarUpdate' method on bar 959:


    so i thougt it can be easier to do doing referrences from a list of swings


    thanks for your help and your time
    Attached Files

    #2
    Hello ernest93,

    Thank you for the post.

    The error you are getting is that an index was used that was not valid at that time. That likely relates to the SwingHigh[(CurrentBar - startbar + 2)];

    I would suggest using a Print to see what the value of (CurrentBar - startbar + 2) is at the time of the error. Depending on what that value is would help to determine what needs to change. You very likely need to add some error checking to make sure the index you made is valid and not greater than the Count of the series.

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      Hello ernest93,

      Thank you for the post.

      The error you are getting is that an index was used that was not valid at that time. That likely relates to the SwingHigh[(CurrentBar - startbar + 2)];

      I would suggest using a Print to see what the value of (CurrentBar - startbar + 2) is at the time of the error. Depending on what that value is would help to determine what needs to change. You very likely need to add some error checking to make sure the index you made is valid and not greater than the Count of the series.
      thank you

      I found the error thanks to your advice,

      the error is that the strategy never stops calculating new minima and maxima until it gives error,

      is there any way to make the strategy stop calculating from 2 swing low for example and not start calculating again unless the conditions to start are given again.

      for example the first step of my strategy is that the price breaks a level (until it does not break that level again the strategy does not start again).

      thanks again

      Comment


        #4
        Hello ernest93,

        You would likely need to use a variable for that purpose to know when to stop doing the action or condition. If you are using a loop you can use any C# means to break the loop like continue or break. The return keyword can also be used if at that point in the logic it should stop doing everything and return.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        56 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        132 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        73 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        45 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