//+------------------------------------------------------------------+
//| tickGraphicInd.mq5 |
//| Copyright 2020, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
//Autor: Infinity Trading
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots 2
#property indicator_label1 "Ask"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrRed
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
#property indicator_label2 "Bid"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrBlue
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
int ticks_History=1999;
double tAskBuffer[];
double tBidBuffer[];
int tAskHandle;
int tBidHandle;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
ChartSetInteger(0,CHART_SHOW_GRID,false);
ChartSetInteger(0,CHART_FOREGROUND,false);
color clrBackGround=(color)ChartGetInteger(0,CHART_COLOR_BACKGROUND,0);
ChartSetInteger(0,CHART_COLOR_CANDLE_BEAR,clrBackGround);
ChartSetInteger(0,CHART_COLOR_CANDLE_BULL,clrBackGround);
ChartSetInteger(0,CHART_COLOR_CHART_UP,clrBackGround);
ChartSetInteger(0,CHART_COLOR_CHART_DOWN,clrBackGround);
ChartSetInteger(0,CHART_COLOR_CHART_LINE,clrBackGround);
ChartSetInteger(0,CHART_SCALE,0);
ChartSetInteger(0,CHART_SCALEFIX,true);
ArraySetAsSeries(tAskBuffer,true);
ArraySetAsSeries(tBidBuffer,true);
SetIndexBuffer(0,tAskBuffer,INDICATOR_DATA);
SetIndexBuffer(1,tBidBuffer,INDICATOR_DATA);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| 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[])
{
//---
MqlTick mticks[];
ArraySetAsSeries(mticks,true);
if(!CopyTicks(_Symbol,mticks,COPY_TICKS_ALL,0,ticks_History))
{
Print("Error al copiar el array de ticks!!!");
}
else
{
int size=ArraySize(mticks);
for(int i=0; i<size; i++)
{
tAskBuffer[i]=mticks[i].ask;
tBidBuffer[i]=mticks[i].bid;
}
}
int size2=ArraySize(mticks);
int scale;
int ticksH;
int plus;
ChartGetInteger(0,CHART_SCALE,0);
switch(scale)
{
case 0:
ticksH=1000;
plus=5;
break;
case 1:
ticksH=500;
plus=4;
break;
case 2:
ticksH=260;
plus=3;
break;
case 3:
ticksH=130;
plus=2;
break;
case 4:
ticksH=70;
plus=1;
break;
case 5:
ticksH=35;
plus=1;
break;
default:
ticksH=1000;
plus=1;
break;
}
int max=ArrayMaximum(tAskBuffer,1,ticksH);
int min=ArrayMinimum(tBidBuffer,1,ticksH);
ChartSetDouble(0,CHART_FIXED_MAX,tAskBuffer[max]+(0.00001*plus));
ChartSetDouble(0,CHART_FIXED_MIN,tBidBuffer[min]-(0.00001*plus));
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
Comments