NexusFi: Find Your Edge


Home Menu

 





Decoupling Strategy and Indicators: A new paradigm for Ninjatrader


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one vantojo with 10 posts (1 thanks)
    2. looks_two terratec with 7 posts (3 thanks)
    3. looks_3 monpere with 7 posts (3 thanks)
    4. looks_4 Fat Tails with 2 posts (0 thanks)
    1. trending_up 10,375 views
    2. thumb_up 7 thanks given
    3. group 10 followers
    1. forum 25 posts
    2. attach_file 2 attachments




 
Search this Thread

Decoupling Strategy and Indicators: A new paradigm for Ninjatrader

  #1 (permalink)
 vantojo 
Vilcabamba, Ecuador
 
Experience: Intermediate
Platform: Ninja
Trading: NQ, UB
Posts: 204 since Jul 2012

Hello,

Background:

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.

-------------------------------------------------------------------------------------------------------------------------------------

Well, if something like this were robust, you can imagine the possibilities.

Any takers?

Feel free to comment, offer suggestions, or other solutions.

Thank you.


PS. Of course, we won't wait for a solution from NinjaTrader :-)

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
Are there any eval firms that allow you to sink to your …
Traders Hideout
Exit Strategy
NinjaTrader
Futures True Range Report
The Elite Circle
 

  #2 (permalink)
 terratec 
Zurich Switzerland
 
Experience: Intermediate
Platform: NinjaTrader
Broker: IB
Trading: ES, 6E, CL
Posts: 403 since Sep 2009
Thanks Given: 64
Thanks Received: 515

I don't know how to send signals around the world to the strategy of another computer. But from an indicator to a strategy on a local machine:



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.

Reply With Quote
Thanked by:
  #3 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102


Try the following:


(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.

Is this what you wanted to do?


Reply With Quote
  #4 (permalink)
 vantojo 
Vilcabamba, Ecuador
 
Experience: Intermediate
Platform: Ninja
Trading: NQ, UB
Posts: 204 since Jul 2012

Hi,

Yes, this sounds like what I want to do...will be interesting to see how the messages are sent between the indicator and the strategy.

Will look at it this week and get back.

Thanks

Started this thread Reply With Quote
  #5 (permalink)
 terratec 
Zurich Switzerland
 
Experience: Intermediate
Platform: NinjaTrader
Broker: IB
Trading: ES, 6E, CL
Posts: 403 since Sep 2009
Thanks Given: 64
Thanks Received: 515


vantojo View Post
Yes, this sounds like what I want to do...will be interesting to see how the messages are sent between the indicator and the strategy.

You send it with the StrategyGlobal.command:
 
Code
StrategyGlobal.command = "BuyStopLast" + Convert.ToString (instrument) + Convert.ToString (strat) + Convert.ToString (BarsPeriod.Value);
And read it out with:
 
Code
					
if ( StrategyGlobal.command.Contains("BuyStopLast" + Convert.ToString (instrument)))	// buy stop above last bar		
	{   
	if (orderId.Length != 0)
		{
		if (entryprice > Highs[timeframe] [1]+1*TickSize)
			{
			      entryprice = Highs[timeframe] [1]+1*TickSize;
			      AtmStrategyChangeEntryOrder(entryprice, entryprice, orderId);
			}
		}
		else
		{.....................
And with StrategyGlobal.command.Substring(x,y) you can read out every part of the string like stop price, targets, quantity etc.

Reply With Quote
Thanked by:
  #6 (permalink)
 vantojo 
Vilcabamba, Ecuador
 
Experience: Intermediate
Platform: Ninja
Trading: NQ, UB
Posts: 204 since Jul 2012

yes, I see how it is coded, thank you....

I'm looking at bTPAM, yes, this would work inside the running Ninja instance, not across a LAN or WAN. Good enough for me, for my current need.

not being a C# coder, I have these questions

What is the scope of this declaration in the indicator?

public class StrategyGlobal {
public static string command = "";

Is it for all scripts running in Ninjatrader?

How do you make sure the .command is matching the correct instrument / strategy / indicator?

Or, can only one Strategy be running at a time with this method?

Perhaps it could be something like this? (for CL Oil)

public class StrategyGlobal {
public static string CLcommand = "";

And, then, perhaps the indicator needs to be launched before the strategy? Otherwise there is no reference to StrategyGlobal.command?

By the way, this is the first time I've seen methods bound by a region. I'm going to start doing that in my code as it really helps. Thank you.

PS. This thread still open to replies from TCP / Named Pipes Gurus....initially on local loop 127.0.0.1

Started this thread Reply With Quote
  #7 (permalink)
 
ThatManFromTexas's Avatar
 ThatManFromTexas 
Houston,Tx
 
Experience: Advanced
Platform: NinjaTrader
Broker: Mirus Futures/Zen-Fire
Trading: TF
Posts: 2,265 since Feb 2010
Thanks Given: 1,206
Thanks Received: 4,348


vantojo View Post


Feel free to comment, offer suggestions, or other solutions.

Thank you.

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!"
Reply With Quote
  #8 (permalink)
 terratec 
Zurich Switzerland
 
Experience: Intermediate
Platform: NinjaTrader
Broker: IB
Trading: ES, 6E, CL
Posts: 403 since Sep 2009
Thanks Given: 64
Thanks Received: 515


vantojo View Post
not being a C# coder, I have these questions

What is the scope of this declaration in the indicator?

public class StrategyGlobal {
public static string command = "";

Is it for all scripts running in Ninjatrader?

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....


vantojo View Post
How do you make sure the .command is matching the correct instrument / strategy / indicator?

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...


vantojo View Post
Or, can only one Strategy be running at a time with this method?

Perhaps it could be something like this? (for CL Oil)

public class StrategyGlobal {
public static string CLcommand = "";

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.


vantojo View Post
And, then, perhaps the indicator needs to be launched before the strategy? Otherwise there is no reference to StrategyGlobal.command?

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...

Reply With Quote
  #9 (permalink)
 
monpere's Avatar
 monpere 
Bala, PA, USA
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Mirus, IB
Trading: SPY, Oil, Euro
Posts: 1,854 since Jul 2010
Thanks Given: 300
Thanks Received: 3,371

See my post about how I do this here:




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
}

In your Indicator put this code:

TradeManagerGlobal.command = "BuyLimit CL 09-12 @ 92.40 Stop=-10 Target=+20 BE=+10.... etc., etc ";

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.

Reply With Quote
Thanked by:
  #10 (permalink)
 vantojo 
Vilcabamba, Ecuador
 
Experience: Intermediate
Platform: Ninja
Trading: NQ, UB
Posts: 204 since Jul 2012


Your ideas were helpful.

Here is what I did

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...

Only have two eyes, and two hands...

Thanks again.

Started this thread Reply With Quote





Last Updated on September 4, 2012


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts