Multitimeframe Signals ADE, EL_Collections, etc.

Questions about MultiCharts and user contributed studies.
Jonny473
Posts: 68
Joined: 04 Apr 2016
Has thanked: 5 times
Been thanked: 1 time

Multitimeframe Signals ADE, EL_Collections, etc.

Postby Jonny473 » 27 Nov 2016

Hi,

as I thought for quiet some time that multitimeframe strategies can be accessed by defining data 2,3, xx. I always wondered why the strategy/signal gives false/ less signals back. Always thought the mistake might lie somewhere else, but now I know that Multicharts is just not able to process it.

So just to give you an example, lets look at the following, easy but effective strategy (at least when I look at the indicators and trade the signals manually):

inputs: F1(6),S1(10),L1(3),F2(6),S2(10),L2(3),F3(270),S3(585),L3(203),
T1(0600),T2(1410),Y(90);
variables: MACD1(0),MACD2(0),MACD3(0),OldMA(0),MACDBuy(9999),MACDSS(-9999);


MACD1=MACD(Close of Data1,F1,S1);
MACD1=XAverage(MACD1,L1); //Exit off of this.
MACD2=MACD(Close of Data2,F2,S2)Data2;
MACD2=XAverage(MACD2,L2); //Enter off of this.
MACD3=MACD(Close of Data3,F3,S3)Data3;


if CurrentBar>2 and Time>T1 and Time<T2 and MarketPosition<=0
and MACD2[1]<0 and MACD2[1]<MACD2[2] and MACD2>MACD2[1] and MACD3>MACD3[1]
and AverageFC(Close of Data2,Y)>OldMA then begin
Buy next bar at market;
MACDBuy=MACD2;
end;

If MarketPosition=1 and MACD1[1]>0 and MACD1<MACD1[1] then Sell next bar at market;


If CurrentBar>2 and Time>T1 and Time<T2 and MarketPosition>=0
and MACD2[1]>0 and MACD2[1]>MACD2[2] and MACD2<MACD2[1] and MACD3<MACD3[1]
and AverageFC(Close of Data2,Y)<OldMA then begin
SellShort next bar at market;
MACDSS=MACD2;
end;

If MarketPosition=-1 and MACD1[1]<0 and MACD1>MACD1[1] then BuyToCover next bar at market;


SetStopLoss(400);

SetExitOnClose;

OldMA=AverageFC(Close of Data2,Y);

The timeframes used should be like this data1<data2<data3
Just setting data1- data3 does not seem to work; thats why I did some more research and came across EL Collections, Global Variables and ADE. Gloval Variables do not seem to work in Backtesting and Optimization, at least thats what I read I did not try it out. Thats why I installed EL Collections and ADE from here:

https://www.multicharts.com/discussion/viewtopic.php?f=5&t=9870
http://www.traderslaboratory.com/forums/trading-indicators/5934-ade-all-data-everywhere-easylanguage-2.html

I think I installed it correctly as the ADE Save Info Test and ADE Plot Info Test works correctly.
________________________
ADE Save Info Test:

[LegacyColorValue = TRUE];

Inputs:
UseFile(ADE.UseFile), // default UseFile is returned by ADE.UseFile function
ADXLen(14),
RSILen(14),
StochLen(14);

Vars:
Class("BarInfoTest"), // class name for our test data
InfoMap(MapSN.New), // we will use this map to pass data to ADE.PutBarInfo
WriteOk(true),
oFastK(0),
oFastD(0),
oSlowK(0),
oSlowD(0);

// If UseFile is true, load any previously stored data from the file on the first bar.
if CurrentBar = 1 and UseFile then
Value1 = ADE.OpenMap(Class, GetSymbolName, ADE.BarInterval);

// Calculate stochastics
Value1 = Stochastic(High, Low, Close, StochLen, 3, 3, 1, oFastK, oFastD, oSlowK, oSlowD);

// Store the indicator values in InfoMap so that we can pass it to ADE.PutBarInfo
Value1 = MapSN.Put(InfoMap, "ADX", ADX(ADXLen));
Value1 = MapSN.Put(InfoMap, "RSI", RSI(Close, RSILen));
Value1 = MapSN.Put(InfoMap, "SlowK", oSlowK);
Value1 = MapSN.Put(InfoMap, "SlowD", oSlowD);

// Store the data for this symbol and bar interval.
// ADE.PutBarInfo will copy the information from our InfoMap into the appropriate DataMap.
Value1 = ADE.PutBarInfo(Class, GetSymbolName, ADE.BarInterval, ADE.BarID, InfoMap);

// If UseFile is true, save the data to the file on the last bar.
if LastBarOnChart and BarStatus(1) = 2 and UseFile and WriteOk then begin
Value1 = ADE.SaveMap(Class, GetSymbolName, ADE.BarInterval);
WriteOk = false; // prevent repeated writes on new bars
end;

Plot1(0); // include a Plot statement so we can use this indicator in RadarScreen[LegacyColorValue = TRUE];

_______________________________
ADE Plot Info Test:

[LegacyColorValue = TRUE];

Inputs:
Interval(ADE.Daily), // number of minutes, or ADE.Daily, ADE.Weekly, ADE.Monthly
UseFile(ADE.UseFile); // default UseFile is returned by ADE.UseFile function

Vars:
Class("BarInfoTest"), // class name for our test data
InfoMap(MapSN.New), // we will use this map to retrieve data with ADE.GetBarInfo
MyADX(0),
MyRSI(0),
MySlowK(0),
MySlowD(0);

