Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

The difference between these two expression

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

    The difference between these two expression

    In practicing coding, I happened to use some code like this:

    Code:
                 protected override void OnBarUpdate()
                 {
                  int  flip, previous_flip;
     
                  if (Input[0]>SMA(10)[0])   flip=1;
                  if (Input[0]<SMA(10)[0])   flip=-1;
    
                  if (flip==1&& previous_flip!=flip)  EnterLong();
               
                  previous_flip=flip; 
                 }
    but the above code does not seem to function properly, and triggers a buy signal on every bar when the flip happens, while I change the code to the following expression, then it operates quite well

    Code:
                 protected override void OnBarUpdate()
                {
                  int  flip, previous_flip;
     
                  if (Input[0]>SMA(10)[0])   flip=1;
                  if (Input[0]<SMA(10)[0])   flip=-1;
    
                  if (flip==1)
                     { 
                            if (previous_flip!=flip)  EnterLong();
                     }
               
                  previous_flip=flip; 
                 }
    the logic between the two seems to be the same, why the former one is wrong ?

    #2
    Hello,

    Thanks for the forum post.

    I reviewed the code and came to the same conclusion as you did, I would expect both code snips to run largely the same.

    At this point I suspect some other change may have caused the difference.

    In either regaurd what I would hve to do is add in Print() statements to me code to understand what is an is not running and what the variables states are so that I could figure out what is going on.

    Please use this information below to help you with doing this.



    I would also add in TraceOrders so you can understand what is going on here as well.



    Let me know if you need further assistance once this is added in.
    BrettNinjaTrader Product Management

    Comment


      #3
      Thank you Brett, I would try it.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      630 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      364 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      105 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      566 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      568 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X