Commit 3f934b07 authored by FXcoder's avatar FXcoder

price arrays, ma check

parent d1e4cf54
......@@ -53,6 +53,11 @@ void OnInit()
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total, const int prev_calculated, const datetime& time[], const double& open[], const double& high[], const double& low[], const double& close[], const long& tick_volume[], const long& volume[], const int& spread[])
{
ArraySetAsSeries(open, true);
ArraySetAsSeries(high, true);
ArraySetAsSeries(low, true);
ArraySetAsSeries(close, true);
int i, j, nCountedBars;
double dAPrice, dAmount, dMovingAverage;
......@@ -73,10 +78,13 @@ int OnCalculate(const int rates_total, const int prev_calculated, const datetime
{
dAmount = 0.0;
dMovingAverage = MA(NULL, 0, ExtStdDevPeriod, 0, (ENUM_MA_METHOD)ExtStdDevMAMethod, ExtStdDevAppliedPrice, i);
if (dMovingAverage == 0.0)
return(rates_total - i - 1);
for (j = 0; j < ExtStdDevPeriod; j++)
{
dAPrice = GetAppliedPrice(ExtStdDevAppliedPrice, i + j);
dAPrice = GetAppliedPrice(ExtStdDevAppliedPrice, i + j, open, high, low, close);
dAmount += (dAPrice - dMovingAverage) * (dAPrice - dMovingAverage);
}
......@@ -91,7 +99,7 @@ int OnCalculate(const int rates_total, const int prev_calculated, const datetime
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double GetAppliedPrice(int nAppliedPrice, int nIndex)
double GetAppliedPrice(int nAppliedPrice, int nIndex, const double& open[], const double& high[], const double& low[], const double& close[])
{
double dPrice;
......@@ -99,31 +107,31 @@ double GetAppliedPrice(int nAppliedPrice, int nIndex)
switch (nAppliedPrice)
{
case 0:
dPrice = Close[nIndex];
dPrice = close[nIndex];
break;
case 1:
dPrice = Open[nIndex];
dPrice = open[nIndex];
break;
case 2:
dPrice = High[nIndex];
dPrice = high[nIndex];
break;
case 3:
dPrice = Low[nIndex];
dPrice = low[nIndex];
break;
case 4:
dPrice = (High[nIndex] + Low[nIndex]) / 2.0;
dPrice = (high[nIndex] + low[nIndex]) / 2.0;
break;
case 5:
dPrice = (High[nIndex] + Low[nIndex] + Close[nIndex]) / 3.0;
dPrice = (high[nIndex] + low[nIndex] + close[nIndex]) / 3.0;
break;
case 6:
dPrice = (High[nIndex] + Low[nIndex] + 2 * Close[nIndex]) / 4.0;
dPrice = (high[nIndex] + low[nIndex] + 2 * close[nIndex]) / 4.0;
break;
default:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment