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:
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:
#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
