Using Multiple Symbols and Timeframes in a Strategy

Questions about MultiCharts and user contributed studies.
flipflopper
Posts: 261
Joined: 28 Feb 2008
Has thanked: 2 times
Been thanked: 1 time

Using Multiple Symbols and Timeframes in a Strategy

Postby flipflopper » 11 Jan 2010

Is this possible?

Where can I learn about this?

flipflopper
Posts: 261
Joined: 28 Feb 2008
Has thanked: 2 times
Been thanked: 1 time

Postby flipflopper » 11 Jan 2010

I'll be a bit more specific.

I only want to trade one symbol. But in order to trade that symbol I need confirmation from another symbol.

I then need my entries and exits to be based on studies for the main symbol but those studies are based on different time frames.

Is this possible to do in Multicharts?

SUPER
Posts: 646
Joined: 03 Mar 2007
Has thanked: 106 times
Been thanked: 84 times

Postby SUPER » 11 Jan 2010

You can with Global Variables....there is considerable amount of stuff on GV on this forum....a simple search will open up interesting threads.

flipflopper
Posts: 261
Joined: 28 Feb 2008
Has thanked: 2 times
Been thanked: 1 time

Postby flipflopper » 11 Jan 2010

Is there any sample code of global variables being used? I did a google search and didn't turn up much.

For instance I want to have a global variable that shows the Advancing vs. Declining NYSE stocks. Then I want to use that number to to determine whether I go long or short in the ES.

I want to use a 30 minute 20 period moving average on the ES for entry and an 8 period 5 minute moving average on the ES for the exit.

I am looking to fully automate My trading strategies that have lots of multiple chart, multiple time frame, multiple symbol parameters. Is multicharts the best solution for coding this? I have read that Java or C are the best languages to automate trading strategies.

What would be considered Multicharts biggest competition besides TS?

Thanks to anyone for the help.

SUPER
Posts: 646
Joined: 03 Mar 2007
Has thanked: 106 times
Been thanked: 84 times

Postby SUPER » 12 Jan 2010

There is plenty on this forum....use the search facility and you will find many articles. I can only point you to the water hole.....you will have to do the rest.


http://forum.tssupport.com/viewtopic.php?t=2484

flipflopper
Posts: 261
Joined: 28 Feb 2008
Has thanked: 2 times
Been thanked: 1 time

Postby flipflopper » 12 Jan 2010

The more I read the more I think I can do this without Global variables.

Instead I can just add all the symbols/timeframes into the chart then reference them as Data2, Data3, etc.

flipflopper
Posts: 261
Joined: 28 Feb 2008
Has thanked: 2 times
Been thanked: 1 time

Postby flipflopper » 12 Jan 2010

Can you reference indicators in your signal?

Or do you have to copy the whole indicator into the body of the code of your signal?

flipflopper
Posts: 261
Joined: 28 Feb 2008
Has thanked: 2 times
Been thanked: 1 time

Postby flipflopper » 12 Jan 2010

Why doesn't this work?

variables:
ES30min(0);

ES30min = data1;



Why can't I use a variable to reference a data Id?

tcat
Posts: 175
Joined: 02 Feb 2008
Location: Lausanne, Switzerland
Has thanked: 9 times
Been thanked: 5 times

Postby tcat » 12 Jan 2010

You don't need GV to do this.

With data1 being defined as ES5min and data2 as ES30min, you would then code something like this:

inputs: length1, length2;
vars: 5min8periodMA(0), 30min20periodMA(0);

length1=8;
length2=20;

5min8periodMA = XAverage (Price,length1);
30min20periodMA(0)= XAverage (Price,length2)data2;

flipflopper
Posts: 261
Joined: 28 Feb 2008
Has thanked: 2 times
Been thanked: 1 time

Postby flipflopper » 12 Jan 2010

Great thanks.

But It looks like I cannot create a variable to represent data1 by itself?

tcat
Posts: 175
Joined: 02 Feb 2008
Location: Lausanne, Switzerland
Has thanked: 9 times
Been thanked: 5 times

Postby tcat » 12 Jan 2010

Did you try something like

valueX = price data2;

flipflopper
Posts: 261
Joined: 28 Feb 2008
Has thanked: 2 times
Been thanked: 1 time

Postby flipflopper » 12 Jan 2010

That seems to have worked.

Thanks. I'm a newbie at Easylanguage though I have done a bit of programming in my past. I'm just not too familiar with the syntax.

flipflopper
Posts: 261
Joined: 28 Feb 2008
Has thanked: 2 times
Been thanked: 1 time

Postby flipflopper » 12 Jan 2010

I noticed that it seems like the only bar price data points you can use are open, high, low, and close.

What if I want to know the last price. I don't care if the bar has closed or not. I just want the last price traded in real time.

flipflopper
Posts: 261
Joined: 28 Feb 2008
Has thanked: 2 times
Been thanked: 1 time

Postby flipflopper » 12 Jan 2010

Can someone give me an example of placing a limit order to buy the 30 minute 20 period moving average?

I tried to use the statement:

[IntraBarOrderGeneration = TRUE]

from the Easly Language reference guide but it doesn't seem to want to take it.

glen demarco
Posts: 35
Joined: 16 Nov 2009
Contact:

Postby glen demarco » 13 Jan 2010

flipflop,

Java, C++ and C#, C are far more complicated languages then easy language and in generel if you are not already a professional or have done extensive developement then thay would not be the right solution for you.


You use the datax parameter to indicated to you script what symbol to associate with data1 you do not assign a variable name to data1.

