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

Trailing stop utilizing currency rather than ticks

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

    Trailing stop utilizing currency rather than ticks

    I would like an automated trailing stop that with an ATM profit target of $100 and a loss target of $100 would trail with the following conditions. 1) if profit = $20 then stop loss = $80. If profit reaches $40 stop loss = 0 or break even. If profit = 80 stop loss = $70 profit. Is this possible? Thanls in advance for any advice.

    #2
    Hello TheDailyBenjamins,

    Yes, this would be possible.

    Code:
    if (/* entry conditions here */)
    {
        SetStopLoss(CalculationMode.Currency, 100); // the stop loss needs to be set before the entry is submitted to the initial distance
        EnterLong();
    }
    
    if (Position.MarketPosition != MarketPosition.Flat)
    {
        // storing this to a variable to shorten conditions
        double currentPnL = Position.GetUnrealizedProfitLoss(PerformanceUnit.Currency, Close[0]);
    
        // profit is equal to or greater than 20 and less than 40, set stop loss to $80
        if (currentPnL >= 20 && currentPnL < 40)
            SetStopLoss(CalculationMode.Currency, 80);
    
        // profit is equal to or greater than 40 and less than 80, set stop loss to breakeven
        if (currentPnL >= 40 && currentPnL < 80)
            SetStopLoss(CalculationMode.Price, Position.AveragePrice);​
    
        // profit is equal to or greater than 80, set stop loss to $70
        if (currentPnL >= 80)
            SetStopLoss(CalculationMode.Currency, 70);
    }



    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you for the response. Do you know anyone who would code this for me? I do not know anything about Ninja coding.

      Comment


        #4
        Hello TheDailyBenjamins,

        You can search our extensive library of NinjaScript consultants through the link below. Simply enter a consultant name or search by using our filter categories. Once you have identified your consultants of choice, please visit each consultant's site for more information or contact them directly to learn more!
        Programming Services - https://ninjatraderecosystem.com/sea...mming-services
        Educators - https://ninjatraderecosystem.com/sea...ures=education

        You can locate the contact information for the consultants on their direct websites for any additional questions you may have. Since these consultants are third party services for NinjaTrader all pricing and support information will need to be obtained through the consultant.

        This NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The companies and services listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.​


        Below I am also providing a link to a forum post with helpful resources on getting started with NinjaScript and C#.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by rbeckmann05, Yesterday, 06:48 PM
        1 response
        12 views
        0 likes
        Last Post bltdavid  
        Started by llanqui, Today, 03:53 AM
        0 responses
        6 views
        0 likes
        Last Post llanqui
        by llanqui
         
        Started by burtoninlondon, Today, 12:38 AM
        0 responses
        10 views
        0 likes
        Last Post burtoninlondon  
        Started by AaronKoRn, Yesterday, 09:49 PM
        0 responses
        15 views
        0 likes
        Last Post AaronKoRn  
        Started by carnitron, Yesterday, 08:42 PM
        0 responses
        11 views
        0 likes
        Last Post carnitron  
        Working...
        X