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

Help with trailing stop in script

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

    Help with trailing stop in script

    Hello,

    I have a simple strategy with 1 position for all entries. I find that the trailing stop doesn't work some times in live sim. Appreciate any help.


    protected override void OnStateChange()
    {
    if (State == State.Configure)
    {
    SetTrailStop(CalculationMode.Ticks, 30);
    }
    }

    protected override void OnBarUpdate()
    {
    if (CurrentBars[0] < 1)
    return;

    if <Longcondition>
    {
    EnterLong(Convert.ToInt32(DefaultQuantity), @"GoLong ");
    }


    if <Shortcondition>
    {
    EnterShort(Convert.ToInt32(DefaultQuantity), @"GoShort");
    }
    }



    Basically, if a long or short condition is met, an order is placed with a trail stop. The order gets stopped either by a trailing stop or until opposite condition is met, in which case an order is placed in the opposite direction with a trailing again (whichever occurs first).

    This works perfectly fine in Strategy Analyzer.

    But, in live sim, I find that the trailing stop doesn't work for some orders and the trade goes on until opposite condition is met and trade gets placed in opposite direction. Any idea how I could resolve this?

    Thanks

    #2
    Hello hchandrashe,

    Thanks for your post.

    What datafeed are you connected to?

    What instruments have you observed this on?

    What Calculate mode are you using (OnBarClose, OnPriceChange, OnEachTick)?

    Have you observed any error messages (either pop-up or appearing in the "log" tab of the control center when this occurs)?

    Please send your log and trace files in and advise what dates the trail stop did not function when testing in live sim. Send the email to PlatformSupport[at]NinjaTrader[dot]Com. Mark the email Atten:Paul and include a link to this thread.

    Follow the steps below to manually attach your log and trace files to your e-mail so I may investigate this matter further.

    Open your NinjaTrader folder under My Documents.
    Right click on the 'log' and 'trace' folders and select Send To> Compressed (zipped) Folder.
    Send the 2 compressed folders as attachments to the email.
    Once complete, you can delete these compressed folders.
    Paul H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by frankthearm, Today, 09:08 AM
    5 responses
    14 views
    0 likes
    Last Post NinjaTrader_Clayton  
    Started by jeronymite, 04-12-2024, 04:26 PM
    3 responses
    43 views
    0 likes
    Last Post jeronymite  
    Started by yertle, Today, 08:38 AM
    5 responses
    15 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Started by adeelshahzad, Today, 03:54 AM
    3 responses
    19 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Started by bill2023, Yesterday, 08:51 AM
    6 responses
    27 views
    0 likes
    Last Post NinjaTrader_Erick  
    Working...
    X