Код: Выделить всё
function Initialize()
{
IndicatorName = "MACD_idicator";
PriceStudy = false;
AddInput("Input", Inputs.Price);
AddParameter("PFast", 10);
AddParameter("PSlow", 20, 2);
AddParameter("PSig", 10);
AddSeries("S", DrawAs.Custom,Color.White);
AddSeries("B", DrawAs.Custom,Color.Yellow);
AddSeries("Line", DrawAs.Line, Color.Gray); //,false
AddSeries("Signal", DrawAs.Line, Color.Red);
//AddLevel(0, Color.Gray, "Line");
AddGlobalVariable("EMA1", Types.Double, 0.0);
AddGlobalVariable("EMA2", Types.Double, 0.0);
AddGlobalVariable("KC1", Types.Double, 0.0);
AddGlobalVariable("KC2", Types.Double, 0.0);
AddGlobalVariable("KC", Types.Double, 0.0);
//AddGlobalVariable("r", Types.Double, 0.2);
}
function Evaluate()
{
if( CurrentIndex < 1 )
{
EMA1 = Input[0];
EMA2 = Input[0];
Line = 0.0;
Signal = 0.0;
KC1 = 2.0 / ((double) PFast + 1.0);
KC2 = 2.0 / ((double) PSlow + 1.0);
KC = 2.0 / ((double) PSig + 1.0);
}
else
{
EMA1 = (1.0 - KC1)*EMA1 + KC1*Input[0];
EMA2 = (1.0 - KC2)*EMA2 + KC2*Input[0];
Line = EMA1 - EMA2;
Signal = (1.0 - KC)*Signal[-1] + KC*Line;
}
if (Line[-1] > Signal[-1]&&Line[0] < Signal[0])
S.DrawArrowDown();
//PlaySound(InnerSystemSounds.Exclamation ) ;
S=Signal[0];
if (Line[-1] < Signal[-1]&&Line[0] > Signal[0])
B=Line[0];
B.DrawArrowUp();
//PlaySound(InnerSystemSounds.Exclamation ) ;
}