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

Entries per direction

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

    Entries per direction

    What is the point of Entries Per Direction parameter in the strategy setup window. The help file on this shows the following:

    Entries per direction
    Sets the maximum number of entries allowed per direction while a position is active based on the "Entry handling" property


    .......yet


    when I run, say..., the sample ATMStrategy that comes standard with NT it allows multiple entries even though the default parameter is set to only 1 direction per entry.


    What is the point of that parameter and why does it seem to fail?

    #2
    Hello ShruggedAtlas,

    Thank you for your inquiry.

    When using ATM Strategies, strategy set up parameters such as EntriesPerDirection, EntryHandling, and ExitOnClose do not apply.

    You could, however, establish this maximum limit manually with a counter.

    Let's say you want a limit of two. After calling AtmStrategyCreate(), increment the counter by one. Before calling another AtmStrategyCreate(), check to see if the counter is less than two. If it is, call the method and increment by one.

    Example:
    Code:
    int counter = 0;
    
    if (counter < 2)
    {
         AtmStrategyCreate(...);
         counter++
    }
    When an ATM Strategy is completed, you can decrement the counter by one.

    Example:
    Code:
    if (GetAtmStrategyMarketPosition("id") == MarketPosition.Flat)
    {
         counter--;
    }
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      I'll test this but I have some concerns as it applies to my unique code.

      I have to have my code running with CalculateOnBarClose == false because i'm running a multitimeframe strategy and I need to be able to see longer term timeframe values changing on a tick by tick basis. That is a necessity.

      I haven't tested yet but I'm thinking that based on what another support person told me when I create an ATM the order is pending and not yet filled so the status is the orderId and atmStrategyId are > 0 and yet the values show the position as flat.

      Therefore, in my case since I only want one entry per direction, as soon as the ATM is created, the counter which I set to 0 gets set to 1. Then, instantly before the position is filled when the position shows as flat, the counter is reset back to 0 thereby allowing the strategy to create yet another ATM even before the first one is filled.

      I'll test this now, but I don't think it will work because I'm calculating the bars on each tick rather than close.

      Comment


        #4
        Testing failed

        I tested the idea of using a counter - see code below. Unless i've made a mistake in how I applied the counter, I don't believe this will work.

        I also tried changing CalulateOnBarClose to both true and false just to see what would happen. Both result in multiple entries within the same bar. note: Even when the order did fill, it continues to attempt to place new orders when entry conditions allow. Since there are multiple entries, there are multiple orderId's and atmStrategyId's but only one counter.

        any advice would be greatly appreciated.

        Code:
                protected override void OnBarUpdate()
                {
        
                    if (Historical)
                        return;
        
        
                    if (orderId.Length == 0 && atmStrategyId.Length == 0 && Close[0] > Open[0])
                    {
                        if (counter == 0)
                        {
                            atmStrategyId = GetAtmStrategyUniqueId();
                            orderId = GetAtmStrategyUniqueId();
                            AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Limit, Low[0], 0, TimeInForce.Day, orderId, "QUICKTEST", atmStrategyId);
                            counter = 1;
                        }
                    }
                    // Check for a pending entry order
                    if (orderId.Length > 0)
                    {
                        string[] status = GetAtmStrategyEntryOrderStatus(orderId);
                        
                        // If the status call can't find the order specified, the return array length will be zero otherwise it will hold elements
                        if (status.GetLength(0) > 0)
                        {
                            // Print out some information about the order to the output window
                            Print("The entry order average fill price is: " + status[0]);
                            Print("The entry order filled amount is: " + status[1]);
                            Print("The entry order order state is: " + status[2]);
        
                            // If the order state is terminal, reset the order id value
                            if (status[2] == "Filled" || status[2] == "Cancelled" || status[2] == "Rejected")
                                Print("Setting orderId to empty string");
                                orderId = string.Empty;
                                counter = 0;
                        }
                    } // If the strategy has terminated reset the strategy id
                    else if (atmStrategyId.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat)
                        Print("Setting atmStrategyId to empty string");
                        atmStrategyId = string.Empty;
                        counter = 0;
                }
        I also used the following entry condition to test if it made a difference...sadly, no difference (note CalculateOnBarClose was set to true) yet I got multiple entries within the same 50 tick bar.

        Code:
                    if (counter == 0)
                    {
                        if (orderId.Length == 0 && atmStrategyId.Length == 0 && Close[0] > Open[0])
                        {
                            atmStrategyId = GetAtmStrategyUniqueId();
                            orderId = GetAtmStrategyUniqueId();
                            AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Limit, Low[0], 0, TimeInForce.Day, orderId, "QUICKTEST", atmStrategyId);
                            counter = 1;
                        }
                    }
        Last edited by ShruggedAtlas; 06-18-2015, 07:02 AM.

        Comment


          #5
          Hello ShruggedAtlas,

          I understand that another member of the NinjaScript team has worked with you on this issue through email.

          Please, let us know if we may be of further assistance.
          Zachary G.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by CortexZenUSA, Today, 12:53 AM
          0 responses
          1 view
          0 likes
          Last Post CortexZenUSA  
          Started by CortexZenUSA, Today, 12:46 AM
          0 responses
          1 view
          0 likes
          Last Post CortexZenUSA  
          Started by usazencortex, Today, 12:43 AM
          0 responses
          5 views
          0 likes
          Last Post usazencortex  
          Started by sidlercom80, 10-28-2023, 08:49 AM
          168 responses
          2,265 views
          0 likes
          Last Post sidlercom80  
          Started by Barry Milan, Yesterday, 10:35 PM
          3 responses
          11 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Working...
          X