Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Swing comparison not working?

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

    #16
    Well, things are working now, but I have no idea why and would like to know why, because I was doing this for 5 hours yesterday and it didn't work.

    This morning it did. **shrugs helplessly**

    So first, if you mean the line:

    if (CurrentBars[0] < 50)
    return;​

    I originally changed all my Swing statements to Swing(2).SwingLowBar(0, 2, 30), but that didn't fix things.

    So this morning I implemented your code for the printout (THANK YOU, HUGE HELP! Watching Strategy 401 didn't help much) and then modified it to:

    protected override void OnBarUpdate()
    {

    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 70)

    return;

    Print(string.Format("{0} | CurrentBar: {1} > Swing(2).SwingLowBar(0, 2, 50): {0}", Time[0], CurrentBar, Swing(2).SwingLowBar(0, 2, 50) ));

    if (CurrentBar > Swing(2).SwingLowBar(0, 2, 50) && Swing(2).SwingLowBar(0, 2, 50) >= 0)
    {
    Print(string.Format("{0} | Condition true | Swing(2).SwingLowBar(0, 1, 50): {1}, Low[{1}]: {2}", Time[0], Swing(2).SwingLowBar(0, 1, 50), Low[Swing(2).SwingLowBar(0, 1, 50)]));
    Print(string.Format("{0} | Condition true | Swing(2).SwingLowBar(0, 2, 50): {1}, Low[{1}]: {2}", Time[0], Swing(2).SwingLowBar(0, 2, 50), Low[Swing(2).SwingLowBar(0, 2, 50)]));
    Print(string.Format("{0} | Condition true | Swing(2).SwingHighBar(0, 1, 50): {1}, High[{1}]: {2}", Time[0], Swing(2).SwingHighBar(0, 1, 50), High[Swing(2).SwingHighBar(0, 1, 50)]));
    Print(string.Format("{0} | Condition true | Swing(2).SwingHighBar(0, 2, 50): {1}, High[{1}]: {2}", Time[0], Swing(2).SwingHighBar(0, 2, 50), High[Swing(2).SwingHighBar(0, 2, 50)]));

    }​

    Now it works for some insane reason?

    I am glad, but I cannot understand why reducing all Swing() calls to 30 period didn't fix it. Perhaps I overlooked something, I've gone through 11 versions or so trying different things, but it only take one problem.

    You have no idea how important this was to me. THANK YOU THANK YOU!!

    I know smatterings of 6 different computer languages, and was doing system automations with MATLAB for 3.5 years, but it is really hard to debug anything unfamiliar if it won't even run.

    I've saved everything as a .TXT document and will export the strategy for safekeeping, and now I can trying out different commands. Good error messages really matter, and this OnBarUpdate() really doesn't explain stuff.

    I did notice it had been plaguing people since NinjaTrader 7... I did try to search the forums for answers before I posted here. So thank you again, Chelsea!

    Comment


      #17
      Hello Mistoffelees,

      CurrentBar must be greater than the largest barsAgo index.

      If Swing(2).SwingLowBar(0, 2, 50) is the index, then CurrentBar needs to be greater than this.

      if (CurrentBar > Swing(2).SwingLowBar(0, 2, 50) && Swing(2).SwingLowBar(0, 2, 50) >= 0)

      This ensures that CurrentBar is greater than the SwingLowBar barsAgo index.

      I am not suggesting that you hard code 70 or any other number as the number of bars CurrentBar needs to be greater than.
      I am suggesting that you ensure CurrentBar is greater than the index.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #18
        I appreciate it, seems to be working now!

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        23 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        120 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        63 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        41 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        45 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X