Can I get any calculated value from an indicator?
How could I get the value of O[_i] from this indicator to an EA.
O[_i] is the open price of the overlay chart indicator.
How could I get the value of O[_i] from this indicator to an EA.
O[_i] is the open price of the overlay chart indicator.
Inserted Code
//+------------------------------------------------------------------+
//| OverlayChart.mq5 |
//| Copyright 2014-2016, EarnForex.com |
//| http://www.earnforex.com |
//| Converted from MT4 version by http://www.irxfx.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014-2016, EarnForex.com"
#property link "http://www.earnforex.com"
#property version "1.01"
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_plots 1
#property indicator_type1 DRAW_COLOR_BARS
#property indicator_color1 clrMediumSeaGreen, clrOrange
#property indicator_width1 1
//Indicator Parameters
input string SubSymbol = "GBPUSD";
input bool Mirroring = false;
input ENUM_DRAW_TYPE DrawType = DRAW_COLOR_BARS;
input color GridColor = clrBlack;
//Indicator Buffers
double O[];
double H[];
double L[];
double C[];
double Color[];
// Global variables
double SubOpen[];
double SubHigh[];
double SubLow[];
double SubClose[];
string Prefix = "OverlayChart"; //Indicator Prefix
int Grid = 10; //Grid Lines
int SnapPips = 10; //Snap Pips For Grid Lines
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
IndicatorSetString(INDICATOR_SHORTNAME, "OverLay Chart (" + SubSymbol + ")");
SetIndexBuffer(0, O, INDICATOR_DATA);
SetIndexBuffer(1, H, INDICATOR_DATA);
SetIndexBuffer(2, L, INDICATOR_DATA);
SetIndexBuffer(3, C, INDICATOR_DATA);
SetIndexBuffer(4, Color, INDICATOR_COLOR_INDEX);
ArraySetAsSeries(O, true);
ArraySetAsSeries(H, true);
ArraySetAsSeries(L, true);
ArraySetAsSeries(C, true);
ArraySetAsSeries(Color, true);
PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, 0);
PlotIndexSetInteger(0, PLOT_DRAW_TYPE, DrawType);
ArraySetAsSeries(SubOpen, true);
ArraySetAsSeries(SubHigh, true);
ArraySetAsSeries(SubLow, true);
ArraySetAsSeries(SubClose, true);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
ObjectsDeleteAll(0, Prefix);
/* for (int _i = 1; _i <= Grid; _i ++)
{
ObjectDelete(0, Prefix + "Grid" + IntegerToString(_i));
ObjectDelete(0, Prefix + "Price" + IntegerToString(_i));
}*/
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
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[])
{
int _BarsCount;
double _CurRangeHigh, _CurRangeLow, _CurRangeCenter;
double _SubRangeHigh, _SubRangeLow, _SubRangeCenter;
double _SubPoint;
int _SubDigit;
double _SubOpen, _SubHigh, _SubLow, _SubClose;
double _PipsRatio;
double _GridPips, _GridPrice;
int _i;
ArraySetAsSeries(Open, true);
ArraySetAsSeries(High, true);
ArraySetAsSeries(Low, true);
ArraySetAsSeries(Close, true);
ArraySetAsSeries(Time, true);
ArrayInitialize(O, 0);
ArrayInitialize(H, 0);
ArrayInitialize(L, 0);
ArrayInitialize(C, 0);
//Calculate Visible Bars
_BarsCount = (int)ChartGetInteger(0, CHART_VISIBLE_BARS) + 1;
int _FirstBar = (int)ChartGetInteger(0, CHART_FIRST_VISIBLE_BAR);
int _LastBar = _FirstBar - _BarsCount + 1;
if ( _LastBar < 0 ) {
_LastBar = 0;
_BarsCount = _FirstBar + 1;
}
//Calculate Chart Ratio
_CurRangeHigh = High[ArrayMaximum(High, _LastBar, _BarsCount)];
_CurRangeLow = Low[ArrayMinimum(Low, _LastBar, _BarsCount)];
_CurRangeCenter = (_CurRangeHigh + _CurRangeLow) / 2;
int n;
n = CopyOpen(SubSymbol, 0, _LastBar, _BarsCount, SubOpen);
if (!CheckData(n, _BarsCount)) return(0);
n = CopyHigh(SubSymbol, 0, _LastBar, _BarsCount, SubHigh);
if (!CheckData(n, _BarsCount)) return(0);
n = CopyLow(SubSymbol, 0, _LastBar, _BarsCount, SubLow);
if (!CheckData(n, _BarsCount)) return(0);
n = CopyClose(SubSymbol, 0, _LastBar, _BarsCount, SubClose);
if (!CheckData(n, _BarsCount)) return(0);
double SubMax = SubHigh[ArrayMaximum(SubHigh)];
double SubMin = SubLow[ArrayMinimum(SubLow)];
if (Mirroring)
{
_SubRangeHigh = SubMin;
_SubRangeLow = SubMax;
}
else
{
_SubRangeHigh = SubMax;
_SubRangeLow = SubMin;
}
_SubRangeCenter = (_SubRangeHigh + _SubRangeLow) / 2;
_SubPoint = SymbolInfoDouble(SubSymbol, SYMBOL_POINT);
_SubDigit = (int)SymbolInfoInteger(SubSymbol, SYMBOL_DIGITS);
if (_SubRangeHigh - _SubRangeLow == 0) return(0);
_PipsRatio = (_CurRangeHigh - _CurRangeLow) / (_SubRangeHigh - _SubRangeLow);
_GridPips = (_SubRangeHigh - _SubRangeLow) / Grid;
_GridPips = MathRound((_SubRangeHigh - _SubRangeLow) / Grid / (_SubPoint * SnapPips)) * (_SubPoint * SnapPips);
//Draw Candlesticks
for (_i = _LastBar; _i < _LastBar + _BarsCount; _i++)
{
int i = _i - _LastBar;
_SubOpen = SubOpen[i] - _SubRangeCenter;
_SubHigh = SubHigh[i] - _SubRangeCenter;
_SubLow = SubLow[i] - _SubRangeCenter;
_SubClose = SubClose[i] - _SubRangeCenter;
if (Mirroring)
{
if (_SubOpen < _SubClose)
{
H[_i] = _CurRangeCenter + _SubHigh * _PipsRatio;
L[_i] = _CurRangeCenter + _SubLow * _PipsRatio;
Color[_i] = 0;
}
else
{
L[_i] = _CurRangeCenter + _SubLow * _PipsRatio;
H[_i] = _CurRangeCenter + _SubHigh * _PipsRatio;
Color[_i] = 1;
}
C[_i] = _CurRangeCenter + _SubClose * _PipsRatio;
O[_i] = _CurRangeCenter + _SubOpen * _PipsRatio;
}
else
{
if (_SubOpen < _SubClose)
{
H[_i] = _CurRangeCenter + _SubHigh * _PipsRatio;
L[_i] = _CurRangeCenter + _SubLow * _PipsRatio;
Color[_i] = 0;
}
else
{
L[_i] = _CurRangeCenter + _SubLow * _PipsRatio;
H[_i] = _CurRangeCenter + _SubHigh * _PipsRatio;
Color[_i] = 1;
}
C[_i] = _CurRangeCenter + _SubClose * _PipsRatio;
O[_i] = _CurRangeCenter + _SubOpen * _PipsRatio;
}
}
for (_i = 1; _i <= Grid; _i ++)
{
_GridPrice = MathRound(_SubRangeCenter / (_SubPoint * SnapPips)) * (_SubPoint * SnapPips);
_GridPrice = ((_GridPrice + _GridPips / 2) + _GridPips * (Grid / 2 - 1)) - (_GridPips * (_i - 1));
string grid_string = Prefix + "Grid" + IntegerToString(_i);
ObjectCreate(0, grid_string, OBJ_TREND, 0, 0, 0);
ObjectSetInteger(0, grid_string, OBJPROP_TIME, 0, Time[_FirstBar]);
ObjectSetDouble(0, grid_string, OBJPROP_PRICE, 0, _CurRangeCenter + (_GridPrice - _SubRangeCenter) * _PipsRatio);
ObjectSetInteger(0, grid_string, OBJPROP_TIME, 1, Time[_LastBar]);
ObjectSetDouble(0, grid_string, OBJPROP_PRICE, 1, _CurRangeCenter + (_GridPrice - _SubRangeCenter) * _PipsRatio);
ObjectSetInteger(0, grid_string, OBJPROP_COLOR, GridColor);
ObjectSetInteger(0, grid_string, OBJPROP_STYLE, STYLE_DOT);
ObjectSetInteger(0, grid_string, OBJPROP_WIDTH, 1);
ObjectSetInteger(0, grid_string, OBJPROP_RAY_RIGHT, true);
grid_string = Prefix + "Price" + IntegerToString(_i);
ObjectCreate(0, grid_string, OBJ_TEXT, 0, 0, 0);
ObjectSetInteger(0, grid_string, OBJPROP_TIME, 0, Time[_FirstBar - _BarsCount / 10]);
ObjectSetDouble(0, grid_string, OBJPROP_PRICE, 0, _CurRangeCenter + (_GridPrice - _SubRangeCenter) * _PipsRatio);
ObjectSetInteger(0, grid_string, OBJPROP_COLOR, GridColor);
ObjectSetString(0, grid_string, OBJPROP_TEXT, DoubleToString(_GridPrice, _SubDigit));
}
return(rates_total);
}
// Checks the number of timeseries bars and returns either true (OK) or false (Error).
bool CheckData(int n, int _BarsCount)
{
if (n == -1)
{
Print("Chart data unavailable: ", SubSymbol);
return(false);
}
if (n != _BarsCount)
{
Print("Chart data still loading for: ", SubSymbol);
return(false);
}
return(true);
}
//+------------------------------------------------------------------+