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 monpere with 7 posts (3 thanks)
    3. looks_3 terratec with 7 posts (3 thanks)
    4. looks_4 Fat Tails with 2 posts (0 thanks)
    1. trending_up 10,595 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

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

@vantojo
thanks for feedback
I see an advantage in splitting the data on the indicator side.
When I parse prices from different instruments then I have to deal with different length. ES 5618 / 6E 12302 (4 or 5 digits). And sometimes an instrument is in the zone where it flips from 4 to 5 and back from 5 to 4 digits. Such things do complicate my life, but I can live with them.
On the other hand when sending all information with one click, I am confident that everything is on the way.
Do you see other advantages?

@monpere and the rest of the world
Do you see any advantages/disadvantages with this way?

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Exit Strategy
NinjaTrader
Better Renko Gaps
The Elite Circle
How to apply profiles
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
29 thanks
Just another trading journal: PA, Wyckoff & Trends
25 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
23 thanks
GFIs1 1 DAX trade per day journal
18 thanks
  #12 (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


terratec View Post
@vantojo
thanks for feedback
I see an advantage in splitting the data on the indicator side.
When I parse prices from different instruments then I have to deal with different length. ES 5618 / 6E 12302 (4 or 5 digits). And sometimes an instrument is in the zone where it flips from 4 to 5 and back from 5 to 4 digits. Such things do complicate my life, but I can live with them.
On the other hand when sending all information with one click, I am confident that everything is on the way.
Do you see other advantages?

@monpere and the rest of the world
Do you see any advantages/disadvantages with this way?

Not sue I understand the question

Reply With Quote
  #13 (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



monpere View Post
Not sue I understand the question

@monpere
Sometimes it is a bit difficult to understand me as I am German thinking and writing...

We send one string with all the stuff we need. In the strategy we pick the substrings from that string to create the order and the order management stuff etc. It is all sent by one click.
public static string command = "";

vantojo does use for each thing an own variable and therefore does not have to pick substrings etc.
public static string Instrument = "";
public static string LongShort = "";
public static double Price = 0;
public static string ATM_Name = "My ATM";

I know what I (we?) do. His way could make some things easier or riskier or more CPU consuming or whatever. I am thinking about it (as I am always curious) and would like to have some inputs. Like chances with this way, risks etc.

Reply With Quote
  #14 (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


terratec View Post
@monpere
Sometimes it is a bit difficult to understand me as I am German thinking and writing...

We send one string with all the stuff we need. In the strategy we pick the substrings from that string to create the order and the order management stuff etc. It is all sent by one click.
public static string command = "";

vantojo does use for each thing an own variable and therefore does not have to pick substrings etc.
public static string Instrument = "";
public static string LongShort = "";
public static double Price = 0;
public static string ATM_Name = "My ATM";

I know what I (we?) do. His way could make some things easier or riskier or more CPU consuming or whatever. I am thinking about it (as I am always curious) and would like to have some inputs. Like chances with this way, risks etc.

I send one string to the strategy, and let the strategy parse it and figure out what to do with the command. The more parsing logic in the strategy, the more flexible I find it personally. I parse all strings using REGEX which is pretty powerful for string manipulation. You also only need to run 1 strategy per instrument, because the strategy compares the instrument in the command string to the instrument it is running, in order to consume or ignore the command. These are a sample of some of the command strings I generally send to the strategy.

"GLD, SellReverseNextBar 300 @ 156.71 +40-156.79~0=8 @8:-4 @40:+8 NoFillCancel_2"
"EURUSD, BuyNextBar @ 1.2325 $150+2R=1.25R~5Bars NoFillCancel_4"
"CL, BuyMarket 1 ATM_'FUT 10R' NoFillCancel_2"
"SPY, Chase 2"
"CL, Close"
"CL, Status"
"GLD, MoveTarget+1R"
"SPY, BarTrail 3"
"GLD, PauseStrategy"
etc.

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

I am finding the structure I posted to be adequate for my purposes to communicate trade signals from indicator to a strategy. I am not using this for anything other than sending the initial trade signal.

