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 rajendrasubedi2023, Today, 09:50 AM
      0 responses
      6 views
      0 likes
      Last Post rajendrasubedi2023  
      Started by ender_wiggum, Today, 09:50 AM
      0 responses
      2 views
      0 likes
      Last Post ender_wiggum  
      Started by bmartz, Today, 09:30 AM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_Erick  
      Started by geddyisodin, Today, 05:20 AM
      3 responses
      23 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by lorem, Today, 09:18 AM
      1 response
      5 views
      0 likes
      Last Post lorem
      by lorem
       
      Working...
      X