Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
update the price on a stop limit order created on my strategy calling the ATM
Collapse
X
-
update the price on a stop limit order created on my strategy calling the ATM
for example I'm summiting a buy stop limit order 20ticks above the market and let's say that the bar close and did not trigger my stop limit order when the next bar opens i want to update the price of the stop limit order and if it happens again continue to do so until cancel.Tags: None
-
hi Chelsea
thanks for your quick response, i try what you mention above but im not sure if im using it right this is what im working with i just want that the stop limit constantly update as long my entry condition is true and im running this in price change
//ATM
// Check any pending long or short orders by their Order Id and if the ATM has terminated.
// Check for a pending long order.
if (longOrderId.Length > 0)
{
// If the status call can't find the order specified, the return array length will be zero otherwise it will hold elements.
string[] status = GetAtmStrategyEntryOrderStatus(longOrderId);
if (status.GetLength(0) > 0)
{
if( long_e==false )
{
{
AtmStrategyCancelEntryOrder(longOrderId);
longOrderId = string.Empty;
}
}
// If the order state is terminal, reset the order id value.
if (status[2] == "Filled" || status[2] == "Cancelled" || status[2] == "Rejected")
longOrderId = string.Empty;
}
} // If the strategy has terminated reset the strategy id.
else if (longAtmId.Length > 0 && GetAtmStrategyMarketPosition(longAtmId) == Cbi.MarketPosition.Flat)
{
longAtmId = string.Empty;
isLongAtmStrategyCreated = false;
}
// Check for a pending short order.
if (shortOrderId.Length > 0)
{
// If the status call can't find the order specified, the return array length will be zero otherwise it will hold elements.
string[] status = GetAtmStrategyEntryOrderStatus(shortOrderId);
if (status.GetLength(0) > 0)
{
if( short_e==false)
{
AtmStrategyCancelEntryOrder(shortOrderId);
shortOrderId = string.Empty;
}
// If the order state is terminal, reset the order id value.
if (status[2] == "Filled" || status[2] == "Cancelled" || status[2] == "Rejected")
shortOrderId = string.Empty;
}
} // If the strategy has terminated reset the strategy id.
else if (shortAtmId.Length > 0 && GetAtmStrategyMarketPosition(shortAtmId) == Cbi.MarketPosition.Flat)
{
shortAtmId = string.Empty;
isShortAtmStrategyCreated = false;
}
// End check.
// Entries.
// **** YOU MUST HAVE AN ATM STRATEGY TEMPLATE NAMED 'AtmStrategyTemplate' CREATED IN NINJATRADER (SUPERDOM FOR EXAMPLE) FOR THIS TO WORK ****
// Enter long if Close is greater than Open.
if(long_e)
{
// Print("Long condition at : "+Time[0]);
// If there is a short ATM Strategy running close it.
if(shortAtmId.Length != 0 && isShortAtmStrategyCreated)
{
AtmStrategyClose(shortAtmId);
isShortAtmStrategyCreated = false;
}
// Ensure no other long ATM Strategy is running.
if(longOrderId.Length == 0 && longAtmId.Length == 0 && !isLongAtmStrategyCreated)
{
longOrderId = GetAtmStrategyUniqueId();
longAtmId = GetAtmStrategyUniqueId();
AtmStrategyCreate(OrderAction.Buy, OrderType.StopLimit, Open[3]+.25, Open[3], TimeInForce.Day, longOrderId, "ATR", longAtmId, (atmCallbackErrorCode, atmCallBackId) => {
//check that the atm strategy create did not result in error, and that the requested atm strategy matches the id in callback
if (atmCallbackErrorCode == ErrorCode.NoError && atmCallBackId == longAtmId)
isLongAtmStrategyCreated = true;
if (Close[0] < Open[0])
{
AtmStrategyChangeStopTarget(Open[3]+.25, Open[3], "p change", "longAtmId");
}
});
}
}
// Enter short if Close is less than Open. shortAtmId.Length != 0 && isShortAtmStrategyCreated &&
if(short_e)
{
// Print("Short condition at " + Time[0]);
// If there is a long ATM Strategy running close it.
if(longAtmId.Length != 0 && isLongAtmStrategyCreated)
{
AtmStrategyClose(longAtmId);
isLongAtmStrategyCreated = false;
}
// Ensure no other short ATM Strategy is running.
if(shortOrderId.Length == 0 && shortAtmId.Length == 0 && !isShortAtmStrategyCreated)
{
shortOrderId = GetAtmStrategyUniqueId();
shortAtmId = GetAtmStrategyUniqueId();
AtmStrategyCreate(OrderAction.SellShort, OrderType.StopLimit, Open[3]-.25, Open[3], TimeInForce.Day, shortOrderId, "ATR", shortAtmId, (atmCallbackErrorCode, atmCallBackId) => {
//check that the atm strategy create did not result in error, and that the requested atm strategy matches the id in callback
if (atmCallbackErrorCode == ErrorCode.NoError && atmCallBackId == shortAtmId)
isShortAtmStrategyCreated = true;
if (Close[0] > Open[0])
{
AtmStrategyChangeStopTarget(Open[3]-.25, Open[3], "p change", "shortAtmId");
}
});
}
}
Comment
-
Hello fgs092790,
The SampleATMStrategy included with NinjaTrader provides sample code that can give you a starting point.
You will not be able to call AtmStrategyChangeStopTarget() in the callback for AtmStrategyCreate() as the stop and target will not yet be working.
In a separate condition call GetAtmStrategyStopTargetOrderStatus() to ensure the stop order is working, and then you can call AtmStrategyChangeStopTarget() to modify the price of the working order.Chelsea B.NinjaTrader Customer Service
Comment
-
Hi Chelsea,
I look at the SampleATMStrategy and I copy paste part of the code which I tough was the right part that I needed to accomplished my price updated but I think I'm doing something wrong here is was i add to the code for the long side.
thanks so much for your help.
//MY // Check for a pending entry order
if (longOrderId.Length > 0)
{
string[,] orders = GetAtmStrategyStopTargetOrderStatus("longOrderId", "longAtmId");
// If the status call can't find the order specified, the return array length will be zero otherwise it will hold elements
if (orders.GetLength(0) > 0)
{
// Print out some information about the order to the output window
// Print("The entry order average fill price is: " + orders[0]);
// Print("The entry order filled amount is: " + orders[1]);
// Print("The entry order order state is: " + orders[2]);
// If the order state is terminal, reset the order id value
// if (orders == "Pending")
// orderId = string.Empty;
{
AtmStrategyChangeStopTarget(Open[3]+.25, Open[3], "p change", "longAtmId");
}
Comment
-
Hello fgs092790,
I am providing a link to the help guide for GetAtmStrategyStopTargetOrderStatus().
https://ninjatrader.com/support/help...rgetorders.htm
Note the method signature.
GetAtmStrategyStopTargetOrderStatus(string orderName, string atmStrategyId)
The first parameter is the order name.
In the example 'Target1' is the name of the profit target order.
If you want the stop order this would be 'Stop1'
Regarding the logic, print longOrderId.GetLength(0). Is this greater than 0?
Print orders[2], what is showing for the order state?Chelsea B.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Yesterday, 05:17 AM
|
0 responses
55 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
132 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
73 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
45 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
49 views
0 likes
|
Last Post
|

Comment