logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Derek Worswick  
#1 Posted : Sunday, March 23, 2014 1:28:17 PM(UTC)
Derek Worswick

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 8/11/2005(UTC)
Posts: 104

Hi,

re posting my Message as code was not posted the correct panel

Derek

Derek Worswick  
#2 Posted : Sunday, March 23, 2014 1:42:22 PM(UTC)
Derek Worswick

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 8/11/2005(UTC)
Posts: 104

I am re posting my Message as code was not posted the panel

Derek
______________________________________

Hi,

Could you please tell me how to convert the four lines of thinkscript code in curly braces { }

into MetaStock code in the code panel.

I do not understand how to convert the line below into MetaStock

{ compoundValue(1, if posValue > 0 then stdev(posValue, lookback) else posDev[1], 0); }

Syntex

CompoundValue( int length, IDataHolder visible data , IDataHolder historical data );

Parameter ! Default value Description

length ! 1 Defines length with which the bar number is compared.

visible data ! - Defines data to be returned if bar number exceeds the specified length.

historical data Defines data to be returned if bar number is less than or equal to the specified length.

Thanking you in advance.

Best regards,

Derek

Code:


 

Data:=(H+L)/2;

fastLength:=
Input("fastLength",5,34,5);

slowLength:=Input("slowLength",5,200,175);

factor:=100;

lookback:=150;

AvgFast:=Mov(Data,fastLength,S);

AvgSlow:=Mov(Data,slowLength,S);

OscValue:= AvgFast -
AvgSlow;

 

{… start Breakout Bands logic ...}

 

{ def posValue = if OscValue > 0 then OscValue else 0; }





{ rec posDev = compoundValue(1, if posValue > 0 then stdev(posValue,
lookback) else posDev[1], 0); }





{ def negValue = if OscValue < 0 then
absValue(OscValue) else 0; }





{ rec negDev = compoundValue(1, if negValue
> 0 then stdev(negValue, lookback) else negDev[1], 0); }

 

{… End Breakout Bands logic ...}

 

UpperBand:=factor/100 * posDev;

LowerBand:= -factor/100 * negDev;

 

OscValue;

 

UpperBand;

LowerBand;

 

 

wabbit  
#3 Posted : Tuesday, March 25, 2014 6:39:53 PM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
try
Code:

fastLength:= Input("fastLength",5,34,5);
slowLength:=Input("slowLength",5,200,175);

data:=(H+L)/2;
factor:=100;
lookback:=150;

AvgFast:=Mov(data,fastLength,S);
AvgSlow:=Mov(data,slowLength,S);
OscValue:= AvgFast - AvgSlow;

{start Breakout Bands logic}
posValue := (OscValue > 0) * OscValue;
posDev := If(posValue > 0,Stdev(posValue, lookback),PREV);
negValue := (OscValue < 0) * Abs(OscValue);
negDev := If(negValue > 0, Stdev(negValue, lookback),PREV);
{End Breakout Bands logic}

UpperBand:=factor/100 * posDev;
LowerBand:= -factor/100 * negDev;

{plot}
OscValue;
UpperBand;
LowerBand;


Derek Worswick  
#4 Posted : Wednesday, March 26, 2014 1:58:00 AM(UTC)
Derek Worswick

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 8/11/2005(UTC)
Posts: 104

Hello Wabbit,

Many thanks for your help with the code...that works great,

Best regards

Derek
Derek Worswick  
#5 Posted : Sunday, April 6, 2014 8:04:09 AM(UTC)
Derek Worswick

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 8/11/2005(UTC)
Posts: 104

Hi

Using

fastLength:= 5

slowLength= 35

Adding Signal lines as positive and negative Moving averages

Code:


fastLength:= Input("fastLength",5,34,5);

slowLength:=Input("slowLength",5,252,35);

dev:=Input("Devations",1,2,1);


data:=(H+L)/2;

factor:=200;

lookback:=150;
AvgFast:=Mov(data,fastLength,S);

AvgSlow:=Mov(data,slowLength,S);

OscValue:= AvgFast - AvgSlow;


 {start Breakout Bands logic}

posValue := (OscValue > 0) * OscValue;

posDev:=If(posValue>0,dev*(Stdev(posValue, lookback)),PREV);

negValue := (OscValue < 0) * Abs(OscValue);

negDev := If(negValue > 0, dev*(Stdev(negValue, lookback)),PREV);{End Breakout Bands logic}

 

UpperBand:=factor/100 * posDev;

LowerBand:= -factor/100 * negDev;

 OscValue1:=OscValue;


MAPos:=Input("MA-Pos",2,200,9);

MANeg:=Input("MA-Neg",2,200,9);

PosNegMA:=If(OscValue>=0,Mov(OscValue,MAPos,S)
,Mov(OscValue1,MAneg,S));


 {plot}

OscValue;

OscValue1;

UpperBand; LowerBand;

PosNegMA;

 
http://i.imgur.com/sTfXECK.jpg "> http://i.imgur.com/sTfXECK.jpg
Users browsing this topic
Guest (Hidden)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.