Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
atm
Collapse
X
-
Hello franatas,
Thank you for your post.
Do you mean that once the first entry is executed, one target and stop loss is placed, then once the second contract is entered the second target is placed and the stop loss moves to be a distance from the average entry between the two contracts? This wouldn't be possible using the ATM strategy settings; if you scale in/out of an existing active ATM strategy, stops and targets will be added/removed at the original prices based on the average entry when the ATM was initially opened. This could be possible using a custom NinjaScript strategy that uses logic to determine the profit target/stop loss prices, however.
If you have a programming background and are interested in developing this type of NinjaScript strategy yourself, we could provide you with links to samples that would help you write the script yourself. Otherwise, we can provide you with resources to find a programmer to create the script for you. Please let me know if either option interests you so I may follow up accordingly.
Thank you for using NinjaTrader.
-
To create programmatic protective orders based on manual entries, you would need to utilize the Account class in your script:You could subscribe to OrderUpdate events so the script can tell when an entry order is submitted:Originally posted by franatas View PostYes, I have some experience. but I looked at it briefly, the question is: how can I enter the manual entries and code to associate the tp and sl with the manual entry- https://ninjatrader.com/support/help...rderupdate.htm
- https://ninjatrader.com/support/help...rs_account.htm
Comment
-
private void OnAccountItemUpdate(object sender, AccountItemEventArgs e)
{
foreach (Order order in myAccount.Orders)
{
//if (OrdenEntrada.OrderAction == OrderAction.Buy)
//{
// OrdenEntrada.Name = "LARGOS";
//}
}
}
private void OnExecutionUpdate(object sender, Cbi.ExecutionEventArgs e)
{
OcO = Guid.NewGuid().ToString();
if (e.MarketPosition == MarketPosition.Long)
{
StopLoss = Instrument.MasterInstrument.RoundToTickSize(Positi on.AveragePrice - TiksStop * TickSize);
Target = Instrument.MasterInstrument.RoundToTickSize(Positi on.AveragePrice + TicksProfit * TickSize);
OrdenStop = myAccount.CreateOrder(Instrument, OrderAction.Sell, OrderType.StopMarket, TimeInForce.Day, 1, 0, StopLoss, OcO, "STOP", null);
OrdenProfit = myAccount.CreateOrder(Instrument, OrderAction.Sell, OrderType.Limit, TimeInForce.Day, 1, Target, 0, OcO, "PROFIT", null);
myAccount.Submit(new[] { OrdenStop });
myAccount.Submit(new[] { OrdenProfit });
OrdenProfit = null;
OrdenStop = null;
}
if (e.MarketPosition == MarketPosition.Short)
{
StopLoss = Instrument.MasterInstrument.RoundToTickSize(Positi on.AveragePrice + TiksStop * TickSize);
Target = Instrument.MasterInstrument.RoundToTickSize(Positi on.AveragePrice - TicksProfit * TickSize);
OrdenStop = myAccount.CreateOrder(Instrument, OrderAction.Buy, OrderType.StopMarket, TimeInForce.Day, 1, 0, StopLoss, OcO, "STOP", null);
OrdenProfit = myAccount.CreateOrder(Instrument, OrderAction.Buy, OrderType.Limit, TimeInForce.Day, 1, Target, 0, OcO, "PROFIT", null);
myAccount.Submit(new[] { OrdenStop });
myAccount.Submit(new[] { OrdenProfit });
OrdenProfit = null;
OrdenStop = null;
}
}
Where should I delete the orders after they have been used? It is as if they were saved and in the next order that I open it puts the new sl and tp and also the old ones
Comment
-
Hello franatas,
Thank you for your reply.
"Where should I delete the orders after they have been used? It is as if they were saved and in the next order that I open it puts the new sl and tp and also the old ones"
There is no concept of "deleting" the orders, however, you should manage the Order objects (such as OrdenEntrada, OrdenStop, and OrdenProfit) and you can set the object to null once the order is filled/canceled/rejected. The following add-on example uses the Account class and manages entry, stop loss, and profit target order objects:As for the error messages, these don't seem to be related to this topic. Please send a support email from the platform to open a support case where we may review your diagnostic files and assist you with the errors. You can do this by going to the Control Center-> Help-> Email Support. Ensuring 'Log and Trace Files' is checked will include these files. This is checked by default. Please provide a brief description of the errors you are receiving in the body of the email.
Thank you for your time and patience.
Comment
-
We will still need to review your diagnostic files to get a better understanding of the error message. Please go to Control Center-> Help-> Email Support. Include "ATTN Emily C" in the subject line and paste a link to this forum thread into the body of the email. Double-check that 'Log and Trace Files' is checked, then click Send.Originally posted by franatas View PostThis error is caused by the strategy, I already implemented the reset of the orders but I cannot find out where this error comes from, in the script output it does not mark anything and it only occurs with this script
I look forward to assisting you further.
Comment
-
private void OnAccountItemUpdate(object sender, AccountItemEventArgs e)
{
foreach (Order order in myAccount.Orders)
{
}
}
private void OnExecutionUpdate(object sender, Cbi.ExecutionEventArgs e)
{
OcO = Guid.NewGuid().ToString();
if (e.MarketPosition == MarketPosition.Long)
{
OrdenStop = myAccount.CreateOrder(Instrument, OrderAction.Sell, OrderType.StopMarket, TimeInForce.Gtc, 1, 0, 90, OcO, "STOP", null);
OrdenProfit = myAccount.CreateOrder(Instrument, OrderAction.Sell, OrderType.Limit, TimeInForce.Gtc, 1, 90.3, 0, OcO, "PROFIT", null);
myAccount.Submit(new[] { OrdenStop, OrdenProfit });
}
if (e.MarketPosition == MarketPosition.Short)
{
OrdenStop = myAccount.CreateOrder(Instrument, OrderAction.Buy, OrderType.StopMarket, TimeInForce.Gtc, 1, 0, 90.3, OcO, "STOP", null);
OrdenProfit = myAccount.CreateOrder(Instrument, OrderAction.Buy, OrderType.Limit, TimeInForce.Gtc, 1, 90, 0, OcO, "PROFIT", null);
myAccount.Submit(new[] { OrdenStop, OrdenProfit });
}
if ((OrdenProfit != null && (OrdenProfit.OrderState == OrderState.Filled || OrdenProfit.OrderState == OrderState.Rejected || OrdenProfit.OrderState == OrderState.Cancelled)) ||
(OrdenStop != null && (OrdenStop.OrderState == OrderState.Filled || OrdenStop.OrderState == OrderState.Rejected || OrdenStop.OrderState == OrderState.Cancelled)))
{
OrdenProfit = null;
OrdenStop = null;
}
}
One of the problems that arises for me is that I cannot identify when an order is input or not, this means that when I execute an sl or pt it places sl and pt again according to the execution of the sl or pt order
and the other is that if I initialize the account like this: lock (Account.All)
myAccount = Account.All.FirstOrDefault(a => a.Name == "Sim101"); I couldn't use it in another account, that's why I wanted to know how to solve this, I can think of a variable that changes according to the account selector in the properties configuration of the strategy panel, this would be possible
Comment
-
Hello franatas,
Thank you for your reply.
In order to troubleshoot the stop loss and profit target behavior, please add print statements to check your conditions and understand how the script is allowing for a stop loss and profit target to be submitted again based on the executions of your stops and targets. You will likely need to modify your conditions that submit stops and targets to be more specific about when they should be submitted or not. For more info on using prints to debug a script:
As for the accounts, you could consider creating a user input such as a string to select the account by name. Account.All is a collection of account objects and does not need to be specific to the account named "Sim101":
Please let us know if we may be of further assistance.
Comment
-
I just realized that I have the default ATM at 15 ticks of sl and tp, the fact is that when I activate it and change the parameters to 20 ticks what it does is put both, the one at 15 and the one at 20 and Now I really don't understand anything, I was sure that it was an ATM as a strategy where I activate it or not and where I can change the behaviors, but the fact is that it says sl and tp without being active
Comment
-
I am not aware of a way to set up a dropdown with the available accounts. As I mentioned, you could use a string input for an account name and then programmatically set it to that account based on the string. Otherwise, you could use an add-on approach and add an AccountSelector control and the script could subscribe based on the account selected in that selector from a window or tab:Originally posted by franatas View PostAs for the accounts, isn't there the possibility of creating a dropdown with the available accounts?It has to be manually setting the account, right?
You could also consider using the account selected from the Chart Trader:
You are using the term ATM strategy; this would specifically relate to ATM strategies in the Chart Trader and ATM strategy templates that could be used in a NinjaScript strategy:
Programmatically creating protective orders for stop loss and profit targets is not the same as an ATM strategy. What are the steps you are taking to "activate it and change the parameters to 20 ticks" and what are the results if you add print statements to print out the number of ticks in the parameters as well as prints each time an order is submitted by your script? Prints will add additional insight into how your script is behaving and help you to identify what parts of your script will need to be modified in order to achieve the desired behavior.
Thank you for your time and patience.
Comment
-
Good morning, I changed the approach radically and now I have this addons, the first order is placed correctly with all the chosen parameters, the problem is obtaining the entry price to adjust the second order
private void SubmitEntryOrder()
{
// el nombre de la orden debe ser Entrada o la orden se atascará en el estado de inicialización
//************************************************** ************************************COMPRAS******* ************************************************** *****************************//
//================================================== ================================================== ================================================== =============================//
if (Largos)
OrdenEntrada = submissionAccount.CreateOrder(instrumentSelector.I nstrument, OrderAction.Buy, OrderType.Market, OrderEntry.Automated, TimeInForce.Day, cantidadSeleccionada1, 0, 0, string.Empty, "LARGOS", Globals.MaxDate, null);
if (Cortos)
OrdenEntrada = submissionAccount.CreateOrder(instrumentSelector.I nstrument, OrderAction.Sell, OrderType.Market, OrderEntry.Automated, TimeInForce.Day, cantidadSeleccionada1, 0, 0, string.Empty, "CORTOS", Globals.MaxDate, null);
submissionAccount.Submit(new[] { OrdenEntrada });
if (cantidadSeleccionada2 > 0)
{
double precioSegundaOrden = PrecioEntrada - 10 * tickSize;
entryBuyMar****rder2 = submissionAccount.CreateOrder(instrumentSelector.I nstrument, OrderAction.Buy, OrderType.Limit, OrderEntry.Automated, TimeInForce.Day, cantidadSeleccionada2, precioSegundaOrden, precioSegundaOrden, string.Empty, "Entry", Globals.MaxDate, null);
submissionAccount.Submit(new[] { entryBuyMar****rder2 });
}
The problem is that here: double SecondOrderPrice = EntryPrice - 10 * tickSize; entry price is 0
I get the entry price variable from here:
PrecioEntrada = orderUpdateArgs.AverageFillPrice;
How can I get the entry price before executing the second order?
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
635 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
365 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
106 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
567 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
571 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment