Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.

    Comment


      #3
      Thank you Brett, I would try it.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by zstheorist, Today, 07:52 PM
      0 responses
      3 views
      0 likes
      Last Post zstheorist  
      Started by pmachiraju, 11-01-2023, 04:46 AM
      8 responses
      149 views
      0 likes
      Last Post rehmans
      by rehmans
       
      Started by mattbsea, Today, 05:44 PM
      0 responses
      5 views
      0 likes
      Last Post mattbsea  
      Started by RideMe, 04-07-2024, 04:54 PM
      6 responses
      33 views
      0 likes
      Last Post RideMe
      by RideMe
       
      Started by tkaboris, Today, 05:13 PM
      0 responses
      5 views
      0 likes
      Last Post tkaboris  
      Working...
      X