Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Creating a function that skips inside bars

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

    Creating a function that skips inside bars

    Hey everybody,
    I am currently coding an indicator that plots the swing highs and lows on the chart. The logic for a swing low is that when a low is forming it has to have two higher-lows on both sides of the bar.
    What I am trying to do now is that I want to ignore any inside bars leading up to the swing low or after the forming swing low bar.

    In the picture below you can see the inside bars that I don't want to count after the swing low bar labeled SL.

    I currently have hard code the indexs to check for Swing lows:

    if(lookingForSL)
    {
    if(lookForSL())
    {
    Draw.Text(this, "SL" + CurrentBar, "SL", 2, Low[2] - 0.05);
    lookingForSH = true;
    lookingForSL= false;
    return;
    }
    }​

    private bool lookForSL()
    {
    return Low[1] > Low[2] &&
    Low[1] <= Low[0] &&
    Low[0] > Low[2] &&
    Low[3] > Low[2] &&
    Low[4] > Low[2];
    }

    Low[2] is the swing low on the chart​
    LookingForSL is a flag so that the loop resets and looks for a SH when a SL is found.

    I would be so greatful for any ideas :-)

    Cheers

    //Stefan

    #2
    The easy answer would be to just use the existing NinjaTrader Swing indicator. Test it using different "Strength" settings to see what works best for you.

    Here is a link to the NS part: https://ninjatrader.com/support/help...html?swing.htm

    Comment


      #3
      Hello Stefan,

      Thanks for your post.

      Tasker-182 is correct. The Swing indicator from NinjaTrader could be used and you could test the different 'Strength' settings to find what works best for your goals.

      For information about how to access the Swing indicator values in a custom NinjaScript, see the help guide linked by Tasker-182.

      You could view the Swing indicator's code in a NinjaScript Editor window by going to Control Center > New > NinjaScript Editor, opening the Indicators folder, and double-clicking on the Swing file.

      Let me know if I may assist further.
      <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

      Comment


        #4
        Thanks for the tips Tasker-182 and NinjaTrader_BrandonH

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by cmoran13, Yesterday, 01:02 PM
        0 responses
        25 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        17 views
        0 likes
        Last Post PaulMohn  
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        160 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        94 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        148 views
        2 likes
        Last Post CaptainJack  
        Working...
        X