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

Position doubling up with live account

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

    Position doubling up with live account

    I have a strategy that runs great in sim mode, but every time I use with my live account, without making any change, the position is doubling up.
    I can't understand what is wrong and is very hard for me to debug with the live account because I need to manage my position. I'm not using any copier, nor I'm having more than one instance of this strategy running at the same time.

    I only enter the position when it is flat.

    This is the code I'm using to enter the position:

    Code:
    if (Position.MarketPosition == MarketPosition.Flat) {
    if (CrossAbove(EMA_Low, EMA_High, 3) {
    
    SetStopLoss(@"Long", CalculationMode.Ticks, StopLoss, false);
    SetProfitTarget("Long", CalculationMode.Ticks, TargetTicks);
    EnterLong(Qty, @"Long");
    }
    }
    ​


    Qty is 1 and EntriesPerDirection is set 3.

    To be honest, I'm not sure if it's doubling up or entering 1 more contract, because I'm usually take 1 contract, but the order is executed twice and end up with 2 contracts.

    Again, in sim mode, everything works fine. The problem is in the live account.

    The log shows two different executions:

    Order='69274400291/8127836' Name='Long Copied' New state='Submitted' Instrument='NQ 06-24' Action='Buy' Limit price=0 Stop price=0 Quantity=1 Type='Market' Time in force=GTC Oco='e5a9a72f25954eb99799e587e0312936' Filled=0 Fill price=0 Error='No error' Native error=''
    Order='69274400291/8127836' Name='Long Copied' New state='Working' Instrument='NQ 06-24' Action='Buy' Limit price=0 Stop price=0 Quantity=1 Type='Market' Time in force=GTC Oco='e5a9a72f25954eb99799e587e0312936' Filled=0 Fill price=0 Error='No error' Native error=''
    Order='69274400291/8127836' Name='Long Copied' New state='Accepted' Instrument='NQ 06-24' Action='Buy' Limit price=0 Stop price=0 Quantity=1 Type='Market' Time in force=GTC Oco='e5a9a72f25954eb99799e587e0312936' Filled=0 Fill price=0 Error='No error' Native error=''
    Execution='68921980094_1' Instrument='NQ 06-24' Account='8093601' Exchange=Default Price=17736.75 Quantity=1 Market position=Long Operation=Operation_Add Order='68921980094' Time='4/24/2024 9:35 AM'
    Instrument='NQ 06-24' Account='8093601' Average price=17736.75 Quantity=1 Market position=Long Operation=Operation_Add
    NinjaScript strategy 'EMA Strategy V1.3/305394201' submitting order
    Order='68921980094/8093601' Name='Long' New state='Filled' Instrument='NQ 06-24' Action='Buy' Limit price=0 Stop price=0 Quantity=1 Type='Market' Time in force=GTC Oco='' Filled=1 Fill price=17736.75 Error='No error' Native error=''
    Order='68921980094/8093601' Name='Long' New state='Submitted' Instrument='NQ 06-24' Action='Buy' Limit price=0 Stop price=0 Quantity=1 Type='Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
    Order='68921980094/8093601' Name='Long' New state='Working' Instrument='NQ 06-24' Action='Buy' Limit price=0 Stop price=0 Quantity=1 Type='Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
    Order='68921980094/8093601' Name='Long' New state='Accepted' Instrument='NQ 06-24' Action='Buy' Limit price=0 Stop price=0 Quantity=1 Type='Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
    NinjaScript strategy 'EMA Strategy V1.3/305394201' submitting order​

    Any ideas?​
    Last edited by chbruno; 04-24-2024, 04:13 PM.

    #2
    Hello chbruno,

    Thank you for your inquiry.

    Are you using any other methods to enter long or short? Are you perhaps calling ExitLong() in another condition (entering an exiting on the same bar)?

    With EntriesPerDirection set to 3, this allows you to enter up to 3 entries per direction while your position is active. So your strategy could have up to 3 long positions at one time.




    In order to understand why the script is behaving as it is, such as placing orders or not placing orders when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

    In the strategy add prints (outside of any conditions) that print the date time of the bar and all values compared in every condition that places an order.

    The prints should include the time of the bar and should print all values from all variables and all hard coded values in all conditions that must evaluate as true for this action to be triggered. It is very important to include a text label for each value and for each comparison operator in the print to understand what is being compared in the condition sets.

    Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

    Further, enable TraceOrders which will let us know if any orders are being ignored and not being submitted when the condition to place the orders is evaluating as true.

    I am happy to assist you with analyzing the output from the output window.

    Run or backtest the script and when the output from the output window appears save this by right-clicking the output window and selecting Save As... -> give the output file a name and save -> then attach the output text file to your reply.

    Below is a link to a forum post that demonstrates using informative prints to understand behavior and includes a link to a video recorded using the Strategy Builder to add prints.


    Please let me know if I may further assist with analyzing the output or if you need any assistance creating a print or enabling TraceOrders.​
    Last edited by NinjaTrader_Gaby; 04-25-2024, 06:39 AM.
    Gaby V.NinjaTrader Customer Service

    Comment


      #3
      The logic is correct, as it works flawlessly in sim mode. I have both enterlong and entershort and I close the position with the appropriate method.

      I found out NT8 with Tradovate acconts is being reported with this issue, and both performance accounts I have are using Tradovate as you can see in this post, multiple complains about apex and tradvate. One of the accounts I have is Apex.

      As the title suggests, all of my trades are showing up as duplicates in Trade Performance. Here is a screenshot to show you what I mean based on today's trades. I see this is the case for every day's trades, any help?


      I can try setting the entriesperdirection = 1, but this isn't a fix. I usually like to have a runner, and if I set 2, the runner entry will be mostly ignored.

      Please let me know if you have any information regarding this travodate issue with NT8.


      Comment


        #4
        Hello chbruno,

        The issue in those posts are specifically with the Trade Performance report, not the actual trades/positions taken by the strategy as you are reporting. Unless you were referring to inaccurate reporting in the TradePerformance report in your initial post?

        If not, we will need to information from the prints and TraceOrders in order to analyze the strategy's behavior.

        Please let us know if you need any further assistance.
        Gaby V.NinjaTrader Customer Service

        Comment


          #5
          Hi Gaby,

          Thanks for your reply.

          The print works just fine when using the sim account. Everything is accurate. When today I got a trade and the qty set was one, but the order manager got 2 and I manually had to close 1 with a small loss. I played the same strategy using the playback data and the strategy worked just fine, taking only 1 contract.

          Unfortunately, I will not try to debug the code using Visual Studio using my live account. I can do on sim, but sim account is working fine.

          Comment


            #6
            Hello chbruno,

            Unfortunately, without the output from the prints it is hard to make an assessment about what is going on.

            One issue could be that you mentioned you are using both enter and exit methods.

            I have both enterlong and entershort and I close the position with the appropriate method.
            This could cause an overfill if you are entering and exiting on the same bar. If you want to reverse the position, call an entry order in the opposite direction of the position without calling an exit method first. For example if the position is long then call EnterShort(). NinjaTrader will automatically send a Close position order and then send another order as the entry order to enter the opposite direction.

            As a heads up, calling an exit order and an entry order on the same pass of OnBarUpdate will result in either the strategy position entering the opposite position with double the quantity or will result in an Overfill.

            This forum post goes into detail:



            Please let us know if you have any further questions.
            Gaby V.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by KeitDevs, Today, 06:36 AM
            0 responses
            1 view
            0 likes
            Last Post KeitDevs  
            Started by AgriTrdr, Yesterday, 01:51 PM
            6 responses
            21 views
            0 likes
            Last Post bobperez  
            Started by ETFVoyageur, Yesterday, 12:11 PM
            11 responses
            40 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by rdlans, Today, 05:42 AM
            0 responses
            7 views
            0 likes
            Last Post rdlans
            by rdlans
             
            Started by llanqui, 05-22-2024, 06:14 AM
            13 responses
            35 views
            0 likes
            Last Post llanqui
            by llanqui
             
            Working...
            X