Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Dynamic stop loss set above SMA on each new bar

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

    Dynamic stop loss set above SMA on each new bar

    I am working on a strategy that dynamically moves the stop loss for a short position to be 3 ticks above an SMA. I have looked through the forum and other documentation but I can't get it to submit the stop exit order. The strategy is entering the short order per my conditions and getting short but once the strategy is short the stop order is not being generated. I would also like the stop exit order to continue updating on each new bar to stay 3 ticks above the SMA. Any help would be greatly appreciated. Current code is listed below:


    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (condition for entry)
    {
    EnterShortStop(0, true, DefaultQuantity, //short price set here by indicator location//, "shortEntry");

    }


    //This was produced by wizard as a way to exit short position
    if (Position.MarketPosition == MarketPosition.Short)
    {
    ExitShortStop(SMA(14)[0] + 3 * TickSize, "shortExit", "shortEntry");
    }



    I also noticed I am getting the following error in the log:
    An Exit() method to submit an exit order at '6/15/2012 7:16:00 AM' has been ignored. Please search on the term 'Internal Order Handling Rules' in the Help Guide for detailed explanation.
    Last edited by jhowinvest; 06-16-2012, 06:41 PM.

    #2
    You're probably looking for SetStopLoss(), and I'm going to guess that the reason you're getting that error is because as soon as you open your position, your code is trying to exit that position.

    SetStopLoss(): http://www.ninjatrader.com/support/h...etstoploss.htm

    Comment


      #3
      Okay, I figured it out. I had a set profit target in the initialize section and I guess this was interfering. Once I removed that from the code my stop loss trailing 3 ticks from the SMA worked.

      Now I have another question....is it possible to set a profit target in ticks AND have the stop order trailing the SMA? If so what code needs to be added.

      Thanks to all.

      Comment


        #4
        Originally posted by jhowinvest View Post
        Now I have another question....is it possible to set a profit target in ticks AND have the stop order trailing the SMA? If so what code needs to be added.
        Yup, SetStopLoss and SetProfitTarget will do this. This will function like an OCO type thing.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        648 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        369 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        108 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        572 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        573 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X