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 DJ888, Today, 10:57 PM
      0 responses
      1 view
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by MacDad, 02-25-2024, 11:48 PM
      7 responses
      158 views
      0 likes
      Last Post loganjarosz123  
      Started by Belfortbucks, Today, 09:29 PM
      0 responses
      7 views
      0 likes
      Last Post Belfortbucks  
      Started by zstheorist, Today, 07:52 PM
      0 responses
      7 views
      0 likes
      Last Post zstheorist  
      Started by pmachiraju, 11-01-2023, 04:46 AM
      8 responses
      151 views
      0 likes
      Last Post rehmans
      by rehmans
       
      Working...
      X