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

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 algospoke, Yesterday, 06:40 PM
            2 responses
            18 views
            0 likes
            Last Post algospoke  
            Started by ghoul, Today, 06:02 PM
            3 responses
            14 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by jeronymite, 04-12-2024, 04:26 PM
            3 responses
            44 views
            0 likes
            Last Post jeronymite  
            Started by Barry Milan, Yesterday, 10:35 PM
            7 responses
            20 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by AttiM, 02-14-2024, 05:20 PM
            10 responses
            180 views
            0 likes
            Last Post jeronymite  
            Working...
            X