Decoupling Strategy and Indicators: A new paradigm for Ninjatrader - NinjaTrader | futures io social day trading
futures io futures trading


Decoupling Strategy and Indicators: A new paradigm for Ninjatrader
Updated: Views / Replies:5,524 / 25
Created: by vantojo Attachments:2

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 2  
 
Thread Tools Search this Thread
 

Decoupling Strategy and Indicators: A new paradigm for Ninjatrader

  #1 (permalink)
Elite Member
Neuquen, Argentina
 
Futures Experience: Intermediate
Platform: Ninja
Favorite Futures: CL, TF, 6S, NG, sometimes GC
 
Posts: 195 since Jul 2012
Thanks: 25 given, 39 received

Decoupling Strategy and Indicators: A new paradigm for Ninjatrader

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 :-)

Reply With Quote
The following user says Thank You to vantojo for this post:
 
  #2 (permalink)
Elite Member
Zurich Switzerland
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: IB
Favorite Futures: ES, 6E, CL
 
Posts: 404 since Sep 2009
Thanks: 64 given, 511 received

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:

https://futures.io/elite-circle/13607-btpa-thinkplanaction-4.html#post229027

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
The following user says Thank You to terratec for this post:
 
  #3 (permalink)
Elite Member
Berlin, Europe
 
Futures Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker/Data: Interactive Brokers
Favorite Futures: Keyboard
 
Fat Tails's Avatar
 
Posts: 9,653 since Mar 2010
Thanks: 4,226 given, 25,601 received
Forum Reputation: Legendary


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)
Elite Member
Neuquen, Argentina
 
Futures Experience: Intermediate
Platform: Ninja
Favorite Futures: CL, TF, 6S, NG, sometimes GC
 
Posts: 195 since Jul 2012
Thanks: 25 given, 39 received

to terratec

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

Reply With Quote
 
  #5 (permalink)
Elite Member
Zurich Switzerland
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: IB
Favorite Futures: ES, 6E, CL
 
Posts: 404 since Sep 2009
Thanks: 64 given, 511 received


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
The following user says Thank You to terratec for this post:
 
  #6 (permalink)
Elite Member
Neuquen, Argentina
 
Futures Experience: Intermediate
Platform: Ninja
Favorite Futures: CL, TF, 6S, NG, sometimes GC
 
Posts: 195 since Jul 2012
Thanks: 25 given, 39 received

a couple of questions

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

Reply With Quote
 
  #7 (permalink)
Elite Member
Houston,Tx
 
Futures Experience: Advanced
Platform: NinjaTrader
Broker/Data: Mirus Futures/Zen-Fire
Favorite Futures: TF
 
ThatManFromTexas's Avatar
 
Posts: 2,302 since Feb 2010
Thanks: 1,208 given, 4,293 received


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.


Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).

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)
Elite Member
Zurich Switzerland
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: IB
Favorite Futures: ES, 6E, CL
 
Posts: 404 since Sep 2009
Thanks: 64 given, 511 received


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)
Elite Member
Bala, PA, USA
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: Mirus, IB
Favorite Futures: SPY, Oil, Euro
 
monpere's Avatar
 
Posts: 1,858 since Jul 2010
Thanks: 300 given, 3,276 received

See my post about how I do this here:

https://futures.io/ninjatrader-programming/22282-triggercustomevent-another-running-object.html#post249887


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.


Last edited by monpere; August 13th, 2012 at 03:18 PM.
Reply With Quote
The following user says Thank You to monpere for this post:
 
  #10 (permalink)
Elite Member
Neuquen, Argentina
 
Futures Experience: Intermediate
Platform: Ninja
Favorite Futures: CL, TF, 6S, NG, sometimes GC
 
Posts: 195 since Jul 2012
Thanks: 25 given, 39 received

Thanks Guys...


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.

Reply With Quote

Reply



futures io > > > > Decoupling Strategy and Indicators: A new paradigm for Ninjatrader

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
NinjaTrader 7 Indicators YoderIII NinjaTrader Programming 4 July 24th, 2013 03:35 PM
Ninjatrader indicators without plots jstnbrg NinjaTrader 6 March 2nd, 2011 02:14 AM
How-to import indicators in NinjaTrader ZTR Help, Tutorials, and How-Tos 2 July 21st, 2010 02:06 PM
Fibonacci Indicators for NinjaTrader Fat Tails The Elite Circle 48 July 6th, 2010 11:58 AM
NinjaTrader 7 indicators Big Mike The Elite Circle 31 November 21st, 2009 03:00 PM


All times are GMT -4. The time now is 08:29 AM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts
Page generated 2017-12-15 in 0.16 seconds with 20 queries on phoenix via your IP 54.234.247.118