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 Mindset, 04-21-2026, 06:46 AM
0 responses
87 views
0 likes
Last Post Mindset
by Mindset
 
Started by M4ndoo, 04-20-2026, 05:21 PM
0 responses
128 views
0 likes
Last Post M4ndoo
by M4ndoo
 
Started by M4ndoo, 04-19-2026, 05:54 PM
0 responses
65 views
0 likes
Last Post M4ndoo
by M4ndoo
 
Started by cmoran13, 04-16-2026, 01:02 PM
0 responses
117 views
0 likes
Last Post cmoran13  
Started by PaulMohn, 04-10-2026, 11:11 AM
0 responses
67 views
0 likes
Last Post PaulMohn  
Working...
X