Compiling error ts code

Questions about MultiCharts and user contributed studies.
O66
Posts: 146
Joined: 28 Nov 2006
Location: Netherlands
Has thanked: 2 times
Been thanked: 3 times

Compiling error ts code

Postby O66 » 07 Apr 2012

hi,

how can i compile this code (i get syntax errors):

Code: Select all

input fastLength = 3;
input slowLength = 10;
input MACDLength = 16;

def fastAvg = Average(data = close, length = fastLength);
def slowAvg = Average(data = close, length = slowLength);

plot Value = fastAvg – slowAvg;
plot Avg = Average(data = Value, length = MACDLength);
plot Diff = fastAvg – slowAvg;
plot ZeroLine = 0;

Value.SetDefaultColor(GetColor(1));
Avg.SetDefaultColor(GetColor(8));
Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.DefineColor(“Positive”, Color.UPTICK);
Diff.DefineColor(“Negative”, Color.DOWNTICK);
Diff.AssignValueColor(if diff >= 0 then Diff.color(“Positive”) else Diff.color(“Negative”));
ZeroLine.SetDefaultColor(GetColor(0));

sptrader
Posts: 742
Joined: 09 Apr 2010
Location: Texas
Has thanked: 483 times
Been thanked: 274 times
Contact:

Re: Compiling error ts code

Postby sptrader » 07 Apr 2012

Look at the MACD study that is built-in MC, it looks about the same to me..just change the input values to 3,10 and 16;

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

Re: Compiling error ts code

Postby TJ » 07 Apr 2012

hi,

how can i compile this code (i get syntax errors):

input fastLength = 3;
input slowLength = 10;
input MACDLength = 16;

def fastAvg = Average(data = close, length = fastLength);
def slowAvg = Average(data = close, length = slowLength);

plot Value = fastAvg – slowAvg;
plot Avg = Average(data = Value, length = MACDLength);
plot Diff = fastAvg – slowAvg;
plot ZeroLine = 0;

Value.SetDefaultColor(GetColor(1));
Avg.SetDefaultColor(GetColor(8));
Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.DefineColor(“Positive”, Color.UPTICK);
Diff.DefineColor(“Negative”, Color.DOWNTICK);
Diff.AssignValueColor(if diff >= 0 then Diff.color(“Positive”) else Diff.color(“Negative”));
ZeroLine.SetDefaultColor(GetColor(0));
This is not EasyLanguage.

O66
Posts: 146
Joined: 28 Nov 2006
Location: Netherlands
Has thanked: 2 times
Been thanked: 3 times

Re: Compiling error ts code

Postby O66 » 08 Apr 2012

thanks for replies.
i thought it was easylanguage, but i see now its for tos.

macd is based om ema, this 3/10 is based on sma.

three ten oscillator:

The fast line (red) is a 10 period simple moving average subtracted from a 3 period simple moving average. The slow line (cyan) is then a 16 period SMA of the slow line. The histogram is the delta between these two lines and therefore crosses the zero line when the fast and slow line cross. The histogram is hidden by default but can be revealed in the normal manner on the study properties pane.

O66
Posts: 146
Joined: 28 Nov 2006
Location: Netherlands
Has thanked: 2 times
Been thanked: 3 times

Re: Compiling error ts code

Postby O66 » 08 Apr 2012

i copied the macd function and called it macdsma.
changed xaverge to average
--

Code: Select all

inputs:
PriceValue( numericseries ),
FastLen( numericsimple ),
SlowLen( numericsimple ) ;

MACDSMA = Average( PriceValue, FastLen ) - Average( PriceValue, SlowLen ) ;
--

copied the macd indicator, and changed macd to macdsma
changed xaverage to average

---

Code: Select all

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

var0 = MACDSMA( Close, FastLength, SlowLength ) ;
var1 = Average( var0, MACDLength ) ;
var2 = var0 - var1 ;

Plot1( var0, "MACD" ) ;
Plot2( var1, "MACDAvg" ) ;
Plot3( var2, "MACDDiff" ) ;
Plot4( 0, "ZeroLine" ) ;

condition1 = var2 crosses over 0 ;
if condition1 then
Alert( "Bullish alert" )
else
begin
condition1 = var2 crosses under 0 ;
if condition1 then
Alert( "Bearish alert" ) ;
end;
----

As far as i understand the macdsma is now the macd but based on sma.
Is this correct?
Last edited by O66 on 08 Apr 2012, edited 1 time in total.

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

Re: Compiling error ts code

Postby TJ » 08 Apr 2012

i copied the macd function and called it macdsma.
changed xaverge to average
--

Code: Select all

inputs:
PriceValue( numericseries ),
FastLen( numericsimple ),
SlowLen( numericsimple ) ;

MACDSMA = Average( PriceValue, FastLen ) - Average( PriceValue, SlowLen ) ;
--

copied the macd indicator, and changed macd to macdsma
changed xaverage to average

---

Code: Select all

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

var0 = MACDSMA( Close, FastLength, SlowLength ) ;
var1 = Average( var0, MACDLength ) ;
var2 = var0 - var1 ;

Plot1( var0, "MACD" ) ;
Plot2( var1, "MACDAvg" ) ;
Plot3( var2, "MACDDiff" ) ;
Plot4( 0, "ZeroLine" ) ;

condition1 = var2 crosses over 0 ;
if condition1 then
Alert( "Bullish alert" )
else
begin
condition1 = var2 crosses under 0 ;
if condition1 then
Alert( "Bearish alert" ) ;
end;
----

As far as i understand the macdsma is now the macd but based on sma.
Is this correct?
That is correct.

Well done !


Return to “MultiCharts”