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

Positionsize - Account Sync in simulated trading

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

    Positionsize - Account Sync in simulated trading

    Hey guys,

    I am new to the NT Forum and hope that someone can help me with my problem.
    I tried to find a similar Topic, but wasn't successful.

    I am currently testing a Long-only-strategy with a paper account in realtime and experience some problems with the position size, which weren't occuring in backtests. As you can see from the attached screenshot, the Long-only-strategy is also opening short positions, which shouldn't be.
    I try to check whether I am currently long with "Position.MarketPosition == MarketPosition.Long" before making the exit order. However, it seems that this code and/or "Account Sync = True" is not working properly, otherwise there shouldn't occure Shortpositions in the trading account from my point of view.

    I would be very thankful if someone could help me with this issue and tell me where the problem is.

    Thank you very much in advance!
    Cheers PaBa

    Code:
            protected override void OnBarUpdate()
     {
                //Enter Long
                    if (Position.MarketPosition == MarketPosition.Flat 
                    && entryOrder == null && CrossAbove(SMA(fast), SMA(slow), 1))
                    {
        
                        // calculates the number of shares to buy based on the Account Cashvalue
                        Dquantity = ((AccountSize/30)/Close[0]);                                                   
                        OrderQuantity = Convert.ToInt32(Dquantity);    
    
                        entryOrder = EnterLongLimit(0, true, OrderQuantity, Close[0],"Long");
                        PosiQuantity = OrderQuantity; 
                        Print("the Entry-Position is "+PosiQuantity);
                        barNumberOfOrder = CurrentBar;
                        }
                    
                  // Exit Long
                        if (Position.MarketPosition == MarketPosition.Long 
                        && CrossBelow(SMA(fast), SMA(slow), 1))
                             {
                           ExitLong(PosiQuantity,"", "Long");
                        Print("the Exit-Position is "+PosiQuantity);
                        }        
                    
                       
    }
    Attached Files
    Last edited by cNuuuuuu; 01-13-2015, 05:03 PM.

    #2
    PaBa,

    What are the Prints() saying in the Output Window when you run the strategy?

    Can you attach a screenshot of the Orders Tab?

    Your code may be submitting to ExitLong()'s thus getting the Short poisitions.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Hey man, I haven't played with this yet, but can only assume some maths behind the position quantity is not working properly.

      If you have 50 long, and exit long with 100, you end up with 50 short.

      Comment


        #4
        Thank you for your answers

        @happypappy: In oder to avoid the issue you mentioned I use the following code on entry
        which stores the order quantity in "PosiQuantity":
        Code:
        entryOrder = EnterLongLimit(0, true, OrderQuantity, Close[0],"Long"); 
        PosiQuantity = OrderQuantity;
        and calls this amount on exit:
        Code:
        ExitLong(PosiQuantity,"", "Long");
        @NinjaTraderCal: I will send the Prints tomorrow evening. I just wrote them on Saturday to locate the problem. However in Backtests everything works as it should. The mentioned code looks correct, right?! Is there another possibilty to store the position quantity? The order "Exit Long" will only executed when NT thinks it is invested long, right (so not, when it is market neutral)? Or is it possible with NT to check directly the position quantity in the bank account?

        I'll start tomorrow again the strategy, because I think that it might be an issue with the "Acount Sync". The code works for most stocks work as it should. Only 2-3 Stocks were short or Neutral, which is obviously not correct in a long-only stategy. So I think, that the "simulated Selling" was maybe really executed?!

        Comment


          #5
          Hello cNuuuuuu,

          Thank you for your response.

          The code looks correct, however it could be due to multiple strategies running at once. As Cal recommended please try Print() and please enable TraceOrders in your strategy as well: http://www.ninjatrader.com/support/h...raceorders.htm

          The position can be tracked with Position.MarketPosition: http://www.ninjatrader.com/support/h...7/position.htm

          The strategy should only be checking it's own position. It is possible for the strategy to become out of sync after the initial sync if other strategies are running or manual trades are placed.

          Comment


            #6
            Hey Patrick,
            I also thank you for your response. I implemented the "Traceorder" and Print Feature in my strategy and started it again with "account sync = true". Settings in Options/Strategies/NinjaScript are on standard (Wait until flat before executing live).

            I am running this strategy on the DOW- Instrument List. So there are 30 identical strategies running, but each on a single stock. So I am not running multiple Strategies on one stock, which could produce this result.

            I will post the output and trackrecord, when this error occurs again

            Comment


              #7
              Hey guys,

              it's been a while... I had some issues with my server, so I wasn't able to run the strategy with the output window. I started the strategy yesterday, now having the same problem:

              I highlighted AXP as an example and attached the output/orders/execution windows of NT so we can locate the problem.
              I was wondering whether this error is connected with cancelling a limit buy order. Maybe NT thinks that it is invested long, although I have this code to check before selling a long-position: if (Position.Marketposition == MarketPosition.Long). This could maybe than cause this net-short Position?!

              Thank you so much for your help! I wish you all a Merry Christmas
              Attached Files
              Last edited by cNuuuuuu; 12-24-2014, 05:20 AM.

              Comment


                #8
                Hello cNuuuuuu,

                Thank you for your update on this matter.

                Would it be possible to review your Log and Trace files? If so, please send me your log and trace files for today so that I may look into what occurred.

                You can do this by going to the Control Center-> Help-> Mail to Platform Support.

                Please reference this thread in the subject line of the e-mail: "http://www.ninjatrader.com/support/forum/showthread.php?t=70755"

                Comment


                  #9
                  Hey PatrickH,

                  I upgraded my server today, so I had to restart the strategy, but as soon as I observe that the problem occurs, I'll send you the desired files as described. Thank you very much for helping me with this issue!

                  Have a nice Christmas!

                  Comment


                    #10
                    cNuuuuuu, thanks for the files we will review and be back in touch with our thoughts.
                    BertrandNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by llanqui, Today, 10:29 AM
                    1 response
                    12 views
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Started by Trader146, 05-10-2024, 09:17 PM
                    1 response
                    22 views
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Started by bourasrafik, Today, 03:26 PM
                    0 responses
                    5 views
                    0 likes
                    Last Post bourasrafik  
                    Started by benmarkal, Yesterday, 08:44 AM
                    1 response
                    30 views
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Started by somethingcomplex, Yesterday, 10:36 PM
                    1 response
                    24 views
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Working...
                    X