Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Swing stops being placed too far

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

    Swing stops being placed too far



    They are appearing way to far away and the stops arent trailing, not sure whats going on my code looks good

    // Swing Stops

    if(Position.MarketPosition == MarketPosition.Long)
    {
    SetStopLoss(CalculationMode.Ticks, Swing(5).SwingLow[0] - 3 * TickSize);
    }

    if(Position.MarketPosition == MarketPosition.Short)
    {
    SetStopLoss(CalculationMode.Ticks, Swing(5).SwingHigh[0] + 3 * TickSize);
    }

    //Breakeven at 10 ticks then plus 2 ticks

    if (Position.MarketPosition == MarketPosition.Long
    && Close[0] >= Position.AvgPrice + 9 * TickSize)

    {
    SetStopLoss(Position.AvgPrice + 2 * TickSize);
    }

    if (Position.MarketPosition == MarketPosition.Short
    && Close[0] < Position.AvgPrice - 9 * TickSize)
    {
    SetStopLoss(Position.AvgPrice - 2 * TickSize);
    }

    //Trail behind Adaptive Moving Average by 2 ticks, after 12 ticks

    if (Position.MarketPosition == MarketPosition.Long
    && Close[0] > Position.AvgPrice + 12 * TickSize)
    {
    SetStopLoss(CalculationMode.Ticks, KAMA(2, 10, 30)[0] - 2 * TickSize);
    }

    if (Position.MarketPosition == MarketPosition.Short
    && Close[0] < Position.AvgPrice - 12 * TickSize)
    {
    SetStopLoss(CalculationMode.Ticks, KAMA(2, 10, 30)[0] + 2 * TickSize);
    }

    #2
    Hello brucelevy,

    If you are going to placing the stop at a specific price, then use CalculationMode.Price and do not use CalculationMode.Ticks.

    You are setting the stop thousands of ticks below the entry.

    SetStopLoss(CalculationMode.Price, Swing(5).SwingLow[0] - 3 * TickSize);


    Also, for a trail to work you have to know the current price that the stop is set to. Attached is an example that demonstrates.
    Attached Files
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      How would it be adapted for swings instead of fixed stops and trailing on an indicator rather than by a fixed amount

      Comment


        #4
        Hello brucelevy,

        In the example I posted, this moves the stop by calling it with a new price.

        For this you would supply the new swing price calculation. Each time you call SetStopLoss this moves the stop loss to the new price.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Ok, I will try to figure it out.

          What if price is declining and the system buys but tries to put stops below the previous swing low, which in a declining market would be higher than the current swing low and higher than the buy entry point. This is causing me to have errors which disable the strategy. Are there any threads explaining this, has anyone published a robust swing stop system thread

          Comment


            #6
            Hello brucelevy,

            I am not aware of an existing strategy based on the swing indicator.

            When placing a sell stop, check the current bid price. If the price you are going to use is greater than the bid price do not allow this price to be used.

            double myPrice;

            if (myPrice <= GetCurrentBid())
            {
            SetStopLoss(CalculationMode.Price, myPrice);
            }
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by proptrade13, Today, 11:06 AM
            1 response
            5 views
            0 likes
            Last Post NinjaTrader_Clayton  
            Started by quantismo, 04-17-2024, 05:13 PM
            4 responses
            30 views
            0 likes
            Last Post quantismo  
            Started by love2code2trade, 04-17-2024, 01:45 PM
            4 responses
            32 views
            0 likes
            Last Post love2code2trade  
            Started by cls71, Today, 04:45 AM
            2 responses
            10 views
            0 likes
            Last Post eDanny
            by eDanny
             
            Started by kulwinder73, Today, 10:31 AM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_Erick  
            Working...
            X