In you case in the chart load the 30 minute ES which will default to data1 then a reference to data1 in you script witll refer to the es 30 minute chart.

flipflopper
Posts: 261
Joined: 28 Feb 2008
Has thanked: 2 times
Been thanked: 1 time

Postby flipflopper » 13 Jan 2010

Thanks for the response. Upon further research I agree that Easylanguage is the right solution for me.

I will also have to research the datax parameter further. I want the symbols and timeframes to be hard coded in the script and it sounds like you are saying this can be done??

I have also purchased the TS book that TJ recommended because I really can't find good documentation on certain easy language features I want to use.

Intrabarpersist is one topic I have searched for and can't find any clear answers to.

Again one simple sounding task I want to accomplish is the following:

* Buy limit order at 30 minute 8 period moving average.

This sounds so simple yet seems so difficult to achieve.

glen demarco
Posts: 35
Joined: 16 Nov 2009
Contact:

Postby glen demarco » 13 Jan 2010

Here is a sample of code you are looking for.....let me know if the system makes money :>)

Code: Select all

{data1 = S&P 500 Futures -- five-minute continuous data}
{data2 = 10-Year-Treasury-Notes Futures -- five-minute continuous data}
{data3 = S&P 500 Futures -- daily closing prices using continuous data}
{data4 = 10-Year-Treasury-Notes Futures -- daily closing prices using continuous data}
{Note: times in EST}

inputs: entryFactor(3.0), exitFactor(5.0), length(30);
variables: interMarketSpread(0), histVolSP(0), histVolNotes(0), R(0),
weightSP(0.5), weightNotes(0.5), volBand(0);
if close[1] of data3 <> 0 and close[1] of data4 <> 0
then interMarketSpread = log(close of data1/close of data3) -
log(close of data2/close of data4);
if date <> date[1] and close[1] <> 0 and close[1] of data3 <> 0 and
close[1] of data4 <> 0
then begin
histVolSP = stdDev(log(close/close[1]),length) of data3;
histVolNotes = stdDev(log(close/close[1]),length) of data4;
R = coefficientR(log(close of data3/close[1] of data3),
log(close of data4/close[1] of data4), length);
if (square(weightSP) * square(histVolSP) + square(weightNotes) *
square(histVolNotes) + 2 * weightSP * weightNotes * R *
histVolSP * histVolNotes) > 0
then volBand = squareroot(square(weightSP) *
square(histVolSP) + square(weightNotes)*
square(histVolNotes) + 2 * weightSP * weightNotes *
R * histVolSP * histVolNotes);
end;
If time < 1700 or time > 2100
then begin
If interMarketSpread crosses above - entryFactor * volBand
then buy next bar on open;
If interMarketSpread crosses below entryFactor * volBand
then sell short next bar on open;
end;
If marketposition = 1
then begin
If interMarketSpread crosses above 0
then sell next bar on open;
If interMarketSpread crosses below -exitFactor * volBand
then sell next bar on open;
end;
If marketposition = -1
then begin
If interMarketSpread crosses below 0
then buy to cover next bar on open;
If interMarketSpread crosses above exitFactor * volBand
then buy to cover next bar on open;
end;

glen demarco
Posts: 35
Joined: 16 Nov 2009
Contact:

Postby glen demarco » 13 Jan 2010

Here is a sample of code you are looking for.....let me know if the system makes money :>). I'm not sure there is a way to "hard code" the symbols in the script.



{data1 = S&P 500 Futures -- five-minute continuous data}
{data2 = 10-Year-Treasury-Notes Futures -- five-minute continuous data}
{data3 = S&P 500 Futures -- daily closing prices using continuous data}
{data4 = 10-Year-Treasury-Notes Futures -- daily closing prices using continuous data}
{Note: times in EST}

inputs: entryFactor(3.0), exitFactor(5.0), length(30);
variables: interMarketSpread(0), histVolSP(0), histVolNotes(0), R(0),
weightSP(0.5), weightNotes(0.5), volBand(0);
if close[1] of data3 <> 0 and close[1] of data4 <> 0
then interMarketSpread = log(close of data1/close of data3) -
log(close of data2/close of data4);
if date <> date[1] and close[1] <> 0 and close[1] of data3 <> 0 and
close[1] of data4 <> 0
then begin
histVolSP = stdDev(log(close/close[1]),length) of data3;
histVolNotes = stdDev(log(close/close[1]),length) of data4;
R = coefficientR(log(close of data3/close[1] of data3),
log(close of data4/close[1] of data4), length);
if (square(weightSP) * square(histVolSP) + square(weightNotes) *
square(histVolNotes) + 2 * weightSP * weightNotes * R *
histVolSP * histVolNotes) > 0
then volBand = squareroot(square(weightSP) *
square(histVolSP) + square(weightNotes)*
square(histVolNotes) + 2 * weightSP * weightNotes *
R * histVolSP * histVolNotes);
end;
If time < 1700 or time > 2100
then begin
If interMarketSpread crosses above - entryFactor * volBand
then buy next bar on open;
If interMarketSpread crosses below entryFactor * volBand
then sell short next bar on open;
end;
If marketposition = 1
then begin
If interMarketSpread crosses above 0
then sell next bar on open;
If interMarketSpread crosses below -exitFactor * volBand
then sell next bar on open;
end;
If marketposition = -1
then begin
If interMarketSpread crosses below 0
then buy to cover next bar on open;
If interMarketSpread crosses above exitFactor * volBand
then buy to cover next bar on open;
end;


Return to “MultiCharts”