// If UseFile is true, load any previously stored data from the file on the first bar.
if CurrentBar = 1 and UseFile then
Value1 = ADE.OpenMap(Class, GetSymbolName, Interval);

// Retrieve the data for this symbol and bar interval.
// ADE.GetBarInfo will copy the information from the appropriate DataMap into our InfoMap.
Value1 = ADE.GetBarInfo(Class, GetSymbolName, Interval, ADE.BarID, InfoMap);

// Fetch the values from the InfoMap into variables
MyADX = MapSN.Get(InfoMap, "ADX");
MyRSI = MapSN.Get(InfoMap, "RSI");
MySlowK = MapSN.Get(InfoMap, "SlowK");
MySlowD = MapSN.Get(InfoMap, "SlowD");

// Plot them
Plot1(MyADX, "ADX");
Plot2(MyRSI, "RSI");
Plot3(MySlowK, "SlowK");
Plot4(MySlowD, "SlowD");

So now I need to wrap around my MACD strategy mentioned above around the ADE Save and Plot code. Also the strategy shall not plot anything it should buy and sell accordingly. Does anybody have a solution?


I also approached Multicharts with that. Unfortunately they only provided me some links and told me ADE, EL Collections is nothing they support (they might do for ~100hr/programming costs). As mentioned by various users already I am also wondering why Multicharts is not able to implement that function in their engine and was not aware that this does not exist.
Dont get me wrong I still think MC is a good product, but sometimes I am wondering about their answers (also highly depends on who you are talking to on the support side).
I appreciate any kind of help, advice.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Multitimeframe Signals ADE, EL_Collections, etc.

Postby TJ » 27 Nov 2016


User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Multitimeframe Signals ADE, EL_Collections, etc.

Postby JoshM » 27 Nov 2016

Does anybody have a solution?
What's the problem here? Is it..
I always wondered why the strategy/signal gives false/ less signals back. Always thought the mistake might lie somewhere else, but now I know that Multicharts is just not able to process it.
..or is it..
I did some more research and came across EL Collections, Global Variables and ADE. Gloval Variables do not seem to work in Backtesting and Optimization, at least thats what I read I did not try it out. Thats why I installed EL Collections and ADE from here:
But topics are quite different, so let us know what you seek help with.

Jonny473
Posts: 68
Joined: 04 Apr 2016
Has thanked: 5 times
Been thanked: 1 time

Re: Multitimeframe Signals ADE, EL_Collections, etc.

Postby Jonny473 » 27 Nov 2016

Thanks TJ for the advice marking all signals accordingly:

as I thought for quiet some time that multitimeframe strategies can be accessed by defining data 2,3, xx. I always wondered why the strategy/signal gives false/ less signals back. Always thought the mistake might lie somewhere else, but now I know that Multicharts is just not able to process it.

So just to give you an example, lets look at the following, easy but effective strategy (at least when I look at the indicators and trade the signals manually):

Code: Select all

inputs: F1(6),S1(10),L1(3),F2(6),S2(10),L2(3),F3(270),S3(585),L3(203),
T1(0600),T2(1410),Y(90);
variables: MACD1(0),MACD2(0),MACD3(0),OldMA(0),MACDBuy(9999),MACDSS(-9999);


MACD1=MACD(Close of Data1,F1,S1);
MACD1=XAverage(MACD1,L1); //Exit off of this.
MACD2=MACD(Close of Data2,F2,S2)Data2;
MACD2=XAverage(MACD2,L2); //Enter off of this.
MACD3=MACD(Close of Data3,F3,S3)Data3;


if CurrentBar>2 and Time>T1 and Time<T2 and MarketPosition<=0
and MACD2[1]<0 and MACD2[1]<MACD2[2] and MACD2>MACD2[1] and MACD3>MACD3[1]
and AverageFC(Close of Data2,Y)>OldMA then begin
Buy next bar at market;
MACDBuy=MACD2;
end;

If MarketPosition=1 and MACD1[1]>0 and MACD1<MACD1[1] then Sell next bar at market;


If CurrentBar>2 and Time>T1 and Time<T2 and MarketPosition>=0
and MACD2[1]>0 and MACD2[1]>MACD2[2] and MACD2<MACD2[1] and MACD3<MACD3[1]
and AverageFC(Close of Data2,Y)<OldMA then begin
SellShort next bar at market;
MACDSS=MACD2;
end;

If MarketPosition=-1 and MACD1[1]<0 and MACD1>MACD1[1] then BuyToCover next bar at market;


SetStopLoss(400);

SetExitOnClose;

OldMA=AverageFC(Close of Data2,Y);
The timeframes used should be like this data1<data2<data3
Just setting data1- data3 does not seem to work; thats why I did some more research and came across EL Collections, Global Variables and ADE. Gloval Variables do not seem to work in Backtesting and Optimization, at least thats what I read I did not try it out. Thats why I installed EL Collections and ADE from here:

viewtopic.php?f=5&t=9870
http://www.traderslaboratory.com/forums ... age-2.html

I think I installed it correctly as the ADE Save Info Test and ADE Plot Info Test works correctly.
________________________
ADE Save Info Test:

Code: Select all

[LegacyColorValue = TRUE];

Inputs:
UseFile(ADE.UseFile), // default UseFile is returned by ADE.UseFile function
ADXLen(14),
RSILen(14),
StochLen(14);

Vars:
Class("BarInfoTest"), // class name for our test data
InfoMap(MapSN.New), // we will use this map to pass data to ADE.PutBarInfo
WriteOk(true),
oFastK(0),
oFastD(0),
oSlowK(0),
oSlowD(0);

