Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Question about BarsSinceEntryExecution()

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

    Question about BarsSinceEntryExecution()

    Hello,

    I'm working on a Ninjascript strategy that uses ATM orders. Is there a way to use BarsSinceEntryExecution() with those orders? If so what do I use for signalName?
    No matter what I try I keep getting a return value of '-1' even several bars after the order has been submitted.

    Thanks!



    From the reference material:
    Definition


    Returns the number of bars that have elapsed since the last entry. When a signal name is provided, the number of bars that have elapsed since that last specific entry will be returned. Method Return Value


    An int value that represents a number of bars. A value of -1 will be returned if a previous entry does not exist.



    Syntax
    BarsSinceEntryExecution()
    BarsSinceEntryExecution(string signalName)



    The following method signature should be used when working with multi-time frame and instrument strategies:



    BarsSinceEntryExecution(int barsInProgressIndex, string signalName, int entryExecutionsAgo)

    My entry method:
    Code:
    #region Order Entry Method
            private void EnterAtmOrder(OrderAction orderAction)
            {
                // Ensure atmStrategyId and atmStrategyOrderId are initialized
                if (atmStrategyId == null) atmStrategyId = string.Empty;
                if (atmStrategyOrderId == null) atmStrategyOrderId = string.Empty;
    
                // Check if the state is less than realtime
                if (State < State.Realtime)
                {
                    Print("A " + orderAction + " order has been placed on historical data.");
                    return;
                }
    
                if (atmStrategyId.Length == 0)
                {
                    // Assign a new GUID to atmStrategyId
                    atmStrategyId = GetAtmStrategyUniqueId();
                    atmStrategyOrderId = GetAtmStrategyUniqueId(); // Ensure this is unique as well
    
                    // Retrieve the current Bid and Ask prices
                    double askPrice = GetCurrentAsk(0);
                    double bidPrice = GetCurrentBid(0);
    
                    // Print both the Bid and Ask prices
                    Print("Current Ask is: " + askPrice);
                    Print("Current Bid is: " + bidPrice);
    
                    // Determine the price based on orderAction
                    double price = 0;
                    if (orderAction == OrderAction.Buy)
                    {
                        price = askPrice; // Use the Ask price for Buy orders
                    }
                    else if (orderAction == OrderAction.Sell)
                    {
                        price = bidPrice; // Use the Bid price for Sell orders
                    }
    
                    // Create the ATM strategy with a limit order at the determined price
                    AtmStrategyCreate(
                        orderAction,
                        OrderType.Limit,
                        price,
                        0,
                        TimeInForce.Day,
                        atmStrategyOrderId,
                        "ATM MADD Custom",
                        atmStrategyId,
                        (atmCallbackErrorCode, atmCallbackId) =>
                        {
                    // checks that the callback is returned for the current atmStrategyId stored
                    if (atmCallbackId == atmStrategyId)
                            {
                        // check the atm callback for any error codes
                        if (atmCallbackErrorCode == Cbi.ErrorCode.NoError)
                                {
                            // if no error, set private bool to true to indicate the atm strategy is created
                            isAtmStrategyCreated = true;
                                    orderEntryTime = DateTime.Now; // Record the time of entry
                            hasOrderBeenChecked = false; // Reset the check flag on order creation
                        }
                            }
                        }
                    );
                }
            }
            #endregion​

Latest Posts

Collapse

Topics Statistics Last Post
Started by NullPointStrategies, Today, 05:17 AM
0 responses
52 views
0 likes
Last Post NullPointStrategies  
Started by argusthome, 03-08-2026, 10:06 AM
0 responses
130 views
0 likes
Last Post argusthome  
Started by NabilKhattabi, 03-06-2026, 11:18 AM
0 responses
70 views
0 likes
Last Post NabilKhattabi  
Started by Deep42, 03-06-2026, 12:28 AM
0 responses
44 views
0 likes
Last Post Deep42
by Deep42
 
Started by TheRealMorford, 03-05-2026, 06:15 PM
0 responses
48 views
0 likes
Last Post TheRealMorford  
Working...
X