Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

"Swing" indicator script logic

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

    "Swing" indicator script logic

    Hello

    I'm trying to modify the "swing" indicator, but first I'm trying to make sense of the script's logic. For the most part I already understand how the code works, but on line 93 there is an if statement:
    if (BarsArray[0].BarsType.IsRemoveLastBarSupported && CurrentBar < saveCurrentBar)

    I don't understand in which scenario is this if statement true or false and what is the purpose of this if statement?
    Please explain what is "BarsArray[0].BarsType.IsRemoveLastBarSupported" checking for and how can "CurrentBar < saveCurrentBar" be true at all? Since current bar starts counting from 0 and only goes higher and in the beginning saveCurrentBar is -1 and it's value only changes on lines 109 and 212 when its set equal to CurrentBar. There doesn't seem to be any logical scenario where CurrentBar can be lower than saveCurrentBar.


    #2
    Hi Karl, thanks for posting.

    This section is to handle bars types with IsRemoveLastBarSupported, like the Renko bar when it runs OnEachTick. If the current bar is removed it would be less than the saved bar. You can make a copy of the Swing indicator by right clicking the code>Save As, then give it a unique name. This copy can be edited and tested by adding Print() methods throughout.

    Kind regards,
    -ChrisL

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, Yesterday, 09:41 PM
    1 response
    20 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, Today, 02:41 AM
    0 responses
    7 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, Yesterday, 11:44 PM
    0 responses
    18 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    35 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    33 views
    0 likes
    Last Post CarlTrading  
    Working...
    X