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 FrancisMorro, Today, 03:24 AM
            0 responses
            1 view
            0 likes
            Last Post FrancisMorro  
            Started by Segwin, 05-07-2018, 02:15 PM
            10 responses
            1,769 views
            0 likes
            Last Post Leafcutter  
            Started by Rapine Heihei, 04-23-2024, 07:51 PM
            2 responses
            30 views
            0 likes
            Last Post Max238
            by Max238
             
            Started by Shansen, 08-30-2019, 10:18 PM
            24 responses
            943 views
            0 likes
            Last Post spwizard  
            Started by Max238, Today, 01:28 AM
            0 responses
            10 views
            0 likes
            Last Post Max238
            by Max238
             
            Working...
            X