// Condition set 1 if (CrossAbove(TSIchimoku(9, 26, 52).TenkanSen, TSIchimoku(9, 26, 52).KijunSen, 1)) { AtmStrategyCreate(OrderAction.Buy, OrderType.Market, 0, 0, TimeInForce.Day, GetAtmStrategyUniqueId(), "CL-Ichi", GetAtmStrategyUniqueId()); } // Condition set 2 if (CrossBelow(TSIchimoku(9, 26, 52).TenkanSen, TSIchimoku(9, 26, 52).KijunSen, 1)) { AtmStrategyCreate(OrderAction.Sell, OrderType.Market, 0, 0, TimeInForce.Day, GetAtmStrategyUniqueId(), "CL-Ichi", GetAtmStrategyUniqueId()); } }
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
AtmStrategyCreate going into endless loop
Collapse
X
-
AtmStrategyCreate going into endless loop
So I created a new ATM strategy within a strategy, but upon trigger, it goes into an endless loop creating unlimited ATM orders.
Code:Tags: None
-
Hello rdavido,
Thank you for your post.
ATM Strategy methods are not affected by settings such as EntriesPerDirection. The SampleAtmStrategy that is available in your installation of NinjaTrader under Tools > Edit NinjaScript > Strategy > SampleAtmStrategy, demonstrates how to limit entries through using set string variables to hold atmStrategyIds and orderIds to check if an order has been submitted already.
If you have any questions please let me know.
-
-
Hello rdavido,
Thank you for your response.
Your code shows that you check that the Length of the two Ids are 0 then submit an EnterLong() and check if your position is Long before you submit an ATM Strategy.
However, on the next pass the Length is not 0 and the position update would not occur during OnBarUpdate() processing.
Try checking the cross above and below conditions outside of checking the Length of the Ids and then test the strategy again.
For example:
Code:// Condition set 1 if (CrossAbove(TSIchimoku(9, 26, 52).TenkanSen, TSIchimoku(9, 26, 52).KijunSen, 1)) EnterLong(DefaultQuantity, "Long"); if (orderId.Length == 0 && atmStrategyId.Length == 0) {
Comment
-
Ok, now my orders are going through again, but none of the conditions are met to initiate the ATM order alongside my EnterLong. Even adjusting the code doesn't help. We're close. Before it was looping ATM strategies, now it's not initializing it.
Code:if (CrossAbove(TSIchimoku(9, 26, 52).TenkanSen, TSIchimoku(9, 26, 52).KijunSen, 1)) if (orderId.Length == 0 && atmStrategyId.Length == 0) EnterLong(DefaultQuantity, "Long"); if (Position.MarketPosition == MarketPosition.Long) AtmStrategyCreate(OrderAction.Buy, OrderType.Market, 0, 0, TimeInForce.Day, orderId, "CL-Ichi", atmStrategyId);{
Comment
-
Hi rdavido,
The bracket syntax is getting a bit confusing here.
The following is one condition and one action that is independent of the next condition and action:
if (CrossAbove(TSIchimoku(9, 26, 52).TenkanSen, TSIchimoku(9, 26, 52).KijunSen, 1))
if (orderId.Length == 0 && atmStrategyId.Length == 0)
EnterLong(DefaultQuantity, "Long");
Then the Atm Strategy is created if the position is long:
if (Position.MarketPosition == MarketPosition.Long)
AtmStrategyCreate(OrderAction.Buy, OrderType.Market, 0, 0, TimeInForce.Day, orderId, "CL-Ichi", atmStrategyId);{
There is a weird opening curly brace that follows this {
This curly brace and the matching closing curly brace are likely useless as they are not associated with the condition before it.
The likely issue is if (Position.MarketPosition == MarketPosition.Long).
If you are using Atm Strategies in your code, these orders will not affect the NinjaScript Strategy's position. The script will not see these orders because the script is no longer placing these orders.
By calling AtmStrategyCreate, you have asked NinjaTrader outside of your script to place an order and automatically handle this with the Atm Strategy logic that is part of the core application.
At this point the orders are hidden from your script and you will need to check on the status as well as manage orders through Atm Strategy methods.
The method to check the position is GetAtmStrategyMarketPosition().
Below is a link to the help guide on GetAtmStrategyMarketPosition().
http://www.ninjatrader.com/support/h...etposition.htmChelsea B.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by johntraderuser2, Today, 02:34 AM
|
0 responses
6 views
0 likes
|
Last Post Today, 02:34 AM | ||
Started by IanS00, 03-27-2024, 11:24 AM
|
2 responses
12 views
0 likes
|
Last Post Today, 02:00 AM | ||
Started by Mariawilcoxi, Today, 01:32 AM
|
0 responses
4 views
0 likes
|
Last Post
by Mariawilcoxi
Today, 01:32 AM
|
||
Started by gleichnerany, Today, 01:17 AM
|
0 responses
5 views
0 likes
|
Last Post
by gleichnerany
Today, 01:17 AM
|
||
Started by WHICKED, 03-27-2024, 12:33 PM
|
4 responses
47 views
0 likes
|
Last Post Today, 12:28 AM |
Comment