public class MyIndicator_Global
{
public static string Instrument = "";
public static string LongShort = "";
public static double Price = 0;
public static string ATM_Name = "My ATM";
}

Not being a C# guy, this is simple for me. And, personally, I don't like to parse strings much. I prefer to pass data in fixed structures.

With this, I can have several charts open, each with a different instrument, and then the same number of matching strategies running (in Strategy Analyzer), and the signals are not getting confused.

The first thing the strategy does is to see if the MyIndicator_Global.Instrument == Instrument.MasterInstrument.Name

If it matches then we have a signal for the strategy instrument, if not then the script returns. When there is a signal, the strategy processes it then immediately clears the global area so another indicator can write into it.

The disadvantage is that there is just one global communication area shared by multiple instruments. The only time there could be a conflict is if in the almost exact same moment two indicators write a signal into the common area. Unlikely but possible. In this case the first signal would be lost. (Or not, one would need to understand the code execution threading inside Ninja).

I would not write this type of code if it were being used to land a probe on Mars... :-)

My first preference was to have the indicator trigger an event in the matching strategy. This is what my longer term plans are, when I get time. Then there is a direct link between the indicator and the strategy.

Started this thread Reply With Quote
  #16 (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


vantojo View Post
I am finding the structure I posted to be adequate for my purposes to communicate trade signals from indicator to a strategy. I am not using this for anything other than sending the initial trade signal.

public class MyIndicator_Global
{
public static string Instrument = "";
public static string LongShort = "";
public static double Price = 0;
public static string ATM_Name = "My ATM";
}

Not being a C# guy, this is simple for me. And, personally, I don't like to parse strings much. I prefer to pass data in fixed structures.

With this, I can have several charts open, each with a different instrument, and then the same number of matching strategies running (in Strategy Analyzer), and the signals are not getting confused.

The first thing the strategy does is to see if the MyIndicator_Global.Instrument == Instrument.MasterInstrument.Name

If it matches then we have a signal for the strategy instrument, if not then the script returns. When there is a signal, the strategy processes it then immediately clears the global area so another indicator can write into it.

The disadvantage is that there is just one global communication area shared by multiple instruments. The only time there could be a conflict is if in the almost exact same moment two indicators write a signal into the common area. Unlikely but possible. In this case the first signal would be lost. (Or not, one would need to understand the code execution threading inside Ninja).

I would not write this type of code if it were being used to land a probe on Mars... :-)

My first preference was to have the indicator trigger an event in the matching strategy. This is what my longer term plans are, when I get time. Then there is a direct link between the indicator and the strategy.

This is pretty much what I do. I also have one communication variable since I trade manually, and there would never be an instance where I would manually enter 2 trades at the exact same moment in time. This is pretty much a direct link into the strategy since the variable you call global is a memory structure accessible by both indicator and strategy. I've had this code working for years, no issues, it is pretty robust.

If you want to have multiple indicators and strategies talking at the same time, you would have to turn the message communication structure into a list queue, and every indicator and strategy will put and scan the queue for their own messages. That way there is no collision of messages.

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

the other advantage of using a structure is that you can have things in the structure that are not strings....

int
double
bool

(don't know if a structure is the right word)

then you don't have to parse and also don't have to do data type conversions

=============

question....in C#, can a queue contain a structure composed of several data types, as my example?

Started this thread Reply With Quote
  #18 (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


vantojo View Post
the other advantage of using a structure is that you can have things in the structure that are not strings....

int
double
bool

(don't know if a structure is the right word)

then you don't have to parse and also don't have to do data type conversions

=============

question....in C#, can a queue contain a structure composed of several data types, as my example?

Yes it can.

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

good!

Started this thread Reply With Quote
  #20 (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
the other advantage of using a structure is that you can have things in the structure that are not strings....

int
double
bool

(don't know if a structure is the right word)

then you don't have to parse and also don't have to do data type conversions

For a constant (feedback) dataflow like actual account size, risk position value, AvgPrice, filled Quantity etc. it has also some advantages with this structure. But can also be done the other way.

By the way... The constant bidirectional flow has the side effect that you don't need to care about wakeup the strategy.

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