Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Assigning A Value To Swing Points to call in a strategy

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

    Assigning A Value To Swing Points to call in a strategy

    Hello all.

    I am looking for a simple swing indicator that returns a value that can be called in the strategy builder for the following swing conditions.

    HH: higher High (2)
    LH: lower high (1)
    LL: lower low (-1)
    HL: higher low (-2)


    Below is a visual of what I am talking about in the above table with values at each swing point.
    I do not need the actual value to print on the chart itself.
    The only purpose is to pull that value when creating a strategy.







    At any given time, whichever of the 4 above conditions exist as the last printed swing condition, I would like a value assigned until the next swing condition prints on the chart. So for example, if we printed a new Higher High condition on the chart, a value of 2 would be the result for all future bars, until the condition was changed upon the next swing. I need to call a value like this for a strategy I have in mind. I hope this makes sense, and that you can point me in the right direction. Thanks in advance if anyone can help out.

    #2
    Hello BullyWig Trader,

    Below is a link to a support article with helpful resources on getting started with C# and NinjaScript.



    "I am looking for a simple swing indicator that returns a value that can be called in the strategy builder for the following swing conditions."

    The Desktop SDK documentation provides sample code of calling the Swing() indicator.
    Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.


    For an indicator to be usable in the Strategy Builder, a plot must be added with AddPlot(), the plot series must be returned in the getter of a public Series<double> (using the XmlIgnore attribute), and the value you are sending to the host would be assigned to the plot series Value[0] / Values[plot series index][0].

    The support article below provides sample code.



    "I do not need the actual value to print on the chart itself."

    Prints to the NinjaScript output window are helpful for debugging when developing your custom indicator. We do recommend you use these during the building process, and then remove them once you are certain the code is working the way you intend.

    Below is a link to a support article on adding debugging prints to understand behavior.



    "At any given time, whichever of the 4 above conditions exist as the last printed swing condition, I would like a value assigned until the next swing condition prints on the chart. So for example, if we printed a new Higher High condition on the chart, a value of 2 would be the result for all future bars, until the condition was changed upon the next swing."

    On each new bar start by assigning the current bar's plot series value to the previous bar's value to carry the value forward.
    Then your custom condition can update the value when necessary.

    if (CurrentBar < 1)
    return;

    // assign the previous bar value MyPlotSeries[1] to the current MyPlotSeries[0]
    Value[0] = Value[1];

    if (/* your custom conditions here*)
    {
    Value[0] = 1; // assign your value here. for example a 1 could mean the conditions are true and a 0 could mean the conditions are false
    }


    ​​​​​​​You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    558 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    324 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
    545 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