// If UseFile is true, load any previously stored data from the file on the first bar.
if CurrentBar = 1 and UseFile then
Value1 = ADE.OpenMap(Class, GetSymbolName, ADE.BarInterval);

// Calculate stochastics
Value1 = Stochastic(High, Low, Close, StochLen, 3, 3, 1, oFastK, oFastD, oSlowK, oSlowD);

// Store the indicator values in InfoMap so that we can pass it to ADE.PutBarInfo
Value1 = MapSN.Put(InfoMap, "ADX", ADX(ADXLen));
Value1 = MapSN.Put(InfoMap, "RSI", RSI(Close, RSILen));
Value1 = MapSN.Put(InfoMap, "SlowK", oSlowK);
Value1 = MapSN.Put(InfoMap, "SlowD", oSlowD);

// Store the data for this symbol and bar interval.
// ADE.PutBarInfo will copy the information from our InfoMap into the appropriate DataMap.
Value1 = ADE.PutBarInfo(Class, GetSymbolName, ADE.BarInterval, ADE.BarID, InfoMap);

// If UseFile is true, save the data to the file on the last bar.
if LastBarOnChart and BarStatus(1) = 2 and UseFile and WriteOk then begin
Value1 = ADE.SaveMap(Class, GetSymbolName, ADE.BarInterval);
WriteOk = false; // prevent repeated writes on new bars
end;

Plot1(0); // include a Plot statement so we can use this indicator in RadarScreen[LegacyColorValue = TRUE];
_______________________________
ADE Plot Info Test:

Code: Select all

[LegacyColorValue = TRUE];

Inputs:
Interval(ADE.Daily), // number of minutes, or ADE.Daily, ADE.Weekly, ADE.Monthly
UseFile(ADE.UseFile); // default UseFile is returned by ADE.UseFile function

Vars:
Class("BarInfoTest"), // class name for our test data
InfoMap(MapSN.New), // we will use this map to retrieve data with ADE.GetBarInfo
MyADX(0),
MyRSI(0),
MySlowK(0),
MySlowD(0);

// If UseFile is true, load any previously stored data from the file on the first bar.
if CurrentBar = 1 and UseFile then
Value1 = ADE.OpenMap(Class, GetSymbolName, Interval);

// Retrieve the data for this symbol and bar interval.
// ADE.GetBarInfo will copy the information from the appropriate DataMap into our InfoMap.
Value1 = ADE.GetBarInfo(Class, GetSymbolName, Interval, ADE.BarID, InfoMap);

// Fetch the values from the InfoMap into variables
MyADX = MapSN.Get(InfoMap, "ADX");
MyRSI = MapSN.Get(InfoMap, "RSI");
MySlowK = MapSN.Get(InfoMap, "SlowK");
MySlowD = MapSN.Get(InfoMap, "SlowD");

// Plot them
Plot1(MyADX, "ADX");
Plot2(MyRSI, "RSI");
Plot3(MySlowK, "SlowK");
Plot4(MySlowD, "SlowD");
So now I need to wrap around my MACD strategy mentioned above around the ADE Save and Plot code. Also the strategy shall not plot anything it should buy and sell accordingly. Does anybody have a solution?


I also approached Multicharts with that. Unfortunately they only provided me some links and told me ADE, EL Collections is nothing they support (they might do for ~100hr/programming costs). As mentioned by various users already I am also wondering why Multicharts is not able to implement that function in their engine and was not aware that this does not exist.
Dont get me wrong I still think MC is a good product, but sometimes I am wondering about their answers (also highly depends on who you are talking to on the support side).
I appreciate any kind of help, advice.

Jonny473
Posts: 68
Joined: 04 Apr 2016
Has thanked: 5 times
Been thanked: 1 time

Re: Multitimeframe Signals ADE, EL_Collections, etc.

Postby Jonny473 » 27 Nov 2016

Thanks for the answer Josh also: The overall topic is handling of multidata charts and applying signals to those. What is wanted as described in the MACD signal: Three signals, the highest signal builds the "foundation" for a buy/sell to happen, the timeframe one below also has to indicate the same direction and the smallest TF basically triggers the trades when the direction accords with the two higher TFs.
I figured that this does not work correctly in Multicharts only referring to data1, data2, data3:

Code: Select all

inputs: F1(6),S1(10),L1(3),F2(6),S2(10),L2(3),F3(270),S3(585),L3(203),
T1(0600),T2(1410),Y(90);
variables: MACD1(0),MACD2(0),MACD3(0),OldMA(0),MACDBuy(9999),MACDSS(-9999);


MACD1=MACD(Close of Data1,F1,S1);
MACD1=XAverage(MACD1,L1); //Exit off of this.
MACD2=MACD(Close of Data2,F2,S2)Data2;
MACD2=XAverage(MACD2,L2); //Enter off of this.
MACD3=MACD(Close of Data3,F3,S3)Data3;


if CurrentBar>2 and Time>T1 and Time<T2 and MarketPosition<=0
and MACD2[1]<0 and MACD2[1]<MACD2[2] and MACD2>MACD2[1] and MACD3>MACD3[1]
and AverageFC(Close of Data2,Y)>OldMA then begin
Buy next bar at market;
MACDBuy=MACD2;
end;

If MarketPosition=1 and MACD1[1]>0 and MACD1<MACD1[1] then Sell next bar at market;


If CurrentBar>2 and Time>T1 and Time<T2 and MarketPosition>=0
and MACD2[1]>0 and MACD2[1]>MACD2[2] and MACD2<MACD2[1] and MACD3<MACD3[1]
and AverageFC(Close of Data2,Y)<OldMA then begin
SellShort next bar at market;
MACDSS=MACD2;
end;

