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

Getting multiple ATM orders OnBarClose=false

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

    #16
    Nope, still broken. Here's 1/2 the code:
    Code:
    [FONT=Courier New][SIZE=2]
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]( (orderId.Length == [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]) && (atmStrategyId.Length == [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]) )[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000] // now check for a long entry[/COLOR][/SIZE][/FONT]
    [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff] if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]( bAllowLongEntry ) [/SIZE][/FONT]
    [SIZE=2][FONT=Courier New] {[/FONT][/SIZE]
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]   atmStrategyId = GetAtmStrategyUniqueId();[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]   orderId = GetAtmStrategyUniqueId();[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]   AtmStrategyCreate( OrderAction.Buy, OrderType.Market, [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], TimeInForce.Day, orderId, sATMTemplate, atmStrategyId );[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New] }[/FONT][/SIZE]
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff] else[/COLOR][/SIZE][/FONT]
    [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000] // check for a short entry[/COLOR][/SIZE][/FONT]
    [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff] if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]( bAllowShortEntry ) [/SIZE][/FONT]
    [SIZE=2][FONT=Courier New] {[/FONT][/SIZE]
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]   atmStrategyId = GetAtmStrategyUniqueId();[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]   orderId = GetAtmStrategyUniqueId();[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]   AtmStrategyCreate( OrderAction.Sell, OrderType.Market, [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], TimeInForce.Day, orderId, sATMTemplate, atmStrategyId );[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New] }[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
    [/SIZE][/FONT]

    Comment


      #17
      The other half:
      Code:
      [FONT=Courier New][SIZE=2][SIZE=2][FONT=Courier New][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000]// Check for a pending entry order[/COLOR][/SIZE][/FONT]
      [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] (orderId.Length > [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000])[/COLOR][/SIZE][/FONT]
      [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
      [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff] string[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][] status = GetAtmStrategyEntryOrderStatus(orderId);[/SIZE][/FONT]
       
      [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff] if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (status.GetLength([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]) > [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
      [SIZE=2][FONT=Courier New] {[/FONT][/SIZE]
      [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000] // If the order state is terminal, reset the order id value[/COLOR][/SIZE][/FONT]
      [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff] if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] (status[[/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]2[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000]] == [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"Filled"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] || status[[/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]2[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000]] == [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"Cancelled"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] || status[[/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]2[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000]] == [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"Rejected"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000])[/COLOR][/SIZE][/FONT]
      [SIZE=2][FONT=Courier New]   orderId = [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2].Empty;[/SIZE][/FONT]
      [SIZE=2][FONT=Courier New] }[/FONT][/SIZE]
      [SIZE=2][FONT=Courier New]} [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000]// If the strategy has terminated reset the strategy id[/COLOR][/SIZE][/FONT]
      [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]else[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] (atmStrategyId.Length > [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat)[/COLOR][/SIZE][/FONT]
      [SIZE=2][FONT=Courier New] atmStrategyId = [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2].Empty;[/SIZE][/FONT]
      [/SIZE][/FONT][/FONT][/SIZE][/SIZE][/FONT]

      Comment


        #18
        I just saw it place 6 contracts worth of trades over 2 ticks... WHY is this doing this? I thought the
        Code:
        [FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]
        [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]( (orderId.Length == [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]) && (atmStrategyId.Length == [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]) )
        [/SIZE][/FONT][/SIZE][/FONT]
        was supposed to keep me from entering another trade? Remember, this is happening live OnBarClose=false. Does that make any difference?

        Please help.

        Comment


          #19
          New simple test case for your evaluation

          I've simplified the problem into a simple strategy file. If you run it, look at the Output window at the top. The first order is placed and then you see "The current ATM Strategy market position is: Flat" even thought we are in an order. This causes more trades...

          Let me know what you find. It seems like no one has tested the ATM sample against OnBarClose=false.

          I also think if you change your "SampleAtmStrategy" to do market orders, then run it OnBarClose=false, you will see multiple entries.
          Attached Files

          Comment


            #20
            Here's some text from the Print statements. Notice how the order is placed, we get an order ID and a strategy ID, the order is "Filled", and then when we check the strategy market position and it is "Flat". Please explain how that happens. (I added the print out of the strategy ID after the order status)
            **NT** Submitting order with strategy 'JPWTraderATM/9858696b8fcc4369b3d578540e524d35'
            The entry order average fill price is: 95.86
            The entry order filled amount is: 1
            The entry order order state is: Filled
            The entry Strategy ID is: f9a8cc2d9aa649c49cdf84cb73dae3d3
            The current ATM Strategy ID is: f9a8cc2d9aa649c49cdf84cb73dae3d3
            The current ATM Strategy market position is: Flat
            The current ATM Strategy position quantity is: 0
            The current ATM Strategy average price is: 0
            The current ATM Strategy Unrealized PnL is: 0

            Comment


              #21
              Hello Tigger,

              Thank you for your responses on this matter.

              Keep in mind that the GetAtmStrategyMarketPosition() will not reflect the correct market position until the next time OnBarUpdate() is called after the fill (so the next tick after a fill with CalculateOnBarClose = False).

              Please let me know if you have any questions.

              Comment


                #22
                I will look at this again tomorrow morning, a little burnt out right now.

                It still doesn't explain why I am getting multiple entries. Remember, you told me to control the number of entries with:
                Code:
                EntriesPerDirection = [FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]; [/SIZE][/FONT]
                [SIZE=2][FONT=Courier New]EntryHandling = EntryHandling.AllEntries; [/FONT][/SIZE]
                [/SIZE][/FONT]
                which obviously doesn't work at all.

                Let's start with that one. Why doesn't that work?

                Comment


                  #23
                  Hello TiggerTrader,

                  Thank you for your response.

                  Please remove the EntryHandling and EntriesPerDirection lines from your code as this will not work with the ATM Strategy Methods.

                  Comment


                    #24
                    Eill do. So what is the equivalent way in ATM;s?

                    Also, is there a way to ask by TemplateName if any orders are active?

                    Comment


                      #25
                      Hello TiggerTrader,

                      Thank you for your response.

                      This is what we have been working on. Please retest this matter after removing the EntriesPerDirection and EntryHandling and advise if it works properly.

                      Comment


                        #26
                        OK. That did not fix it. I come back to the fact that after the fill, the GetAtmStrategyMarketPosition(atmStrategyId) says the market is flat. Following the code around thru the next pass on the next tick, we get the code:
                        Code:
                        [SIZE=2][FONT=Courier New][COLOR=#008000][SIZE=2][FONT=Courier New][COLOR=#008000][SIZE=2][FONT=Courier New][COLOR=#008000]// If the strategy has terminated reset the strategy id[/COLOR][/FONT][/SIZE]
                        [/COLOR][/FONT][/SIZE][/COLOR][/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]else[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (atmStrategyId.Length > [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat)[/SIZE][/FONT]
                        [SIZE=2][FONT=Courier New]atmStrategyId = [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2].Empty;[/SIZE][/FONT]
                        [/SIZE][/FONT]
                        This then guarantees the next pass around we have no order or position according to:
                        Code:
                        [SIZE=2][FONT=Courier New][COLOR=#0000ff][SIZE=2][FONT=Courier New][COLOR=#0000ff][SIZE=2][FONT=Courier New][COLOR=#0000ff]if[/COLOR][/FONT][/SIZE][/COLOR][/FONT][/SIZE][/COLOR][/FONT][/SIZE][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000]( (orderId.Length == [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000]) && (atmStrategyId.Length == [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000]) )[/COLOR][/SIZE][/FONT]
                        [/SIZE][/FONT]
                        which allows us to add another contract. I had to add a variable to stop allowing multiple entries inside a bar, when placing an order:
                        Code:
                        [SIZE=2][FONT=Courier New][SIZE=2][FONT=Courier New]bOrderAttempted = [/FONT][/SIZE][/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
                        [/SIZE][/FONT]
                        then only allow a new order if that is false and reset it on the FirstTickOfBar.

                        Please let me know your progress.

                        Latest note: sometimes it does recognize the market position. Right now I am in a short and the software is seeing it, therefore only 1 position. I don't know what happenedd differently to make this one work, but it is reporting that it is short.
                        Last edited by TiggerTrader; 01-24-2013, 06:56 AM.

                        Comment


                          #27
                          Hello TiggerTrader,

                          Thank you for your response.

                          Keeping in mind that the GetAtmStrategyMarketPosition() will not reflect the correct market position until the next time OnBarUpdate() is called after the fill (so the next tick after a fill with CalculateOnBarClose = False), please trying adding a return to the strategy after the AtmStrategyCreate() method is called.

                          For example:
                          Code:
                          				if( bAllowLongEntry )  
                          				{
                          					DrawText("jDl"+CurrentBar, "LongBFilled:"+Close[0].ToString(), 0, Low[0] - 8 * TickSize, Color.Black);
                          					
                          					atmStrategyId = GetAtmStrategyUniqueId();
                          					orderId = GetAtmStrategyUniqueId();
                          					AtmStrategyCreate( OrderAction.Buy, OrderType.Market, 0, 0, TimeInForce.Day, orderId, sATMTemplate, atmStrategyId );
                                                                  return; //This will cause the strategy to call OnBarUpdate() only on the next tick after the fill ensuring the Market Position is pulled correctly.
                          				}

                          Comment


                            #28
                            I will try it, but I do not think that will work. BECAUSE we already do that exact thing by using the else clause. Therefore, we don't check the strategy position until the next pass thru AFTER the order has been filled and cleared.

                            But I will try it. It looks like what you're asking me to do is skip to the next pass before we even check the order status. Maybe that will work.

                            Comment


                              #29
                              No, it doesn't work - mostly. It seems to work when there is slow tick movement. But when there is a lot of price action, and my charts freeze for a bit, then it adds as many as it can and all are reporting market position flat.

                              I keep coming back to, is there a way to ask the system "Are you in any position for ATM Template: XYZ?" If we can do that, problem solved.

                              Comment


                                #30
                                Hello TiggerTrader,

                                Thank you for your response.

                                Please send me your most recently updated strategy to [email protected] with 'ATTN: Patrick' in the subject line and a reference to this thread in the body of the e-mail: http://www.ninjatrader.com/support/f...ad.php?t=55326

                                I look forward to assisting you further.

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by LillyMarv, Today, 06:47 AM
                                1 response
                                10 views
                                0 likes
                                Last Post marcus2300  
                                Started by michi08, Today, 08:51 AM
                                1 response
                                7 views
                                0 likes
                                Last Post bltdavid  
                                Started by awwenzovs, Today, 08:03 AM
                                1 response
                                9 views
                                0 likes
                                Last Post bltdavid  
                                Started by nicthe, Today, 07:38 AM
                                1 response
                                12 views
                                0 likes
                                Last Post bltdavid  
                                Started by algospoke, 02-19-2024, 03:25 PM
                                4 responses
                                38 views
                                0 likes
                                Last Post gummybar  
                                Working...
                                X