"MACD LE" signal applied to Data Series 3

Questions about MultiCharts and user contributed studies.
M747
Posts: 25
Joined: 05 Feb 2016
Has thanked: 12 times
Been thanked: 2 times

"MACD LE" signal applied to Data Series 3

Postby M747 » 17 Feb 2016

Hello, I am trying to apply Multicharts' built in "MACD LE" signal to the 3rd data series on my chart, but it is not working for some reason. The code I wrote to do this is below, would really appreciate a code example showing what I did wrong.

FYI: You'll see the third to last line of this code is the only thing I changed from MC's original code in order to get it to apply to data series 3.

Code: Select all

inputs: FastLength( 12 ), SlowLength( 26 ), MACDLength( 9 ) ;
variables: var0( 0 ), var1( 0 ), var2( 0 ) ;

var0 = MACD( Close, FastLength, SlowLength ) ;
var1 = XAverage( var0, MACDLength ) ;
var2 = var0 - var1 ;

condition1 = CurrentBar of data3 > 2 and var2 of data3 crosses over 0 ;
if condition1 then
Buy ( "MacdLE" ) next bar at market ;
Also, I'm not sure if it changes anything about how I'd write this code, but I thought I'd let you know that i'm using this code with Multicharts "Precise Backtesting" feature (explain here http://bit.ly/1RP8kyM) so that the fills are based on actual Bid and ask prices. With that in mind, I have set the chart (and the "properties>backtesting>extended" tab) so that Bid prices are Data1 and Ask prices are data2.

The data3 series I've referred to above represents 5 minute "Last" bars.

Thanks!

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

Re: "MACD LE" signal applied to Data Series 3

Postby TJ » 17 Feb 2016

See post #5
[FAQ] Data2
viewtopic.php?f=16&t=6929

M747
Posts: 25
Joined: 05 Feb 2016
Has thanked: 12 times
Been thanked: 2 times

Re: "MACD LE" signal applied to Data Series 3

Postby M747 » 18 Feb 2016

Thanks TJ, I read that link and changed my code to this

Code: Select all

inputs: FastLength( 12 ), SlowLength( 26 ), MACDLength( 9 ) ;
variables: Macd3( 0, data3), var1( 0 ), var2( 0 ) ;

Macd3 = MACD( Close, FastLength, SlowLength ) data3 ;
var1 = XAverage( Macd3, MACDLength ) ;
var2 = Macd3 - var1 ;

condition1 = CurrentBar of data3 > 2 and var2 of crosses over 0 ;
if condition1 then
Buy ( "MacdLE" ) next bar at market ;
However, its still not working right. Any idea what I did wrong?
Would very much appreciate if you could post a complete version of the code above with my mistakes fixed.

Thanks

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

Re: "MACD LE" signal applied to Data Series 3

Postby TJ » 18 Feb 2016

Thanks TJ, I read that link and changed my code to this

Code: Select all

inputs: FastLength( 12 ), SlowLength( 26 ), MACDLength( 9 ) ;
variables: Macd3( 0, data3), var1( 0 ), var2( 0 ) ;

Macd3 = MACD( Close, FastLength, SlowLength ) data3 ;
var1 = XAverage( Macd3, MACDLength ) ;
var2 = Macd3 - var1 ;

condition1 = CurrentBar of data3 > 2 and var2 of crosses over 0 ;
if condition1 then
Buy ( "MacdLE" ) next bar at market ;
However, its still not working right. Any idea what I did wrong?
Would very much appreciate if you could post a complete version of the code above with my mistakes fixed.

Thanks
Please read post #2
viewtopic.php?f=16&t=10811

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

Re: "MACD LE" signal applied to Data Series 3

Postby TJ » 18 Feb 2016

Multi-data strategy is advanced level programming.
It will take some time and effort to accomplish what you are trying to do. It is not difficult; the devil is in the details, and there is no short cut or substitution for trials and testings. Please re-read my recommendations and try again.

M747
Posts: 25
Joined: 05 Feb 2016
Has thanked: 12 times
Been thanked: 2 times

Re: "MACD LE" signal applied to Data Series 3

Postby M747 » 18 Feb 2016

Can you please revise the code I wrote and repost it?

This simple example would teach me (and other users) a lot about how to write Multi-data strategies.

Thanks.

tony
Posts: 420
Joined: 14 Jun 2013
Has thanked: 30 times
Been thanked: 81 times
Contact:

Re: "MACD LE" signal applied to Data Series 3

Postby tony » 18 Feb 2016

I would not write the following as you have

Code: Select all

condition1 = CurrentBar of data3 > 2 and var2 of crosses over 0 ;
if condition1 then
Buy ( "MacdLE" ) next bar at market ;
I would write something like this

Code: Select all

If current bar of data3 > 2

and var2 crosses above 0

then begin

Buy ( "MacdLE" ) next bar at market ;
You also have a mistake I can see right now. You write "var2 of crosses over 0" var2 of what? Of data2, data3?

M747
Posts: 25
Joined: 05 Feb 2016
Has thanked: 12 times
Been thanked: 2 times

Re: "MACD LE" signal applied to Data Series 3

Postby M747 » 19 Feb 2016

Thanks for the Example Tony!

Also, thanks for pointing out the "of" I wrote accidentally. The "of" is a typo. I meant to write that line of code like this:
condition1 = CurrentBar of data3 > 2 and var2 crosses over 0 ;


Return to “MultiCharts”