If MarketPosition=-1 and MACD1[1]<0 and MACD1>MACD1[1] then BuyToCover next bar at market;


SetStopLoss(400);

SetExitOnClose;

OldMA=AverageFC(Close of Data2,Y);
Correct me if I am wrong or my signal code has mistakes. That is the reason I looked for ADE, EL Collections and Global Variables in this forum. Hopefully the link becomes clearer now. So assuming that this strategy should work correctly using ADE, I am trying to figure out how the ADE (Plot) code could be used on the highest timeframe with the according signal parameters, applying it to the smaller TFs and making the multitimeframe strategy work correctly.

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Multitimeframe Signals ADE, EL_Collections, etc.

Postby JoshM » 28 Nov 2016

The overall topic is handling of multidata charts and applying signals to those. What is wanted as described in the MACD signal: Three signals, the highest signal builds the "foundation" for a buy/sell to happen, the timeframe one below also has to indicate the same direction and the smallest TF basically triggers the trades when the direction accords with the two higher TFs.

(...)

Correct me if I am wrong or my signal code has mistakes. That is the reason I looked for ADE, EL Collections and Global Variables in this forum.
I haven't had time to debug this code, but there two things that seem to be missing that I'd personally add to the code. I don't say these are 'errors' or such, but more things that are easily tested and can save a lot of time with an ADE and/or EL_Collections solutions.

First, is the intra-bar order generation feature so that the signal can submit an order on the first data series whenever the values of the other data series align with a trade. If this helps to solve the problem does depend on the different resolutions used, but with intra-bar order generation you can at least address the situation where a signal is generated on Data2 but that cannot be submitted yet because the bar of Data1 hasn't closed.

Using intra-bar order generation does require adjusting your code a bit, like using the IntrabarPersist keyword for variables that should keep their value from one intra-bar calculation to the next. (Like `MACDBuy`).

Second, with the AllowSendOrdersAlways attribute enabled, a strategy that uses several data series can submit an order even when the different bars don't align. That still sounds abstract but if you follow the link you'll find an example strategy that applies AllowSendOrdersAlways to a strategy with multiple data series. There's also information on its wiki page.

Jonny473
Posts: 68
Joined: 04 Apr 2016
Has thanked: 5 times
Been thanked: 1 time

Re: Multitimeframe Signals ADE, EL_Collections, etc.

Postby Jonny473 » 28 Nov 2016

Thanks for the advice Josh. So here is what I did:

I amended the initial code:

Code: Select all

inputs: F1(6),S1(10),L1(3),F2(6),S2(10),L2(3),F3(270),S3(585),L3(203),
T1(0600),T2(1410),Y(90);
variables: MACD1(0),MACD2(0),MACD3(0),OldMA(0),MACDBuy(9999),MACDSS(-9999);


MACD1=MACD(Close of Data1,F1,S1);
MACD1=XAverage(MACD1,L1); //Exit off of this.
MACD2=MACD(Close of Data2,F2,S2)Data2;
MACD2=XAverage(MACD2,L2); //Enter off of this.
MACD3=MACD(Close of Data3,F3,S3)Data3;


if CurrentBar>2 and Time>T1 and Time<T2 and MarketPosition<=0
and MACD2[1]<0 and MACD2[1]<MACD2[2] and MACD2>MACD2[1] and MACD3>MACD3[1]
and AverageFC(Close of Data2,Y)>OldMA then begin
Buy next bar at market;
MACDBuy=MACD2;
end;

If MarketPosition=1 and MACD1[1]>0 and MACD1<MACD1[1] then Sell next bar at market;


If CurrentBar>2 and Time>T1 and Time<T2 and MarketPosition>=0
and MACD2[1]>0 and MACD2[1]>MACD2[2] and MACD2<MACD2[1] and MACD3<MACD3[1]
and AverageFC(Close of Data2,Y)<OldMA then begin
SellShort next bar at market;
MACDSS=MACD2;
end;

If MarketPosition=-1 and MACD1[1]<0 and MACD1>MACD1[1] then BuyToCover next bar at market;


SetStopLoss(400);

SetExitOnClose;

OldMA=AverageFC(Close of Data2,Y);
with intrabarpersist and Allowsendordersalways to:
[AllowSendOrdersAlways =True];

Code: Select all

inputs: F1(6),S1(10),L1(3),F2(6),S2(10),L2(3),F3(270),S3(585),L3(203),
T1(0600),T2(1410),Y(90);
variables: Intrabarpersist MACD1(0),Intrabarpersist MACD2(0),Intrabarpersist MACD3(0),Intrabarpersist OldMA(0),Intrabarpersist MACDBuy(9999),Intrabarpersist MACDSS(-9999);


MACD1=MACD(Close of Data1,F1,S1);
MACD1=XAverage(MACD1,L1); //Exit off of this.
MACD2=MACD(Close of Data2,F2,S2)Data2;
MACD2=XAverage(MACD2,L2); //Enter off of this.
MACD3=MACD(Close of Data3,F3,S3)Data3;


if CurrentBar>2 and Time>T1 and Time<T2 and MarketPosition<=0
and MACD2[1]<0 and MACD2[1]<MACD2[2] and MACD2>MACD2[1] and MACD3>MACD3[1]
and AverageFC(Close of Data2,Y)>OldMA then begin
Buy next bar at market;
MACDBuy=MACD2;
end;

If MarketPosition=1 and MACD1[1]>0 and MACD1<MACD1[1] then Sell next bar at market;


