Can someone help me to convert from Metastock to Amibroker

#1
Hi,

Can someone help me to convert from Metastock to Amibroker? This is a Supertrend, I found here in this Forum some similar translations, but they aren't the same. I tried and compared a lot of them.


Factor:=Input("Factor",1.00,10.00,3.00);
Pd:=Input("ATR Periods",1,100,10);
Up:=MP()+(Factor*ATR(Pd));
Dn:=MP()-(Factor*ATR(Pd));
Td:=If(Cross(C,LLV(Up,13)),1,If(Cross(HHV(Dn,13),C),-1,PREV));
Dnx:=If(Dn=HighestSince(1,Cross(Td,0),Dn),Dn,PREV);
Upx:=If(Up=LowestSince(1,Cross(0,Td),Up),Up,PREV);
ST:=If(Td=1,Dnx,If(Td=-1,Upx,PREV));
ST





Thanks in advance!

Cheers,

Jacare
 
#2
Here
pls cross check with MS.
you may need to adjust parameters
*Author of this formula = Edward Pottash

_SECTION_BEGIN("ST");
Factor=Param("Factor",2,1,5,0.5);
Pd=Param("ATR Periods",10,1,100,1);
Pda=Param("Look back",13,1,50,1);
Up=(H+L)/2+(Factor*ATR(Pd));
Dn=(H+L)/2-(Factor*ATR(Pd));


aa=Cross(C,LLV(Up,pda));
bb=Cross(HHV(Dn,pda),C);
Td[0]=1;
for(i=1;i<BarCount;i++ )
{
prev=Td[i-1];
if(aa)
{
Td=1;
}
else if(bb)
{
Td=-1;
}
else
{
Td=prev;
}
}
aa=Dn==HighestSince(Cross(Td,0),Dn);
Dnx=Dn[0];
for(i=1;i<BarCount;i++ )
{
prev=Dnx[i-1];
if(aa)
{
Dnx=Dn;
}
else
{
Dnx=prev;
}
}
aa=Up==LowestSince(Cross(0,Td),Up);
Upx=Up[0];
for(i=1;i<BarCount;i++ )
{
prev=Upx[i-1];
if(aa)
{
Upx=Up;
}
else
{
Upx=prev;
}
}
//ST:=If(Td=1,Dnx,If(Td=-1,Upx,PREV));
aa=Td==1;
bb=Td==-1;
ST[0]=1;
for(i=1;i<BarCount;i++ )
{
prev=ST[i-1];
if(aa)
{
ST=Dnx;
}
else if(bb)
{
ST=Upx;
}
else
{
ST=prev;
}
}
SetChartBkColor(ParamColor("bkcolor",ColorRGB(0,0,0)));
SetChartOptions(0,chartShowDates);
SetBarFillColor(IIf(C>O,ParamColor("Candle UP Color", colorGreen),IIf(C<=O,ParamColor("Candle Down Color", colorRed),colorLightGrey)));
Plot(C,"",IIf(C>O,ParamColor("Wick UP Color", colorDarkGreen),IIf(C<=O,ParamColor("Wick Down Color", colorDarkRed),colorLightGrey)),64,0,0,0,0);
Plot(ST,"",colorTan,styleLine);
Thank you
 
#4
Hey cas67,

I noticed that you did the formula together with the price. Could it be possible to have the indicator only, where can I put it in another existing chart? I use this indicator 3 times in the same chart, with differents parameters.

Thanks again!
Jacare
 
#6
Could it be possible to have the indicator only, where can I put it in another existing chart? I use this indicator 3 times in the same chart, with differents parameters.

Thanks again!
Jacare
 

velmont86

Active Member
#7
Could it be possible to have the indicator only, where can I put it in another existing chart? I use this indicator 3 times in the same chart, with differents parameters.

Thanks again!
Jacare

so simple just remove this line
Plot(C,"",IIf(C>O,ParamColor("Wick UP Color", colorDarkGreen),IIf(C<=O,ParamColor("Wick Down Color", colorDarkRed),colorLightGrey)),64,0,0,0,0);
 
#8
_SECTION_BEGIN("ST");
Factor=Param("Factor",2,1,5,0.5);
Pd=Param("ATR Periods",10,1,100,1);
Pda=Param("Look back",13,1,50,1);
Up=(H+L)/2+(Factor*ATR(Pd));
Dn=(H+L)/2-(Factor*ATR(Pd));


aa=Cross(C,LLV(Up,pda));
bb=Cross(HHV(Dn,pda),C);
Td[0]=1;
for(i=1;i<BarCount;i++ )
{
prev=Td[i-1];
if(aa)
{
Td=1;
}
else if(bb)
{
Td=-1;
}
else
{
Td=prev;
}
}
aa=Dn==HighestSince(Cross(Td,0),Dn);
Dnx=Dn[0];
for(i=1;i<BarCount;i++ )
{
prev=Dnx[i-1];
if(aa)
{
Dnx=Dn;
}
else
{
Dnx=prev;
}
}
aa=Up==LowestSince(Cross(0,Td),Up);
Upx=Up[0];
for(i=1;i<BarCount;i++ )
{
prev=Upx[i-1];
if(aa)
{
Upx=Up;
}
else
{
Upx=prev;
}
}
//ST:=If(Td=1,Dnx,If(Td=-1,Upx,PREV));
aa=Td==1;
bb=Td==-1;
ST[0]=1;
for(i=1;i<BarCount;i++ )
{
prev=ST[i-1];
if(aa)
{
ST=Dnx;
}
else if(bb)
{
ST=Upx;
}
else
{
ST=prev;
}
}
SetChartBkColor(ParamColor("bkcolor",ColorRGB(0,0, 0)));
SetChartOptions(0,chartShowDates);
SetBarFillColor(IIf(C>O,ParamColor("Candle UP Color", colorGreen),IIf(C<=O,ParamColor("Candle Down Color", colorRed),colorLightGrey)));
Plot(ST,"",colorTan,styleLine);
Plot(C,"",IIf(C>O,ParamColor("Wick UP Color", colorDarkGreen),IIf(C<=O,ParamColor("Wick Down Color", colorDarkRed),colorLightGrey)),64,0,0,0);
 

Similar threads