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

Can't figure out right variable for GetAtmStrategyMarketPosition("atmStrategyId")

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

    #31
    Hello,
    It could be, as the TICKQ's values are being called every time that each data series bars update.
    I would recommend to put your check for the TICKQ in within a check for its BarsInProgress.
    If we can be of any other assistance please let us know.
    Cody B.NinjaTrader Customer Service

    Comment


      #32
      Well Cody, despite your best efforts I have been unable to resolve the multiple entry issue. It's funny, the strategy works perfectly when I run it on market replay data. I can run multiple days of data and not have one single multiple entry. When I trade with a live data feed though BOOM. Multiple entries almost every trade. Does that differing result give you any clue as to what might be wrong

      Comment


        #33
        For what it's worth I found two other threads where people were having the identical problem. Not sure it was resolved in either


        Comment


          #34
          Hello,
          Please attach your strategy so I may fully view it.
          You can attach your Strategy to your response by going to File > Utilities > Export NinjaScript > Export selected source files > select your Strategy> select the right arrow > Export. The file will be located under (My) Documents\NinjaTrader 7\bin\Custom\ExportNinjaScript.
          I look forward to your reply.
          Cody B.NinjaTrader Customer Service

          Comment


            #35
            Hi Cody I think I may have fixed the multiple entry issue using the template from the strategy created by one of the members in this thread



            Its interesting I found several other threads where people were having the identical issue I was. The strategy worked fine on Market Replay but in live trading would have multiple entries when COBC was false. I printed the trades as you suggested and there were multiple instances where after the entry of a trade, many many many ticks went by before it would show anything other than Flat. Im running my revised strategy now and have not had any entry problems or multiple entries. Ill let you know if the problem reoccurs

            Comment


              #36
              Hi Cody, I have gotten my strategy to work fine and gotten the issues we were working on addressed. I have one last problem. If I am in a trade, I have a series of conditions which if true will close the position. To do this, I have added the following lines of code;

              if ( atmStrategyId.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyId) == MarketPosition.Long && Closes[1][0]<-200)


              {
              AtmStrategyClose(atmStrategyId);

              //
              Print(Time[0].ToString()+"Close Out: " + AtmStrategyClose(atmStrategyId) );

              }
              if (atmStrategyId.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyId) == MarketPosition.Short && Closes[1][0]>200)

              {
              AtmStrategyClose(atmStrategyId);

              //
              Print(Time[0].ToString()+"Close Out: " + AtmStrategyClose(atmStrategyId) );

              }


              When it hits the condition it does in fact close out the trade. However, what appears to be happening is that in the close order is sent but before it is executed another tick comes in showing the MarkertPosition is not flat and it therefore sends ANOTHER close order. So for example. If the ATM trade had me long 2 contracts, I will get closed out with the first Close Order, then end up short 2 shares when the next Close Order is executed. The second Close order just leaves me naked. There is no ATM strategy attached to it. I'm enclosing the prints from the Output window so you can see what I'm talking about. Any easy ways to address this.

              It doesn't happen all the time. Maybe 1 in 3 times when the condition is hit does this happen. The other times it works correctly. Always works correctly on Market Replay
              Attached Files

              Comment


                #37
                Hello,
                To prevent this you will need to add a check for when there is a pending close order. I have attach an example of how you could check the status of a close order using an ATM Strategy based NinjaScript Strategy. I set a bool and if the bool is equal to false that means that there is not a pending order. If you are going to implement something like this example you will need a complete understanding of OnOrderUpdate, IOrder, and ArrayList I would also recommend to fully review the following reference sample that uses a similar idea: http://ninjatrader.com/support/forum...ead.php?t=5790

                Please let me know if you have any questions on the example.
                Attached Files
                Cody B.NinjaTrader Customer Service

                Comment


                  #38
                  Thanks Cody. I will look that over. Could I not just also add the line orderId==0. Wouldn't that require there be no pending orders before the close order is executed.

                  Comment


                    #39
                    orderId.Length ==0 I mean

                    Comment


                      #40
                      Hello,
                      The variable orderID will not be the order id for the close order created by AtmStategyClose(), the orderID only applies to the order created by AtmStrategyCreate().

                      If we can be fo any other assistance please let us know.
                      Cody B.NinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Haiasi, Today, 06:53 PM
                      1 response
                      4 views
                      0 likes
                      Last Post NinjaTrader_Manfred  
                      Started by ScottWalsh, Today, 06:52 PM
                      1 response
                      11 views
                      0 likes
                      Last Post NinjaTrader_Manfred  
                      Started by ScottW, Today, 06:09 PM
                      1 response
                      5 views
                      0 likes
                      Last Post NinjaTrader_Manfred  
                      Started by ftsc2022, 10-25-2022, 12:03 PM
                      5 responses
                      256 views
                      0 likes
                      Last Post KeyonMatthews  
                      Started by Board game geek, 10-29-2023, 12:00 PM
                      14 responses
                      244 views
                      0 likes
                      Last Post DJ888
                      by DJ888
                       
                      Working...
                      X