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 CarlTrading, 05-11-2026, 05:56 AM
0 responses
52 views
0 likes
Last Post CarlTrading  
Started by CarlTrading, 05-10-2026, 08:12 PM
0 responses
29 views
0 likes
Last Post CarlTrading  
Started by Hwop38, 05-04-2026, 07:02 PM
0 responses
194 views
0 likes
Last Post Hwop38
by Hwop38
 
Started by CaptainJack, 04-24-2026, 11:07 PM
0 responses
355 views
0 likes
Last Post CaptainJack  
Started by Mindset, 04-21-2026, 06:46 AM
0 responses
274 views
0 likes
Last Post Mindset
by Mindset
 
Working...
X