Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

GetAtmStrategyMarketPosition()

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

    GetAtmStrategyMarketPosition()

    I wrote a strategy that uses tool bar buttons to generate orders with an ATM strategy. It is designed so that when I press a button, it disables the other buttons until position.market.position==marketposition.Flat.

    Click image for larger version

Name:	Ranger.JPG
Views:	1
Size:	95.6 KB
ID:	896653


    Everything works fine except I cannot get a signal back from GetAtmStrategyMarketPosition() to notify the strategy to release the buttons.

    I have read the help material on using ATM Strategies, but have not been successful.

    Should I be able to get a signal back whether the position is flat or not. Or do I need to build more code?

    I didn't include the entire strategy to save space.

    Code:
     
    Variables:
    private string entryorderid = "";
    private string atmorderid = "";
     
     
     
    AtmStrategyClose(atmorderid);
     
    atmorderid = GetAtmStrategyUniqueId();
    entryorderid = GetAtmStrategyUniqueId(); 
     
     
    if (GetAtmStrategyMarketPosition(atmorderid) == MarketPosition.Flat)
    {
    tsbtnSell.Enabled = true;
    tsbtnBuy.Enabled =true;
    tsbtnSellMkt.Enabled = true;
    tsbtnBuyMkt.Enabled =true;
    tsbtnClose.Enabled = true;
    }
    If I put this code in "On Bar Update" , it immediately releases the buttons as soon as an order is filled.

    If I place this code anywhere else, it doesn't release the buttons unless I do so manually.

    Any advice you can give on direction to take, would be appreciated.

    Thanks.

    Regards,
    TMFT

    #2
    Hello TMFT,

    I would first evaluate this without your custom code, to make sure there is no conflict there. There is a sample to work from built into the platform. Tools > Edit NinjaScript > Strategy > SampleAtmStrategy.

    The sample provides all the needed structure for this, which you will need for proper management of the Atm, and order Ids. From looking at your code snippet, you are creating an ID too frequently. Following the sample will help you create only one ID for the lifecycle of the ATM.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_RyanM View Post
      Hello TMFT,

      I would first evaluate this without your custom code, to make sure there is no conflict there. There is a sample to work from built into the platform. Tools > Edit NinjaScript > Strategy > SampleAtmStrategy.

      The sample provides all the needed structure for this, which you will need for proper management of the Atm, and order Ids. From looking at your code snippet, you are creating an ID too frequently. Following the sample will help you create only one ID for the lifecycle of the ATM.
      Thanks for the reply. I have studied the sample and the help section , and hacked on this for quite some time. Unfortunately the examples are a bit difficult to follow.

      Comment


        #4
        The sample can be used pretty much out of the box. Most all the elements are required for a functioning NinjaScipt > ATM strategy. It may take a bit to understand how it works, but you can still use it without requiring a deep understanding.

        You can save a copy through right click > Save As

        The parts unique to your strategy would be:
        if (orderId.Length == 0 && atmStrategyId.Length == 0 && Close[0] > Open[0])
        • Your condition for placing the initial order.


        AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Limit, Low[0], 0, TimeInForce.Day, orderId, "AtmStrategyTemplate", atmStrategyId);
        • The price the initial order is placed and the name of your ATM strategy template.


        There are also some illustrative points for changing the stop price and printing to the output window. These lines are commented to inform this. The rest of the sample structure is required for it to function properly.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Thanks for the reply.

          I have everything working except for a conclusive response regarding the position. Others have told me they had a similar problem with the time lag between when an order is filled and the response shows the position changed from flat to long/short. It's actually functional as is, I was just trying to maximize use of the software.

          Originally posted by NinjaTrader_RyanM View Post
          The sample can be used pretty much out of the box. Most all the elements are required for a functioning NinjaScipt > ATM strategy. It may take a bit to understand how it works, but you can still use it without requiring a deep understanding.

          You can save a copy through right click > Save As

          The parts unique to your strategy would be:

          if (orderId.Length == 0 && atmStrategyId.Length == 0 && Close[0] > Open[0])
          • Your condition for placing the initial order.

          AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Limit, Low[0], 0, TimeInForce.Day, orderId, "AtmStrategyTemplate", atmStrategyId);
          • The price the initial order is placed and the name of your ATM strategy template.

          There are also some illustrative points for changing the stop price and printing to the output window. These lines are commented to inform this. The rest of the sample structure is required for it to function properly.

          Comment


            #6
            From the OutPut Window:

            GetAtmStrategyMarketPosition() method error: Missing atmStrategyId parameter

            Code:
            if ( entryOrder[2] != "Filled" && GetAtmStrategyMarketPosition(atmStrategyId) == MarketPosition.Flat )
            
            {
            	AtmStrategyChangeEntryOrder(0,price, "orderId");
                    tsLabel.Text ="Pending Buy @ " + price.ToString();
            }
            Any suggestions?

            Comment


              #7
              It can't find your atmID. This could be because none is assigned, management of the ID is not coded properly, or you have not yet used AtmStrategyCreate().

              If you have any issues with ATM integration, use the sample for reference. All the structure is required for maintaining one proper atmStrategyId through the life-cycle of the trade.


              You created three separate threads for help working with ATM strategies. Since it's all related to the same topic, can you please keep ATM questions in one thread for better continuity.
              Ryan M.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by hurleydood, 09-12-2019, 10:45 AM
              14 responses
              1,093 views
              0 likes
              Last Post Board game geek  
              Started by cre8able, Yesterday, 04:16 PM
              1 response
              14 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by cre8able, Yesterday, 04:22 PM
              1 response
              13 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by stafe, 04-15-2024, 08:34 PM
              5 responses
              28 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by StrongLikeBull, Yesterday, 04:05 PM
              1 response
              12 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Working...
              X