Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Extract Swings High Value of Swing Indicator

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

    Extract Swings High Value of Swing Indicator

    Good morning, I am trying to use the Swing indicator to extract some data I need to create a strategy,

    Specifically from the series "swingHighSwings".

    Its content are all the high swings of all the candles, where there is no swing high the value is 0.

    Through a simple loop with a condition I have been able to remove the 0 values.

    Code:
    for(int i = 0; i < 100; i++)
    {
    if (swingHighSwings[i] != 0)
    {
    Print ("Swing High Swings Serie Without 0 value " + "["+i+"] "+swingHighSwings[i]);
    }
    }
    which displays this data:

    ...
    Swing High Swings Serie Without 0 value [4] 4455,25
    Swing High Swings Serie Without 0 value [11] 4454,5
    Swing High Swings Serie Without 0 value [14] 4454,5
    Swing High Swings Serie Without 0 value [22] 4456,25
    Swing High Swings Serie Without 0 value [25] 4455,75
    Swing High Swings Serie Without 0 value [28] 4455,5
    Swing High Swings Serie Without 0 value [30] 4455,5
    Swing High Swings Serie Without 0 value [32] 4455,25
    Swing High Swings Serie Without 0 value [34] 4455,5
    Swing High Swings Serie Without 0 value [38] 4456,5
    ...

    However I would like to extract only the swings with ascending value, for example from this list I would like to remove the
    swings that are lower than the previous one so that their content is this one:

    ...
    Swing High Swings Serie Without 0 value [4] 4455,25
    Swing High Swings Serie Without 0 value [22] 4456,25
    Swing High Swings Serie Without 0 value [38] 4456,5
    ...

    I don't want to sort them, just filter so that only the values I need appear and then put them in a list.


    Could someone give me an idea?

    I have tried to put conditions but I don't get the expected result.

    Thank you very much for your help

    Best regards

    #2
    Hello Mestor,

    The series you are using is not the exposed series of the swing indicator, that is used internally in that indicator. You can see how it is used by using the NinjaScript editor to view its code.

    To find swings using the swing indicator you can use its existing methods to do that:

    Code:
    Swing(int strength).SwingHighBar(int barsAgo, int instance, int lookBackPeriod)
    Swing(int strength).SwingLowBar(int barsAgo, int instance, int lookBackPeriod)
    You can use the instance parameter to get different swings without having to loop or do logic to find them.

    If you then wanted to collect X number of swings and order or prune them in some way you could do that. A C# List<double> would likely be the best way to maintain a collection of swings you are interested in, that also is a type you can use that lets you add or remove as many items as you need. Working with Lists is not something our support can go into detail on but you can search online for C# List<T> tutorials which there are many of.

    If you are instead trying to edit the swing to work differently I would not be able to advise on how to restructure the series. You would need to work out the logic changes to the existing indicator which creates the result you wanted.


    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    563 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    329 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    547 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    547 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X