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 argusthome, 03-08-2026, 10:06 AM
    0 responses
    65 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    41 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    23 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    26 views
    0 likes
    Last Post TheRealMorford  
    Started by Mindset, 02-28-2026, 06:16 AM
    0 responses
    52 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X