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 cmarkb, 05-08-2020, 09:42 AM
11 responses
732 views
0 likes
Last Post rafaelcoisa  
Started by reynoldsn, Today, 03:08 PM
1 response
3 views
0 likes
Last Post NinjaTrader_Jesse  
Started by RubenCazorla, 09-15-2022, 08:28 AM
4 responses
56 views
0 likes
Last Post NinjaTrader_Jesse  
Started by termitikicloud, 01-11-2025, 05:27 PM
12 responses
71 views
0 likes
Last Post termitikicloud  
Started by aligator, 05-05-2021, 09:20 AM
24 responses
1,561 views
1 like
Last Post djayz4u
by djayz4u
 
Working...
X