Need help in converting Metastock code to Tradestation easylanguage

amar_gr

Junior member
Messages
13
Likes
0
Can somebody please help in converting this Metastock Code to Tradestation Easy Language.

It is basically a trend following system. The code generates a buy/sell on breakout above/below the 20 days range. For the exit/sar it plots the trailing stop loss.

Regards & Thanks in advance
Amar
--------
no:=Input("Swing/ Bars", 1, 20, 2);

res:=HHV(H,no);
sup:=LLV(L,no);
avd:=If(C>Ref(res,-1),1,If(C<Ref(sup,-1),-1,0));
avn:=ValueWhen(1,avd<>0,avd);
tsl:=If(avn=1,Ref(sup,-1),Ref(res,-1));

tsl;
 
Hopefully I understand the code right. Am not sure about what you term a trailing stop loss
So I am just putting in the standard TS dollar stop for trailing. This code does not take into account all conditions that might occur, but should serve as an example.

// Assuming daily chart
variables:
Amount ( 100 ) ; // Dollar amount of trailing stop

if close > Highest( high[ 1 ], 20 ) then Buy next bar market ;
if close < Lowest( low[ 1 ], 20 ) then SellShort next bar market ;

SetStopContract;
SetDollarTrailing( Amount ) ;

// Code does not prevent an immediate re-entry of position if conditions are still valid
// After a Trailing Stop has activated.
 
Top