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 futurenow, 12-06-2021, 05:49 PM
18 responses
879 views
0 likes
Last Post dj0ntz
by dj0ntz
 
Started by nailz420, 05-14-2025, 09:14 AM
1 response
117 views
0 likes
Last Post NinjaTrader_ChristopherJ  
Started by NinjaTrader_Brett, 05-12-2025, 03:19 PM
0 responses
525 views
1 like
Last Post NinjaTrader_Brett  
Started by domjabs, 05-12-2025, 01:55 PM
2 responses
84 views
0 likes
Last Post domjabs
by domjabs
 
Started by Morning Cup Of Trades, 05-12-2025, 11:50 AM
1 response
123 views
0 likes
Last Post NinjaTrader_ChristopherJ  
Working...
X