Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Attaching a StopLoss to the Swing indicator in strategy builder

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

    Attaching a StopLoss to the Swing indicator in strategy builder

    I am building a strategy and I am trying to incorporate the Swing indicator to set a trailing style stop loss, but I can't seem to get it figured out. I am using the Wizard as I have no coding experience, but I have also made a separate one using the NinjaScript Editor trying to resolve my issue. I'll input the code from the wizard, I have removed the other indicators i have added to try and cut back on the reading. Thank you for any help.


    {
    private double StopPrice;


    private CDSwing CDSwing1;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    StopPrice = 1;
    }
    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Tick, 1);
    }
    else if (State == State.DataLoaded)
    {
    ATR1 = ATR(Close, 14);
    EMA1 = EMA(Close, 10);
    CDSwing1 = CDSwing(Close, 5);
    SetProfitTarget("", CalculationMode.Currency, 800);
    }
    }

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 1)
    return;


    // Set 2
    if (Position.MarketPosition == MarketPosition.Long)
    {
    StopPrice = CDSwing1.SwingLow[0];
    ExitLongStopMarket(Convert.ToInt32(DefaultQuantity ), StopPrice, "", "");
    }

    // Set 3
    if (Position.MarketPosition == MarketPosition.Short)
    {
    StopPrice = CDSwing1.SwingHigh[1];
    ExitShortStopMarket(Convert.ToInt32(DefaultQuantit y), StopPrice, "", "");
    }


    }


Latest Posts

Collapse

Topics Statistics Last Post
Started by Mindset, 04-21-2026, 06:46 AM
0 responses
91 views
0 likes
Last Post Mindset
by Mindset
 
Started by M4ndoo, 04-20-2026, 05:21 PM
0 responses
137 views
0 likes
Last Post M4ndoo
by M4ndoo
 
Started by M4ndoo, 04-19-2026, 05:54 PM
0 responses
68 views
0 likes
Last Post M4ndoo
by M4ndoo
 
Started by cmoran13, 04-16-2026, 01:02 PM
0 responses
121 views
0 likes
Last Post cmoran13  
Started by PaulMohn, 04-10-2026, 11:11 AM
0 responses
72 views
0 likes
Last Post PaulMohn  
Working...
X