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 stops in umanaged framework

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

    trailing stops in umanaged framework

    Hello. I'm working in unmanaged framework where I have multiple trades on the same instrument, for which each has it's own stop/ profit target. I've got it working so I can put in static stops/ targets associated with each trade, but I'm having trouble figuring out how I might set up trailing stops for each of those. Essentially, I might have 6 separate stops out, and the price of each would need to be updated (by same amount) following every bar update. Have you guys encountered any examples of this? I could imagine just cycling through all the stops and making the adjustment, but some might have already been filled, etc

    Thanks

    #2
    Hello stewarco,

    Thank you for your note.

    I put together a sample for the unmanaged approach which will submit a buy order, then a stop which is assigned to an order object and that order object is added to a list of type Order. Then on each bar update, this list is looped to check that the order is a stop market order and above the price which would trigger a change order call for that stop.

    With your additional stop orders, you’d just add them to this list and have each changed as needed.

    Please see attached.
    Attached Files
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      thanks this is helpful

      Comment


        #4
        possibly relate question

        Hi. This methodology works great. However, I'm having a new problem which may or may not be related. When I try to run a playback simulation, I'm getting the error about "Strategy has been disabled because it attempted to modify a historical order that has transitioned to a live order." I currently have the standard language:

        else if (State == State.Realtime)
        {
        // one time only, as we transition from historical
        // convert any old historical order object references
        // to the new live order submitted to the real-time account
        if (entryOrder != null)
        entryOrder = GetRealtimeOrder(entryOrder);
        if (stopOrder != null)
        stopOrder = GetRealtimeOrder(stopOrder);
        if (targetOrder != null)
        targetOrder = GetRealtimeOrder(targetOrder);
        }

        However, each stopOrder is going into stopList for updating the trailing levels. So do I need to update the code above to cycle through the entire list of outstanding stops? Or is the issue completely unrelated?
        Thanks

        Comment


          #5
          Hello stewarco,

          The sample I provided only should run in real time so this looks unrelated.

          For the issue with attempting to modify a historical order that has transitioned to a live order, please see the following link discussing how to resolve this.


          Please let us know if you need further assistance.
          Alan P.NinjaTrader Customer Service

          Comment


            #6
            follow up

            Hey Alan. I reviewed the section you provided, and included language as referenced below but I'm still having that issue. I guess I'm not entirely clear on the historical to realtime transition, but are you saying if I have multiple stop and target orders outstanding when I transition to realtime they'd still be picked up by

            else if (State == State.Realtime)
            {
            // one time only, as we transition from historical
            // convert any old historical order object references
            // to the new live order submitted to the real-time account
            if (entryOrder != null)
            entryOrder = GetRealtimeOrder(entryOrder);
            if (stopOrder != null)
            stopOrder = GetRealtimeOrder(stopOrder);
            if (targetOrder != null)
            targetOrder = GetRealtimeOrder(targetOrder);
            }

            Thanks

            Comment


              #7
              Hello stewarco,

              I would expect that code to have issues with multiple stops and profit targets.

              Have you attempted to assign each target and stop its own unique order object?

              I look forward to your reply.
              Alan P.NinjaTrader Customer Service

              Comment


                #8
                hi

                Hey alan. Any chance you or somebody can give me a call and I can try to walk you through what I have so far?

                Comment


                  #9
                  Hello stewarco,

                  Could you please send an email to platformsupport[at]ninjatrader[dot]com with Attn: Alan P in the Subject line. Also within the email please include a link to this thread.

                  I look forward to your email.
                  Alan P.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by xiinteractive, 04-09-2024, 08:08 AM
                  3 responses
                  11 views
                  0 likes
                  Last Post NinjaTrader_Erick  
                  Started by Johnny Santiago, 10-11-2019, 09:21 AM
                  95 responses
                  6,193 views
                  0 likes
                  Last Post xiinteractive  
                  Started by Irukandji, Today, 09:34 AM
                  1 response
                  3 views
                  0 likes
                  Last Post NinjaTrader_Clayton  
                  Started by RubenCazorla, Today, 09:07 AM
                  1 response
                  6 views
                  0 likes
                  Last Post RubenCazorla  
                  Started by TraderBCL, Today, 04:38 AM
                  3 responses
                  26 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Working...
                  X