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

Help with finding update of swing

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

    Help with finding update of swing

    Hello to all!
    Having next trouble:
    I want to have only one enter from current Swing indicator. Only once when my condition is accepted. And if it will be accepted on this Swing again - I need to do nothing and skip it. How can I do this?
    F.e. I have next code:
    swLow = price of the current Low Swing

    Code:
    if(trendup == true)
                    {
                        currentLow = Low[0];
                        enterLongPrice = swLow;
                      
                        if(currentLow < enterLongPrice && hadEnterFromThisLong == false)
                        {           
                                priceInLongD = true;
                        }
                        if(priceInLongD == true && currentLow > enterLongPrice)
                        {
                            orderLong = EnterLongLimit(enterLongPrice, "Long Limit Order");
    
                            hadEnterFromThisLong = true;
                        }
    What I need to add? And it doesn't matter will I have enter or not - I need to use the condition of currentLow < enterLongPrice only once. And I need to wait only when the next Swing will be plot, and only then I want to repeat this code.
    Please, help!
    Thanks!

    #2
    Hello YevhenShynkarenko,

    Thank you for your inquiry.

    I would suggest comparing the current swing value to the previous swing value. If there is a change, the new swing value should be different. If it's the same, there wasn't a change. So, here's a quick example to do this. Please note that this is only an example. You'll need to change any variables as needed:
    Code:
    private double prevLowSwing = 0;
    private double currentLowSwing = 0;
    
    public override void OnBarUpdate()
    {
         if (prevLowSwing == 0)
              prevLowSwing = Swing(5).SwingLow[0];
    
         currentLowSwing = Swing(5).SwingLow[0];
    
         if (currentLowSwing > prevLowSwing || currentLowSwing < prevLowSwing) // check if there is any change
         {
              // do stuff
              prevLowSwing = Swing(5).SwingLow[0]; // set prevLowSwing to the new swing value as the value has changed
         }
    }
    Please, let us know if we may be of further assistance.
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ZacharyG View Post
      Hello YevhenShynkarenko,

      Thank you for your inquiry.

      I would suggest comparing the current swing value to the previous swing value. If there is a change, the new swing value should be different. If it's the same, there wasn't a change. So, here's a quick example to do this. Please note that this is only an example. You'll need to change any variables as needed:
      Code:
      private double prevLowSwing = 0;
      private double currentLowSwing = 0;
      
      public override void OnBarUpdate()
      {
           if (prevLowSwing == 0)
                prevLowSwing = Swing(5).SwingLow[0];
      
           currentLowSwing = Swing(5).SwingLow[0];
      
           if (currentLowSwing > prevLowSwing || currentLowSwing < prevLowSwing) // check if there is any change
           {
                // do stuff
                prevLowSwing = Swing(5).SwingLow[0]; // set prevLowSwing to the new swing value as the value has changed
           }
      }
      Please, let us know if we may be of further assistance.
      Very big thanks for you! Working as I want!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by wzgy0920, 04-20-2024, 06:09 PM
      2 responses
      26 views
      0 likes
      Last Post wzgy0920  
      Started by wzgy0920, 02-22-2024, 01:11 AM
      5 responses
      32 views
      0 likes
      Last Post wzgy0920  
      Started by wzgy0920, Yesterday, 09:53 PM
      2 responses
      49 views
      0 likes
      Last Post wzgy0920  
      Started by Kensonprib, 04-28-2021, 10:11 AM
      5 responses
      191 views
      0 likes
      Last Post Hasadafa  
      Started by GussJ, 03-04-2020, 03:11 PM
      11 responses
      3,230 views
      0 likes
      Last Post xiinteractive  
      Working...
      X