Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Decoupling Strategy and Indicators: A new paradigm for Ninjatrader
I'm a retired client server developer with experience in an event driven system with large database behind it. Alot of work with SQL Server back end, and some Oracle. Mostly large systems: corporate, financial applications.
I'm not an experienced C# developer, but can knock out some simple Ninja strategies and indicators.
I also am a Chart Trader / Futures... I look for visual patterns and trade those, on the chart. I don't use the DOM.
I am wanting to use a Strategy to enhance / extend my manual Chart Trader trading, not a Strategy to run by itself. I want to see the orders the Strategy submits, and be able to exit them with Chart Trader.
Ninja Archtecture
I am frustrated with the Ninja design where if there is a strategy on the chart, you cannot see the active orders on that chart, because Chart Trader cannot be active on a chart with a strategy. And, since Chart Trader is not active you cannot close (on the chart) any orders or active positions on that chart.
The software developer inside resists the Ninja architecture what requires that the indicator is instantiated inside a strategy and use exposed variables, et cetera as a method of communication between the two. It seems this requires that the strategy constantly is polling the indicator for changes in status or signal.
I would much rather have the Strategy and Indicator be decoupled, with a method of communication between them.
Here is my idea, perhaps it is not feasible, but if it was it would work for my purposes, and could build a foundation for others to expand upon, in many wonderful and exciting ways. For example, to have an indicator send a signal to your trading buddy's computer half way across the world.
I don't have the expertise to code this, but for sure could use code stubs and bring them into my code.
For a local machine, the idea is to have a strategy running in the strategy analyzer and the indicator running on a chart with chart trader.
I WOULD HAVE THE STRATEGY SUBMIT AN ATM ORDER, AND THUS AN ORDER OR POSITION COULD BE EXITED WITH CHART TRADER WITHOUT MESSING UP THE STRATEGY, AS THE STRATEGY IS ONLY USED TO SUBMIT THE ORDER, NOT TO MANAGE THE TRADE.
A method of communication is established. perhaps TCP on 127.0.0.1 or Named Pipes.
The indicator sends signals through this communication link to the Strategy. For example, Buy Limit at 102.45
Once there was a trade in play, the Strategy would not act on any other signals.
Perhaps there are other ways for the Indicator to communicate with the Strategy. I don't know if it is possible in NinjaTrader for an indicator trigger events (methods) in a decoupled strategy, and pass data during that trigger.
However, TCP would allow a much broader application, across a LAN or WAN.
I do have some questions about the overhead of a TCP Listener, et cetera, and whether this would actually work.
As an inspiration for your own stuff I created this tool on my way from the stuff earlier in this thread toward strategy only.
The indicator sends commands to the strategy to enter the trade with stop orders and manage the stops. The trades are visible …
This example is very basic and simple and uses ATM strategies. It is also possible to send stop and target levels and let the strategy do the money management, and then manage the trade in the charttrader etc.
(1) Generate an automated strategy via the SuperDOM (set ATM parameters such as profit targets, stop loss, breakeven stop and trailing stop
(2) Save the strategy under a name, such as Test_Strategy
(3) Code an automated strategy via the strategy editor. Use AtmStrategyCreate() to enter orders. For more details please see NinjaTrader help file. Save that strategy.
(4) Connect NinjaTrader to a data feed.
(5) Add the strategy to a NinjaTrader chart and activate it. As it is an ATM strategy the execution will not be shown on the chart. You can minimize that chart, as it is only needed to start the strategy.
(6) Open another chart with the chart trader, and you will see the position and stop and profit orders that have been created by the automated strategy.
(7) Now you can manually manage the orders that were submitted by the strategy.
You can write custom buttons on chart trader that cause an indicator to pass an order to a strategy. When the order is filled it triggers an ATM strategy to handle stops, trailing stops , targets, breakevens etc.
You can drag the stops and targets around , NinjaTrader will keep track of everything and you can still use the NinjaTrader Close button to close everything out.
I'm just a simple man trading a simple plan.
My daddy always said, "Every day above ground is a good day!"
First I am not a programmer. I have my concepts and pick some code that could work for me, and then I am changing it my way. So I can not explain much. I am just solving the problems.
In the mentioned thread there are following posts about a bit of StrategyGlobal....
As you see in the example above, I send an order command with the instrument name, the ATM strategy name and the timeframe. You can add whatever you want to say to the strategy like SLprice target1, target2, BE yes/no, move SL ... You just have to tell the strategy what she has to listen for...
You don't need that. You have to start a strategy for each instrument. Then you can switch in the indicator chart timeframes and instruments. (As long as you send those facts with your commands).
If you have more than one indicator chart, then you have to take care that the declaration public class StrategyGlobal {public static string command = ""; does only exist once.
Don't know. My indicaor is always on and then I start the strategy. But it sounds logic that the indi should run first.
You could also run
public class StrategyGlobal {
public static string command = "";
as a standalone indicator or perhaps outside strategy/indicator.
I have to think about what could cause which problem...
This is the way I trade exclusively for the past 4 years. All the buttons on the chart are from an indicator. Every button I click sends a text command to the strategy, and the strategy performs that command. Fore example, Pressing the 'Next Bar' …
In your Strategy put this code:
public class TradeManagerGlobal {
public static string command = "";
}
...
if ( TradeManagerGlobal.command.Contains("BuyLimit")) ) {
... Parse the string
... Execute commands
TradeManagerGlobal.command=""; // Clear the command, or send back results
}
I also add a 1 second wake up timer to my strategy to insure that the strategy execute any command within 1 second of a button press on the chart.
And of course the strategy can communicate any results back to the strategy using the same TradeManagerGlobal.command string, or different similarly defined string variable. Anything can communicate with that strategy, even a chart for a different instrument, if desired. The trade targets also appear on all charts for that instrument, and can be also managed manually.
public class MyIndicator_Global
{
public static string Instrument = "";
public static string LongShort = "";
public static double Price = 0;
public static string ATM_Name = "My ATM";
}
This way I do not have to parse a string in the Strategy.
In the strategy I make sure the Instrument matches the Global Instrument from the Indicator
If I have more than one indicator with a global, each indicator can have its own global public name
Since this is intended to augment manual trading, it is unlikely that I would have a bunch of these running...