If CurrentBar>2 and Time>T1 and Time<T2 and MarketPosition>=0
and MACD2[1]>0 and MACD2[1]>MACD2[2] and MACD2<MACD2[1] and MACD3<MACD3[1]
and AverageFC(Close of Data2,Y)<OldMA then begin
SellShort next bar at market;
MACDSS=MACD2;
end;

If MarketPosition=-1 and MACD1[1]<0 and MACD1>MACD1[1] then BuyToCover next bar at market;


SetStopLoss(400);

SetExitOnClose;

OldMA=AverageFC(Close of Data2,Y);
For testing purposes I used the Dow Jones Index with 4HR-1HR-15 Min timeframe from 2011 to now.
Lets look at the first, initial, strategy:
Image
Image

Lets look at the results of the second one, which are exactly the same:
Image
Image

For the second one with Intrabar Order Generation turned ON, the number of trades are still exactly the same, but the results are worse:
Image
Image
Image

Jonny473
Posts: 68
Joined: 04 Apr 2016
Has thanked: 5 times
Been thanked: 1 time

Re: Multitimeframe Signals ADE, EL_Collections, etc.

Postby Jonny473 » 28 Nov 2016

Again just for testing purposes I made my 3 TF signal 2 TF and put it on 1HR-15 Minutes chart with the same parameters as before:

Code: Select all

[AllowSendOrdersAlways =True];

inputs: F1(6),S1(10),L1(3),F2(6),S2(10),L2(3),T1(0600),T2(1410),Y(90);
variables: Intrabarpersist MACD1(0),Intrabarpersist MACD2(0),Intrabarpersist OldMA(0),Intrabarpersist MACDBuy(9999),Intrabarpersist MACDSS(-9999);


MACD1=MACD(Close of Data1,F1,S1);
MACD1=XAverage(MACD1,L1); //Exit off of this.
MACD2=MACD(Close of Data2,F2,S2)Data2;
MACD2=XAverage(MACD2,L2); //Enter off of this.


if CurrentBar>2 and Time>T1 and Time<T2 and MarketPosition<=0
and MACD2[1]<0 and MACD2[1]<MACD2[2] and MACD2>MACD2[1]
then begin
Buy next bar at market;
MACDBuy=MACD2;
end;

If MarketPosition=1 and MACD1[1]>0 and MACD1<MACD1[1] then Sell next bar at market;


If CurrentBar>2 and Time>T1 and Time<T2 and MarketPosition>=0
and MACD2[1]>0 and MACD2[1]>MACD2[2] and MACD2<MACD2[1]
then begin
SellShort next bar at market;
MACDSS=MACD2;
end;

If MarketPosition=-1 and MACD1[1]<0 and MACD1>MACD1[1] then BuyToCover next bar at market;


SetStopLoss(400);

SetExitOnClose;
I even ripped it apart to make the signal single timeframe:

Code: Select all

[AllowSendOrdersAlways =True];

inputs: F1(6),S1(10),L1(3),T1(0600),T2(1410);
variables: Intrabarpersist MACD1(0),Intrabarpersist OldMA(0),Intrabarpersist MACDBuy(9999),Intrabarpersist MACDSS(-9999);


MACD1=MACD(Close of Data1,F1,S1);
MACD1=XAverage(MACD1,L1); //Exit off of this.


if CurrentBar>2 and Time>T1 and Time<T2 and MarketPosition<=0
and MACD1[1]<0 and MACD1[1]<MACD1[2] and MACD1>MACD1[1]
then begin
Buy next bar at market;
MACDBuy=MACD1;
end;

If MarketPosition=1 and MACD1[1]>0 and MACD1<MACD1[1] then Sell next bar at market;


If CurrentBar>2 and Time>T1 and Time<T2 and MarketPosition>=0
and MACD1[1]>0 and MACD1[1]>MACD1[2] and MACD1<MACD1[1]
then begin
SellShort next bar at market;
MACDSS=MACD1;
end;

If MarketPosition=-1 and MACD1[1]<0 and MACD1>MACD1[1] then BuyToCover next bar at market;


SetStopLoss(400);


SetExitOnClose;
Lets take a look at how the strategy performs in multi(2)-and single timeframes:

Image

So we see the 2TF signal on 15Min-1HR, below the 15 Min chart and lastly the 1HR with all same parameters (6-10-3) for testing purposes.
I highlighted the short entry on the 2TF and 15 Min chart. As the 1HR is not short in this time, I am wondering why the top 2TF is allowed to go short? Just because the 15 Min strategy is long? As said before my understanding is that the higher Timeframe is the "Foundation", the smaller ones just "act" within that. So whenever the 1 HR chart is long/short, the 15 Min chart can only trade and only in the same direction.

Jonny473
Posts: 68
Joined: 04 Apr 2016
Has thanked: 5 times
Been thanked: 1 time

Re: Multitimeframe Signals ADE, EL_Collections, etc.

Postby Jonny473 » 28 Nov 2016

So maybe using ADE correctly might solve this Josh?

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Multitimeframe Signals ADE, EL_Collections, etc.

Postby JoshM » 29 Nov 2016

So maybe using ADE correctly might solve this Josh?
Perhaps. Honestly, I can't say I 'get' this thread anymore. Perhaps I'm reading this thread biased, with something else in mind then what you're talking about which then confuses me.

