Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
Example of how ot use an ATM Strategy in NT8 strategy...
Collapse
X
-
Hello morrnel,
Thanks for your post.
Yes, included with the platform is the strategy SampleAtmStrategy which demonstrates calling an ATM template that is applied when the strategy entry has been filled, Please review the strategy in the Ninjascript editor as the code has been well commented to help clarify the requirements for running the example as well as how the methods and properties work. Once the ATM is active, you can manually move the profit and stop if you wish. Once the stop or profit is hit, the strategy will reset and perform the next entry. The example strategy will only place long orders based on this simple entry condition: Close[0] > Open[0].
A Ninjascript strategy that works with ATM uses special methods and properties, these can be found here: https://ninjatrader.com/support/help...gy_methods.htm
You can find a further example of using ATMs in a Ninjascript strategy in the NT user apps NinjaTrader8 Strategy section, here is a link to the example for your convenience: https://ninjatraderecosystem.com/use...tegy-reversal/ Please note: The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.Paul H.NinjaTrader Customer Service
- Likes 1
Comment
-
-
Hello jhontorres,
Thanks for your post and welcome to the NinjaTrader forums!
You are welcome to post here if your questions directly relate specifically to the thread topic, "Example of how to use an ATM Strategy in NT8 strategy...".
If they don't then please do start a new topic. To start a new topic you would need to navigate back to "forum" page here: https://ninjatrader.com/support/forum/forum the click on the particular forum that would best relate such as NinjaTrader 8 strategy or NinjaTrader 8 indicator. The forum will then show all of the topics in that forum. To create a new topic in that forum, click the light blue "topic button. I've attached an example of that.
Paul H.NinjaTrader Customer Service
Comment
-
yes so what happened is that i created a strategy with the atm example strategy and for some type of reason is only place buy order
Comment
-
Hello jhontorres,
Thanks for your reply.
The reason that it places only buy orders is that is what it was programmed to do, so it is operating as expected. The entry condition is simply if the position is flat to then place a buy order based on Close[0] > Open[0]. This is an example strategy to demonstrate the capability of using an ATM template with a Ninjascript strategy. It is not intended to be a useable/profitable strategy. In the code of the strategy, it explains how the special methods used work. You can read more about them here: https://ninjatrader.com/support/help...gy_methods.htm
Paul H.NinjaTrader Customer Service
Comment
-
-
Hello, I hope I can post my ATM issue here.
I developed a strategy based on the SampleATMReversal example. The strategy has two types of entries. The second type (TYPE 2) entry should only enter orders if the TYPE 1 entry status is FLAT, so only one order is active.
ISSUE: Sometimes the entries are made as expected (Type 2 after Type 1 is flat), and other times both entries are made in sequence, as shown in the attached screenshot. Again, TYPE 2 entry should only be activated if TYPE 1 is FLAT.
I've tried everything but cannot find the cause of the problem. May I please ask for your insight and help?
Thank you. BobPerez
Code:#region SHORT TYPE 1 REVERSAL entry bool sepCortoOk = some condition) ; double diffC = some condition; // If Entry Conditions Are Met if ((sepCortoOk && EmaPos == -1 && Close[0] < Open[0] && conDireccionC && EstadoC == 1 && condicion_Standard) ) { Draw.ArrowDown(this,"largo"+CurrentBar,false,0,High[0]+2*TickSize,Brushes.Yellow); Print(Convert.ToString(Times[0][0]) + "Diferencia corto: " + Convert.ToString((SMA1[0])-EMA1[0] )); EstadoC = 2; // Set variable to true to enter order condicion_C_Rev = true; } #endregion #region SHORT Continuation TYPE 2 entry shortFlat = (shortOrderId.Length == 0 && shortAtmId.Length == 0 && !isShortAtmStrategyCreated) ? true : false; /// I TRIED ALL THIS BUT DOES NOT SEEM TO RECOGNIZE THE FLAT STATUS OF TYPE 1 ENTRY //shortFlat = false; //if(shortAtmId.Length != 0) //{ //if (GetAtmStrategyMarketPosition(shortAtmId) == Cbi.MarketPosition.Flat) //if(!isShortAtmStrategyCreated) // shortFlat = true; //} //if (GetAtmStrategyMarketPosition("shortAtmId") == Cbi.MarketPosition.Flat) // Print("ATM Strategy position shortATMId is currently flat"); //if (isShortAtmStrategyCreated) // Print("isShortAtmStrategyCreated"); // Entry Conditions bool okCon = tradesCorto > 0 && Close[0] < Open[0] && Close[0] < Close[1] && conDireccionC && EmaPos ==-1 && EstadoC == 2 && isFlat && !condicion_C_Rev && ContCounterC == 0 && !isShortAtmStrategyCreated && shortFlat //&& GetAtmStrategyMarketPosition(shortAtmId) == Cbi.MarketPosition.Flat (GENERATES ERROR) && condicion_Standard; if (okCon && shortOrderId.Length == 0 && shortAtmId.Length == 0 && !isShortAtmStrategyCreated //&& shortOrderId.Length == 0 && shortAtmId.Length == 0 && !isShortAtmStrategyCreated) //&& sepCortoOk (DOES NOT WORK) ) { //condicion_C_Con = GetAtmStrategyMarketPosition(shortAtmId) == Cbi.MarketPosition.Flat ? true: false ; // Set entry variable to true condicion_C_Con = true; Draw.ArrowDown(this,"largo"+CurrentBar,false,0,High[0]+2*TickSize,Brushes.Aquamarine); //EstadoC = 0; } //} Print(Convert.ToString(Times[0][0]) + "condicion_C_Con " + condicion_C_Con ); #endregion // Enter short ( BASED ON SAMPLEATMREVERSAL) #region Enter short // Enter if entry conditions were met if(condicion_C_Rev || condicion_C_Czy || condicion_C_Con ) { // 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; } /*if(shortAtmId.Length != 0 && isShortAtmStrategyCreated && condicion_C_Rev) { AtmStrategyClose(shortAtmId); isShortAtmStrategyCreated = false; } */ // Ensure no other short ATM Strategy is running. if(shortOrderId.Length == 0 && shortAtmId.Length == 0 && !isShortAtmStrategyCreated) { Print(Convert.ToString(Times[0][0]) + "11111condicion_C_Con " + condicion_C_Con ); shortOrderId = GetAtmStrategyUniqueId(); shortAtmId = GetAtmStrategyUniqueId(); AtmStrategyCreate(OrderAction.SellShort, OrderType.Market, 0, 0, TimeInForce.Day, shortOrderId, "AtmStrategyTemplate", 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; // (these variables were inserted by me and are ok) tradeCounter++; tradesCorto ++; if(condicion_C_Czy) CzyCounterC++; if(condicion_C_Con) ContCounterC++; Print(Convert.ToString(Times[0][0]) + "tradesCorto " + tradesCorto ); } }); } } #endregion // End entries.
Last edited by bobperez; 11-19-2022, 06:21 PM.
Comment
-
Hello bobperez,
Thanks for your note.
When you say TYPE 1 should be flat, do you mean that the shortFlat bool evaluates to false?
If the condition to place the order is sometimes submitting when expected and not submitting the other other times, this means the condition to place that order is not becoming true.
To understand how the script is processing logic, you would need to add prints on the line above the condition(s) to place the order that prints out each variable used to place that order. This will allow you to compare the prints to see if the condition to place the order is evaluating as true or false and why that is.
Also, enable TraceOrders which will let us know if any orders are being ignored and not being submitted when the condition to place the orders is evaluating as true.
Below is a link to a forum post that demonstrates how to use prints to understand behavior.
https://ninjatrader.com/support/foru...121#post791121
Let us know if we may assist further.Brandon H.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by bortz, 11-06-2023, 08:04 AM
|
47 responses
1,602 views
0 likes
|
Last Post
by aligator
Today, 07:22 PM
|
||
Started by jaybedreamin, Today, 05:56 PM
|
0 responses
8 views
0 likes
|
Last Post
by jaybedreamin
Today, 05:56 PM
|
||
Started by DJ888, 04-16-2024, 06:09 PM
|
6 responses
18 views
0 likes
|
Last Post
by DJ888
Today, 05:12 PM
|
||
Started by Jon17, Today, 04:33 PM
|
0 responses
4 views
0 likes
|
Last Post
by Jon17
Today, 04:33 PM
|
||
Started by Javierw.ok, Today, 04:12 PM
|
0 responses
12 views
0 likes
|
Last Post
by Javierw.ok
Today, 04:12 PM
|
Comment