Thank you nag. thank you Jose,
I originally posted my best attempt at converting the relevant Amibroker to Metastock code conversion to the other thread with this name yesterday. It seems that the only values I get are +57 and -57 for any data series.
Jose the following temporary variables are illegal in Metastock
X1_EMA34 etc. => so I shortened it to X1, X2, etc.
Also C is reserved in metastock so this is an illegal temp variable so I made this C1
I hardcoded the # of periods to 34 for the 34 EMA and left out the periods variable statement.
I also left out the reference to the 25LSMA to concentrate just on this 34EMA degrees issue.
acos in AB is cos in Metastock
---------8<------------------------------------------------------
EMA34:= Mov(C,34,E);
PI:= 3.141593;
HighHigh:= HHV(H, 30);
LowLow:= LLV(L, 30);
range:= 25/(HighHigh - LowLow)*LowLow;
x1:= 0;
x2:= 2;
y1:= 0;
y2:= (Ref(EMA34, -2) - EMA34) / ATR(25)*range;
c1:= Sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1));
angle:= Round(180 * Cos((x2 - x1)/c1) / PI);
If(y2 > 0, -angle, angle);
---------8<------------------------------------------------------
Below is the entire AmiBroker code - opensource- that is used to create a trading panel - I thought I included all the relevant parts for the 34EMA degree calculation - maybe not. In any case I'm attaching a jpeg of the output and a lot of the coding refers to formatting.
///////////////////////////////
// CCI Woodies Style - Started by Wring
// Added and Modified by Kris (crasher_FL)
// Version: 1.015
// Last Update: 08/01/2005
// Additions:
// timer, EMA angle, LSMA angle, trending indicator
// Amibroker 4.70
///////////////////////////////
Version(4.70);
z = CCI(14);
z6 = CCI(6);
CCI50_var = CCI(50);
LSMA25 = LinearReg(C, 25 );
EMA34 = EMA(C,34);
EMAVOL3 = EMA(Volume, 3);
PI = atan(1.00) * 4;
periods = 30;
HighHigh = HHV(H, periods);
LowLow = LLV(L, periods);
range = 25 / (HighHigh - LowLow) * LowLow;
if(SelectedValue(CCI50_var) < 0)
{
CCI50Title = EncodeColor(colorRed);
}
else
{
CCI50Title = EncodeColor(colorLime);
}
CCI50Title = CCI50Title + "CCI 50 = " + round(CCI50_var) + ", ";
StopTitle = EncodeColor(colorWhite) + "STOP = " + EncodeColor(colorYellow);
StopTitle = StopTitle + IIf(O < C, IIf((H - O) < (C - L), StrToNum(NumToStr(C - L, 4.4)), StrToNum(NumToStr(H - O, 4.4))),
IIf((O - L) < (H - C), StrToNum(NumToStr(H - C, 4.4)), StrToNum(NumToStr(O - L, 4.4))));
x1_EMA34 = 0;
x2_EMA34 = 2;
y1_EMA34 = 0;
y2_EMA34 = (Ref(EMA34, -2) - EMA34) / Avg * range;
c_EMA34 = sqrt((x2_EMA34 - x1_EMA34)*(x2_EMA34 - x1_EMA34) + (y2_EMA34 - y1_EMA34)*(y2_EMA34 - y1_EMA34));
angle_EMA34 = round(180 * acos((x2_EMA34 - x1_EMA34)/c_EMA34) / PI);
TitleAngleEMA34 = EncodeColor(colorWhite) + "\\nEMA34 angle = ";
angle_EMA34 = IIf(y2_EMA34 > 0, - angle_EMA34, angle_EMA34);
if(abs(SelectedValue(angle_EMA34)) >= 25)
{
TitleAngleEMA34 = TitleAngleEMA34 + EncodeColor(colorLime);
}
else if(abs(SelectedValue(angle_EMA34)) >= 15)
{
TitleAngleEMA34 = TitleAngleEMA34 + EncodeColor(colorYellow);
}
else
{
TitleAngleEMA34 = TitleAngleEMA34 + EncodeColor(colorRed);
}
TitleAngleEMA34 = TitleAngleEMA34 + angle_EMA34;
x1_LSMA25 = 0;
x2_LSMA25 = 2;
y1_LSMA25 = 0;
y2_LSMA25 = (Ref(LSMA25, -2) - LSMA25) / Avg * range;
c_LSMA25 = sqrt((x2_LSMA25 - x1_LSMA25)*(x2_LSMA25 - x1_LSMA25) + (y2_LSMA25 - y1_LSMA25)*(y2_LSMA25 - y1_LSMA25));
angle_LSMA25 = round(180 * acos((x2_LSMA25 - x1_LSMA25)/c_LSMA25) / PI);
TitleAngleLSMA25 = EncodeColor(colorWhite) + "LSMA25 angle = ";
angle_LSMA25 = IIf(y2_LSMA25 > 0, - angle_LSMA25, angle_LSMA25);
if(abs(SelectedValue(angle_LSMA25)) >= 25)
{
TitleAngleLSMA25 = TitleAngleLSMA25 + EncodeColor(colorLime);
}
else if(abs(SelectedValue(angle_LSMA25)) >= 15)
{
TitleAngleLSMA25 = TitleAngleLSMA25 + EncodeColor(colorYellow);
}
else
{
TitleAngleLSMA25 = TitleAngleLSMA25 + EncodeColor(colorRed);
}
TitleAngleLSMA25 = TitleAngleLSMA25 + angle_LSMA25;
TitleTrending = WriteIf((abs(angle_EMA34) >= 15) AND (abs(angle_EMA34 + angle_LSMA25) >= 50), EncodeColor(colorWhite) + ", SW = " + EncodeColor(colorLime) + "TRENDING",
WriteIf((abs(angle_EMA34) >= 5) AND (((angle_EMA34 >= 0) AND (angle_LSMA25 >= 0)) OR ((angle_EMA34 <= 0) AND (angle_LSMA25 <= 0))) AND (abs(angle_EMA34 + angle_LSMA25) >= 30), EncodeColor(colorWhite) + ", SW = " + EncodeColor(colorYellow) + "NORMAL",
EncodeColor(colorWhite) + ", SW = " + EncodeColor(colorRed) + "FLAT"));
SW = IIf((abs(angle_EMA34) >= 15) AND (abs(angle_EMA34 + angle_LSMA25) >= 50), IIf(angle_LSMA25 > 0, 2, -2),
IIf((abs(angle_EMA34) >= 5) AND (((angle_EMA34 >= 0) AND (angle_LSMA25 >= 0)) OR ((angle_EMA34 <= 0) AND (angle_LSMA25 <= 0))) AND (abs(angle_EMA34 + angle_LSMA25) >= 30), IIf(angle_LSMA25 > 0, 1, -1), 0));
tempnum = Now( 4 ) - TimeNum();
TimeRem = Interval() - ((int(tempnum[BarCount - 1] / 100) * 60) + (tempnum[BarCount - 1] - int(tempnum[BarCount - 1] / 100) * 100));
if (TimeRem[BarCount - 1] < 0) TimeRem = 0;
TitleTimeRem = EncodeColor(colorBlueGrey) + "Time Remaining: ";
MinuteVar = int(TimeRem / 60);
SecondsVar = int(frac(TimeRem / 60) * 60);
if (TimeRem[BarCount - 1] > 60)
{
TitleTimeRem = TitleTimeRem + EncodeColor(colorWhite) + MinuteVar + ":" + WriteIf(SecondsVar > 9, "", "0") + SecondsVar;
}
else if (TimeRem[BarCount - 1] > 20)
{
TitleTimeRem = TitleTimeRem + EncodeColor(colorYellow) + MinuteVar + ":" + WriteIf(SecondsVar > 9, "", "0") + SecondsVar;
}
else
{
TitleTimeRem = TitleTimeRem + EncodeColor(colorLime) + MinuteVar + ":" + WriteIf(SecondsVar > 9, "", "0") + SecondsVar;
}
Title = "" + Name() + ", " + Interval(2) + ", " + Date() + "\\n" +
EncodeColor(colorSkyblue) + "CCI 14 = " + round(z) + EncodeColor(colorWhite) + ", " + EncodeColor(colorLightOrange) +
"CCI 6 = " + round(z6) + EncodeColor(colorWhite) + ", " + //CCI50Title +
StopTitle +
// "\\nC = " + C + ", H = " + H + ", L = " + L + ", O = " + O +
TitleAngleEMA34 + EncodeColor(colorWhite) + ", " + TitleAngleLSMA25 +
TitleTrending + EncodeColor(colorWhite) + "\\nVolume = " + EncodeColor(colorYellow) + Volume +
EncodeColor(colorWhite) + ", " + TitleTimeRem;
// Colour the bars for Woodies Trend Following
Plusbars = BarsSince(z < 0);
Minusbars = BarsSince(z > 0);
TrendBarCount = 6;
Color[0] = colorDefault;
Trend[0] = 0;
for( i = 1; i < BarCount; i++ )
{
if (Plusbars >= TrendBarCount)
{
Trend = 1;
}
else if (Minusbars >= TrendBarCount)
{
Trend = -1;
}
else
{
Trend = Trend[i - 1];
}
if (Trend == 1)
{
if (Minusbars == TrendBarCount - 1)
{
Color = colorGold;
}
else if (z < 0)
{
Color = colorDarkBlue;
}
else
{
Color = colorGreen;
}
}
else if (Trend == -1)
{
if (Plusbars == TrendBarCount - 1)
{
Color = colorGold;
}
else if (z >= 0)
{
Color = colorDarkBlue;
}
else
{
Color = colorRed;
}
}
else
{
Color = colorDefault;
}
}
// CCI Line
Plot(z,"CCI 14", colorSkyblue, styleLine | styleThick);
// Turbo CCI
Plot(z6,"CCI 6", colorLightOrange, styleLine | styleNoLabel);
// CCI Histogram
Plot(z,"",Color,styleHistogram | styleNoLabel);
// CCI 50
//Plot(CCI50_var,"CCI 50", IIf(CCI50_var < 0, colorDarkRed,colorDarkGreen), styleLine | styleNoLabel);
// zero line 25lsma
Plot(0,"",IIf(C > LSMA25,colorGreen,IIf(C<LSMA25,colorRed,colorTeal)),
styleThick | styleNoLabel);
// Set up color for the 100s, green if 34ema above red if below
Color = IIf(C > EMA34, colorGreen,
IIf(C == EMA34, colorTeal, colorRed));
// Plot the 100s
Plot(100,"",Color,styleDots |styleNoLine | styleNoLabel | styleThick);
Plot(-100,"",Color,styleDots |styleNoLine | styleNoLabel | styleThick);
// Set up color for the 200s, green if 34ema above red if below
ColorVol = IIf(EMAVOL3 > 400, colorLime,
IIf(EMAVOL3 > 300, colorGreen,
IIf(EMAVOL3 > 200, colorDarkGreen, colorRed)));
// Plot the 200s
Plot(200,"", ColorVol, styleDots | styleNoLine | styleNoLabel | styleThick);
Plot(-200,"", ColorVol, styleDots | styleNoLine | styleNoLabel | styleThick);
// Plot the 50s
PlotGrid(50,colorTeal);
PlotGrid(-50, colorTeal);
// Plot the 200s
PlotGrid(200, styleNoLine);
PlotGrid(-200, styleNoLine);