Let's take for instance your previous post with the Dow Jones Index results from 2011 till now. I don't follow that because how can we compare adjusted code to the initial strategy, when the first post says the initial strategy 'does not seem to work'. (I hope that makes sense.)
When you say 'the first, initial, strategy' in the Dow Jones Index results post, are you talking about another strategy than the first post or are you using a strategy that doesn't work as a benchmark? In that latter case, wouldn't it be good if the adjusted code shows different results?

So we might not even understand each other when speaking about screenshots. :)

By the way, your "3 TF signal 2 TF and put it on 1HR-15 Minutes chart" post seems to introduce another issue unrelated to multiple data series. It looks like the more I read in this thread, the less grasp I feel about the topic(s) and issue(s) you struggle with. Let's see if someone else can help who better understands what this topic in essence is about.

Jonny473
Posts: 68
Joined: 04 Apr 2016
Has thanked: 5 times
Been thanked: 1 time

Re: Multitimeframe Signals ADE, EL_Collections, etc.

Postby Jonny473 » 29 Nov 2016

Haha sorry did not try to confuse anybody. So lets give it some structure:
Expectation towards MC: Why do people use Multitimeframe charts/signals ? They want all Timeframes to align in one direction to enter a trade. Depending on the indicators they are using, this might be promising, but they might also miss a lot of profitable trades. My understanding is that whenever you use x-multitimeframes, 3 in the example below, the highest gives a basic direction and the following signals applied to the lower timeframes are only allowed to trade in the same direction.
Image
So in the example you have 3 TFs, 4HR-1HR-5 Min: The 4HR gives a long signal during a certain time span (here from month 2 to month 4). Now this signal has to be confirmed by the lower Timeframes: In that time span there are 4 long signals provided in the 1 HR chart. Again one of four 1-HR signals can be exemplary broke down again in the 5 Min chart: 3 possible Long entries would occur here.
So overall the smallest Timeframe always triggers the trades if consistent with the higher Timeframe(s).
Unfortunately Multicharts, correct me if I am wrong, does not work like that, see example 2 posts above. It might also be because of my wrongly coded signal.
So this is where the ADE might come into play. I am not an expert on that as you are Josh, but I believe that a higher timeframe signal can be saved and than “transferred” (plotted) into another smaller chart. In that smaller chart a different strategy can “act” based on the signal “transferred” via ADE. So basically what I described in the example above. Again correct me if I am wrong.

Let's take for instance your previous post with the Dow Jones Index results from 2011 till now. I don't follow that because how can we compare adjusted code to the initial strategy, when the first post says the initial strategy 'does not seem to work'. (I hope that makes sense.)
When you say 'the first, initial, strategy' in the Dow Jones Index results post, are you talking about another strategy than the first post or are you using a strategy that doesn't work as a benchmark? In that latter case, wouldn't it be good if the adjusted code shows different results?


Correct: With initial strategy I mean the one from post #1, which I then amended accordingly, but the results did not change. Not working is the wrong word: The strategy enters trades, but not those that it is supposed to. Supposed to as to my understanding described above. Besides that I was also wondering why the amended code showed exactly the same results.

Hope this clarifies a little bit?!

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Multitimeframe Signals ADE, EL_Collections, etc.

Postby JoshM » 30 Nov 2016

Haha sorry did not try to confuse anybody. So lets give it some structure:
Expectation towards MC: Why do people use Multitimeframe charts/signals ? They want all Timeframes to align in one direction to enter a trade. Depending on the indicators they are using, this might be promising, but they might also miss a lot of profitable trades. My understanding is that whenever you use x-multitimeframes, 3 in the example below, the highest gives a basic direction and the following signals applied to the lower timeframes are only allowed to trade in the same direction.

(...)

So in the example you have 3 TFs, 4HR-1HR-5 Min: The 4HR gives a long signal during a certain time span (here from month 2 to month 4). Now this signal has to be confirmed by the lower Timeframes: In that time span there are 4 long signals provided in the 1 HR chart. Again one of four 1-HR signals can be exemplary broke down again in the 5 Min chart: 3 possible Long entries would occur here.
So overall the smallest Timeframe always triggers the trades if consistent with the higher Timeframe(s).
Thanks for the clarification.

Let's simplify it even more and make the following signal that goes long when:

- The 4H price bar happens on Monday or Tuesday,
- The 1H bar falls between 8:00 and 17:00,
- And the 5M bar happens at 13:00 hour.

If we translate that in a signal, it would trade like this:

Image

The code for this would be:

Code: Select all

Variables:
longSignalData1(false),
longSignalData2(false),
longSignalData3(false);

// Assume Monday & Tuesday are the long signal of 4 hour
longSignalData3 = (DayOfWeek(Date Data3) = Monday) or
(DayOfWeek(Date Data3) = Tuesday);

// Assume the 1 hour long signal is between 8:00 and 17:00
longSignalData2 = (Time Data2 > 800 and Time Data2 <= 1700);

// Assume the 5min is a closing at 13:00 hour
longSignalData1 = (Time[1] < 1300 and Time >= 1300);

// Submit long orders
// These should only happen on Monday and Tuesday, at 13:00 hour
if (MarketPosition(0) = 0) then begin

if (longSignalData1 and longSignalData2 and longSignalData3) then
Buy ("EL") 1 contracts next bar at market;

end;

// Exit position between 16:00 and 17:00
if (MarketPosition(0) > 0) then begin

if (Time > 1600 and Time <= 1700) then
Sell ("XL") all contracts next bar at market;

end;
Of course, this code example is extremely basic. But let's go back to the issue that the thread started with: multi-time frame signals don't seem to work. If that's the case, we would expect this simple signal to trade on other days than Monday or Tuesday (its Data3 condition). I couldn't find those situations on my end.

