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

Modifying Trailing Stop

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

    Modifying Trailing Stop

    I have would like to know how to implement the latter, which was for a stop loss for trailing stop. The caveat is that I want to keep my use input and just divide my "TrailingStop" by two or whatever. My issue is how to divide it by two? Once and if "Trailing Stop" can be divide will the following work?

    // Resets the trailing stop to the original value when all positions are closed
    if (Position.MarketPosition == MarketPosition.Flat)
    {
    SetTrailStop(CalculationMode.Ticks, TrailingStop);
    }

    // If a long position is open, allow for trailing stop modification
    else if (Position.MarketPosition == MarketPosition.Long)

    // Once the price is greater than entry price+50 ticks, set trailing stop to half of use input
    Close[0] > Position.AvgPrice + 50 * TickSize)
    {
    SetTrailStop(CalculationMode.Price, TrailingStop/2);
    }

    #2
    Originally posted by Hammerhorn View Post
    I have would like to know how to implement the latter, which was for a stop loss for trailing stop. The caveat is that I want to keep my use input and just divide my "TrailingStop" by two or whatever. My issue is how to divide it by two? Once and if "Trailing Stop" can be divide will the following work?

    // Resets the trailing stop to the original value when all positions are closed
    if (Position.MarketPosition == MarketPosition.Flat)
    {
    SetTrailStop(CalculationMode.Ticks, TrailingStop);
    }

    // If a long position is open, allow for trailing stop modification
    else if (Position.MarketPosition == MarketPosition.Long)

    // Once the price is greater than entry price+50 ticks, set trailing stop to half of use input
    Close[0] > Position.AvgPrice + 50 * TickSize)
    {
    SetTrailStop(CalculationMode.Price, TrailingStop/2);
    }
    If you are specifying the TrailingStop variable in ticks, then your price calculation is not valid. Correct would be:
    Code:
     
    double StopPrice = Close[0] - TickSize * TrailingStop/2;
    SetTrailStop(CalculationMode.Price, StopPrice);
    Of course, you can concatenate that into one line.

    Comment


      #3
      It should be ticks, sorry. Does that make a difference in your example? I don't see the English in your assistance. Can you break it down for me?
      Last edited by Hammerhorn; 05-03-2013, 11:11 PM.

      Comment


        #4
        Originally posted by Hammerhorn View Post
        It should be ticks, sorry. Does that make a difference in your example? I don't see the English in your assistance. Can you break it down for me?
        I am not sure that I understand your query. My answer assumed that TrailingStop is in ticks, so that is still the answer.

        All it does it to calculate the correct stop price (in the first line), then use that value in the SetTrailStop() method in the next line.

        That having been said, I find that using CalculationMode.Price with SetTrailStop() to be dodgy, so I would just use CalculationMode.Ticks straight out where you have used CalculationMode.Price, thus:
        Code:
        // Once the price is greater than entry price+50 ticks, set trailing stop to half of use input
        Close[0] > Position.AvgPrice + 50 * TickSize)
        {
        SetTrailStop(CalculationMode.[B]Ticks[/B], TrailingStop/2);
        }
        Last edited by koganam; 05-04-2013, 08:17 AM.

        Comment


          #5
          Thanks, sorry for the confusion, I guess I should not reply when it late and I got a baby in my arms.

          Actually, tried inputting,
          // Once the price is greater than entry price+50 ticks, set trailing stop to half of use input Close[0] > Position.AvgPrice + 50 * TickSize) { SetTrailStop(CalculationMode.Ticks, TrailingStop/2); }
          and I get nothing but errors.
          Last edited by Hammerhorn; 05-04-2013, 02:32 PM.

          Comment


            #6
            Hello Hammerhorn,

            Thank you for your post.

            What errors are you receiving? Can you detail the errors in your response or provide a screenshot of these errors?

            I look forward to your response.

            Comment


              #7
              As it is coming back to me I sometimes surprise myself. I added "If" and it fixed it. Tested and works beautiful, thank you again for your assistance and patience.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by StockTrader88, 03-06-2021, 08:58 AM
              45 responses
              3,991 views
              3 likes
              Last Post johntraderuser2  
              Started by TAJTrades, Today, 09:46 AM
              0 responses
              7 views
              0 likes
              Last Post TAJTrades  
              Started by rhyminkevin, Yesterday, 04:58 PM
              5 responses
              62 views
              0 likes
              Last Post dp8282
              by dp8282
               
              Started by realblubb, Today, 09:28 AM
              0 responses
              8 views
              0 likes
              Last Post realblubb  
              Started by AaronKoRn, Yesterday, 09:49 PM
              1 response
              19 views
              0 likes
              Last Post Rikazkhan007  
              Working...
              X