• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Detecting Stopped Trades

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

    Detecting Stopped Trades

    I have some code for what happens after I manually exit a trade, which I made my own closeLong/Short functions for, but when a trade gets stopped out, my code will not execute since it was not under my control.

    What's the best way to know a trade has been stopped? And is it possible to handle immediately afterward?

    #2
    Hello,

    Thank you for the post.

    I wanted to clarify, are you currently trying to use a NinjaScript strategy to control Manual trades? If so, this is not currently possible using the Strategy logic specifically.

    If you are instead using the Addon framework, could you provide details on the logic currently being used? If you are not using the addon framework currently, this is the only way to interact with manual orders correctly. You would need to subscribe to the accounts order events to be able to see manually placed orders. We have a sample of this concept here: https://ninjatrader.com/support/help...ount_class.htm

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Originally posted by gredenko View Post
      I have some code for what happens after I manually exit a trade, which I made my own closeLong/Short functions for, but when a trade gets stopped out, my code will not execute since it was not under my control.

      What's the best way to know a trade has been stopped? And is it possible to handle immediately afterward?
      Manage your own exits also?

      I use OnPositionUpdate to check for any position change. I do not manually exit as you do. I just adjust stops/targets as necessary and use OnPositionUpdate.

      This is on ES, and I'm not afraid of partial fills or anything. Stocks would be a little bit of a concern for partial fills.

      Comment


        #4
        Yes I"m only using NinjaScript for now.


        @sledge OnPositionUpdate sounds like exactly what I need. Thanks for that. I'm doing futures only by the way.

        Comment


          #5
          It seems that I am creating an infinite loop, doing something like what I summarized below.

          I was planning on using OnPositionUpdate() as follows.

          OnBarUpdate() {
          evaluate(); //function that holds all my other function calls.
          }

          onPositionUpdate() {
          evaluate();
          }

          evaluate() {
          //my trade logic for entries, enters longs and shorts inside here while also making other calls that tell me to exit trades manually or adjust profit/stops.
          }

          My strategy just runs forever until the program crashes, so I'm guessing I can't call a function like this through onPositionUpdate/onBarUpdate. If anyone knows a good workaround, I'd appreciate it. My original issue is that upon exiting a trade, when there's an entry signal on the same bar as the exit, my second trade does not enter. So I wanted to "evaluate" the market again immediately after exiting to see if that would help me catch the next trade. I am using OnEachTick as my Calculate value as well.

          What's wrong with doing this?

          Comment


            #6
            Do not call evaluate from OnPostionUpdate.

            Just use that to set variables to report back to the rest of your program that a Position changed=> Long? Short? Flat...

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Bionian, Today, 02:46 PM
            2 responses
            6 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by rwilliam, Today, 01:54 PM
            1 response
            9 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by franco12364, Today, 11:27 AM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_PaulH  
            Started by YevhenShynkarenko, Today, 11:48 AM
            4 responses
            25 views
            0 likes
            Last Post NinjaTrader_ChrisL  
            Started by NinjaTrader_ChrisL, Today, 11:21 AM
            0 responses
            21 views
            0 likes
            Last Post NinjaTrader_ChrisL  
            Working...
            X