The signal would also trade in different time periods than 8:00 till 17:00 (its Data2 condition). I couldn't find those situations either. And lastly, the signal would have to open positions on other bars than 13:00 (its Data1 condition). Those trades I couldn't find.

So from looking at this situation from my end, there's a problem in your MultiCharts version (I'm using 9.0 Release), there's a wrong setting somewhere, or the code has an error.

If you had to translate your MACD signal into words, how would that be? (Don't use code; that only shows us what you've currently implemented, not what you're trying to do.)
Attachments
example-multi-time-frame-time-based.png
(20.62 KiB) Downloaded 2603 times

Jonny473
Posts: 68
Joined: 04 Apr 2016
Has thanked: 5 times
Been thanked: 1 time

Re: Multitimeframe Signals ADE, EL_Collections, etc.

Postby Jonny473 » 01 Dec 2016

Again Josh thanks for the explanation and effort, much appreciated. Applied your code to a chart and yes you are correct, it definitely works. I really thought about why I have those issues: Then I thought about the following: I often used the following Multitimeframe combination: 1HR-4HR-1D(NOT BUILD FROM 1 MINUTE DATA!!). I did not use Bar Magnifier nor Intra Bar Order Generation. One of the indicators for the 1D Timeframe used OHLC calculation what does not make any sense, as only (open and) close price is considered anyhow . So backtesting results seemed to be brilliant, but in live trading, the signals seemed to "repaint" over and over again. When I switch the "Build from 1 Minute data" on, results were totally different. This is why I also questioned the Multichart capability of MC. Does my own explanation make any sense?

Jonny473
Posts: 68
Joined: 04 Apr 2016
Has thanked: 5 times
Been thanked: 1 time

Re: Multitimeframe Signals ADE, EL_Collections, etc.

Postby Jonny473 » 07 Dec 2016

Although I tried to explain this issue already, I think my point was still not understood:

In the following example I want to highlight the issue again using:

-Multitimeframe EUR/USD 3 data streams (with ask/ bid so dont get confused by the pictures)
-in the first example I am using the 1 HR TF for all 3 data streams only
-in the second example I am using the 1HR/1D/1HR data streams
-my simple signal is only applied to the first and second data stream, so leave the 3rd data stream aside
-the signal is just saying: If RSI is >certain level buy, if RSI is <certain level sell
-the idea is: data stream 2 is the "basis" with greater RSI length, data stream has the smaller RSI length

Code: Select all

Inputs:
TakeLong(true),
TakeShort(false),

RSI1(false),
RSI1_Length(14),
RSI1_LongBelowLevel(30),
RSI1_ShortAboveLevel(70),

RSI2(false),
RSI2_Length(14),
RSI2_LongBelowLevel(30),
RSI2_ShortAboveLevel(70),

RSI3(false),
RSI3_Length(14),
RSI3_LongBelowLevel(30),
RSI3_ShortAboveLevel(70),

Lot(1);


Variables:
lot_long(0), lot_short(0),
stop_long(0), stop_short(0), Intrabarpersist stop_work(0), take_long(0), take_short(0), Intrabarpersist take_work(0),
is_loss(0), buy_sig(false), sell_sig(false);


lot_long = Lot;
lot_short = Lot;

buy_sig =
(RSI1 = false or RSI(Close, RSI1_Length) < RSI1_LongBelowLevel) and
(RSI2 = false or RSI(Close of data2, RSI2_Length) < RSI2_LongBelowLevel) and
(RSI3 = false or RSI(Close of data3, RSI3_Length) < RSI3_LongBelowLevel);


sell_sig = (RSI1 = false or RSI(Close, RSI1_Length) > RSI1_ShortAboveLevel) and
(RSI2 = false or RSI(Close of data2, RSI2_Length) > RSI2_ShortAboveLevel) and
(RSI3 = false or RSI(Close of data3, RSI3_Length) > RSI3_ShortAboveLevel);


if buy_sig and sell_sig then begin
buy_sig = false;
sell_sig = false;
end;


is_loss = 0;
If Positionprofit < 0 then
is_loss = 1;


If buy_sig then begin



Buy ("Long Entry") lot_long contracts next bar market;
end;

If sell_sig then begin

If Marketposition <> -1 then begin
stop_work = stop_short;
take_work = take_short;

Sellshort ("Short Entry") lot_short contracts next bar market;
end;
end;
As I experienced that this only works if all Timeframes are the same, I tried to "build" the Daily RSI in the 1 HR chart: So I figured RSI_Length 14 x 24=336 gives me the value of the RSI 14 Daily. But the Oversold/ Overbought levels also change so I adapted those accordingly to ~46,1 and 54,1.
Image
For the first data stream I used RSI_2 (70/30) as levels. So everytime both conditions are in place buy/ sell. Although this signal does not make much sense, the logic works as supposed.
Image

In the second example I used as described above the Daily timeframe for the 2nd data stream. And adapted the RSI length to 14 and the oversold/overbought levels accordingly, the first data stream stayed the same:

Image

The daily data is not taken into consideration as we can clearly see:

Image

The Daily RSI was under 30 in the midst of November so long trades (if the 1HR condition is fulfilled as well) would have been only allowed at this time,

Is the problem clearer now? Multitimeframe, at least if the Timeframes are not congruent, does not work. It could also be my code which is not written correctly, please advise!

User avatar
ABC
Posts: 718
Joined: 16 Dec 2006
Location: www.abctradinggroup.com
Has thanked: 125 times
Been thanked: 408 times
Contact:

Re: Multitimeframe Signals ADE, EL_Collections, etc.

Postby ABC » 09 Dec 2016

Jonny473,

it appears you are not using the correct code for what you want and in turn use values internally that are different from what you expect them to be. Just because you feed the price of data 2 to a function doesn't mean the function is only computed on data2.

It usually helps to print and plot values from your code, as this way the issues are easier to see. Compare the outcome of the below code on a chart (Data1 5 min for example and Data2 = 30 minutes) and compare it the build in RSI indicator that is just running on a 30 minute chart (or one that is running on the Data1/Data2 chart, but is specifically based on Data2 under the study properties).

RSI 1 is computed similar to your RSI using just the price of data2 as an input. The RSI 2 is tied to Data2 to ensure it gives you the same result you'd get on a single 30 minute chart.

Code: Select all

Variables:
rsi1 ( 0 ),
rsi2 ( 0, Data2 );


rsi1 = RSI( Close Data2, 14 ) ;

rsi2 = RSI( Close Data2, 14 ) Data2 ;

Plot1( rsi1, "RSI 1" );
Plot2( rsi2, "RSI 2" );
Regards,

ABC

Jonny473
Posts: 68
Joined: 04 Apr 2016
Has thanked: 5 times
Been thanked: 1 time

Re: Multitimeframe Signals ADE, EL_Collections, etc.

Postby Jonny473 » 09 Dec 2016

Thanks ABC. Will try that and keep you updated!

Jonny473
Posts: 68
Joined: 04 Apr 2016
Has thanked: 5 times
Been thanked: 1 time

Re: Multitimeframe Signals ADE, EL_Collections, etc.

Postby Jonny473 » 09 Dec 2016

Thanks for the hint ABC works now. I can post the code if somebody is interested.

User avatar
MarketMicro
Posts: 24
Joined: 04 May 2014
Been thanked: 1 time

Re: Multitimeframe Signals ADE, EL_Collections, etc.

Postby MarketMicro » 30 Jan 2017

Hi,

I'm currently trying to use Data1 as 1min bars, and Data2 as 10min bars, and in the same chart window.

Using the code quoted here,
inputs: F1(6),S1(10),L1(3),F2(6),S2(10),L2(3),F3(270),S3(585),L3(203),
T1(0600),T2(1410),Y(90);
variables: MACD1(0),MACD2(0),MACD3(0),OldMA(0),MACDBuy(9999),MACDSS(-9999);


MACD1=MACD(Close of Data1,F1,S1);
MACD1=XAverage(MACD1,L1); //Exit off of this.
MACD2=MACD(Close of Data2,F2,S2)Data2;
MACD2=XAverage(MACD2,L2); //Enter off of this.
MACD3=MACD(Close of Data3,F3,S3)Data3;


if CurrentBar>2 and Time>T1 and Time<T2 and MarketPosition<=0
and MACD2[1]<0 and MACD2[1]<MACD2[2] and MACD2>MACD2[1] and MACD3>MACD3[1]
and AverageFC(Close of Data2,Y)>OldMA then begin
Buy next bar at market;
MACDBuy=MACD2;
end;

I notice MACD2[0] and MACD2[1] have the correct values, as I checked that if I plot Data2 (i.e. 10min bars) by itself in its own chart window and apply MACD, I get the same values.

However, when I try to obtain the values of MACD2[2], and MACD2[3] from the chart with 1min and 10min bars, these values are not the same as they should when Data2 is plotted by itself. Instead I notice that MACD2[2] == MACD2[1] and MACD2[3]==MACD2[1] as well.

Is there a bug with how the series is stored in Multichart, or did I do something wrong?

janus
Posts: 835
Joined: 25 May 2009
Has thanked: 63 times
Been thanked: 104 times

Re: Multitimeframe Signals ADE, EL_Collections, etc.

Postby janus » 31 Jan 2017

Hi,
I notice MACD2[0] and MACD2[1] have the correct values, as I checked that if I plot Data2 (i.e. 10min bars) by itself in its own chart window and apply MACD, I get the same values.

However, when I try to obtain the values of MACD2[2], and MACD2[3] from the chart with 1min and 10min bars, these values are not the same as they should when Data2 is plotted by itself. Instead I notice that MACD2[2] == MACD2[1] and MACD2[3]==MACD2[1] as well.

Is there a bug with how the series is stored in Multichart, or did I do something wrong?
Not sure if this will help but try using MACD2(0,data2),MACD3(0,data3) in the variables line instead of simply MACD2(0),MACD3(0)

User avatar
MarketMicro
Posts: 24
Joined: 04 May 2014
Been thanked: 1 time

Re: Multitimeframe Signals ADE, EL_Collections, etc.

Postby MarketMicro » 31 Jan 2017

Don't know why it works, but your suggestion works. Not sure why I need to declare it as MACD2(0,data2) and not MACD2(0). Thank you.
Appreciate it if someone can explain why it works.
Thank you.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Multitimeframe Signals ADE, EL_Collections, etc.

Postby TJ » 31 Jan 2017

Don't know why it works, but your suggestion works. Not sure why I need to declare it as MACD2(0,data2) and not MACD2(0). Thank you.
Appreciate it if someone can explain why it works.
Thank you.

viewtopic.php?t=6929#p35429

User avatar
MarketMicro
Posts: 24
Joined: 04 May 2014
Been thanked: 1 time

Re: Multitimeframe Signals ADE, EL_Collections, etc.

Postby MarketMicro » 31 Jan 2017

Thanks, TJ.
I gather it's just the right syntax of MC.


Return to “MultiCharts”