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

Trade Count Problem

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

    Trade Count Problem

    Hi,

    In certain strategies, I would like to limit the daily number of losing trades. I have implemented the logic to do this by using Performance.AllTrades.Count.

    In backtesting, this works great, but live, what seems to happen is that the market orders for entry seem to get executed as several fills. For example, a recent market order for 651 shares worked out to be 300 @ Default, 200 @ Default, 100 @ Default, 51 @ Default. It does this even though it is being executed at the same price. I know this because I have a Print() in OnExecution which shows me the fills and the IExecution.

    What happens next is when these trades are closed (by a single market order), this then counts as 4 losing trades rather than just 1. Is there a solution to this?

    Thanks

    #2
    wuileng, yes you could certainly be getting so called partial fills in live trading and on the simulator, in backtesting this would not be possible. From the entry and exit execution pairing this would report as multiple trades then. What you could look into is for example a counter on the position updates seen in OnPositionUpdate(). Just increment if it changes to anything non flat and reset every day/session.

    BertrandNinjaTrader Customer Service

    Comment


      #3
      Hi Bertand,

      Using the method you suggester in OnPositionUpdate(), would I encounter the same problem with OnPositionUpdate() being called four times on that market order problem?

      If that is the case, what I would need to do would be if (Position.MarketPosition != MarketPosition.Flat && [Position Right Before This Was Flat]). Is there an easy way of implementing the second condition or would I need to update a variable with the strategy's position on each bar update in OnBarUpdate?

      Thanks

      Comment


        #4
        No I would not expect that, the first time you are in a position it would not change again as you're just adding to the already existing position via the partials seen.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Thanks, so just to clarify - OnPositionUpdate is only called when a strategy's position changes between Long/Short/Flat and not when the quantity of a position changes?

          Comment


            #6
            That is correct wuileng, it's just the market position update and not a size update.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Thanks again for your help!

              Comment


                #8
                Sorry to disturb, but I had a quick follow up question.

                Say I had a multi instrument long-short strategy, which trades the primary and a secondary instrument XYZ. Also let's say that it went long primary, and short XYZ as a hedge (in the same OnBarUpdate call via market orders):

                Would OnPositionUpdate be called twice or just once?
                Would the generic Position.MarketPosition (rather than Positions[0] or Positions[1]) show long (because it enters long primary first)?

                Now, if one leg was closed first, say the long primary leg so what remains is short XYZ:

                Would OnPositionUpdate be called again?
                Would the generic Position.MarketPosition now show short?

                Thanks

                Comment


                  #9
                  Yes, OnPositionUpdate() would be called for each change of the market positions, as you would then have 2 strategy positions for the script trading on 2 instruments. To see what exactly you get just print the position.ToString to your output when passed in OnPositionUpdate().
                  BertrandNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by kujista, Today, 06:23 AM
                  4 responses
                  12 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by traderqz, Yesterday, 09:06 AM
                  2 responses
                  15 views
                  0 likes
                  Last Post traderqz  
                  Started by traderqz, Today, 12:06 AM
                  3 responses
                  6 views
                  0 likes
                  Last Post NinjaTrader_Gaby  
                  Started by RideMe, 04-07-2024, 04:54 PM
                  5 responses
                  28 views
                  0 likes
                  Last Post NinjaTrader_BrandonH  
                  Started by f.saeidi, Today, 08:13 AM
                  1 response
                  8 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Working...
                  X