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 NullPointStrategies, Today, 05:17 AM
0 responses
50 views
0 likes
Last Post NullPointStrategies  
Started by argusthome, 03-08-2026, 10:06 AM
0 responses
127 views
0 likes
Last Post argusthome  
Started by NabilKhattabi, 03-06-2026, 11:18 AM
0 responses
69 views
0 likes
Last Post NabilKhattabi  
Started by Deep42, 03-06-2026, 12:28 AM
0 responses
42 views
0 likes
Last Post Deep42
by Deep42
 
Started by TheRealMorford, 03-05-2026, 06:15 PM
0 responses
46 views
0 likes
Last Post TheRealMorford  
Working...
X