//+------------------------------------------------------------------+
//| AlterGrid v2 |
//| Copyright 2015, mrak297 |
//| http://www.mql5.com/ru/users/mrak297 |
//+------------------------------------------------------------------+
#property copyright "© 2015 mrak297"
#property link "http://www.mql5.com/ru/users/mrak297"
#property indicator_chart_window
input color Color = DimGray;
input ENUM_LINE_STYLE Style = STYLE_DOT;
double dXPoint = 1;
double Div = 0;
double i = 0;
double HighPrice = 0;
double LowPrice = 0;
int iDigits;
int L = 0;
//+------------------------------------------------------------------+
int start()
{
HighPrice = MathRound(WindowPriceMax(0) * Div);
LowPrice = MathRound(WindowPriceMin(0) * Div);
for (i = LowPrice; i <= HighPrice; i++)
{
if (ChartPeriod(0) < 30)
{
for (L=10; L<=90; L=L+10)
{
if (StringSubstr(DoubleToStr(i/Div,iDigits),StringLen(DoubleToStr(i/Div,iDigits))-2,2) == L)
{
if (ObjectFind("0 "+DoubleToStr(i,0)) != 0)
{
DrawHLine("0 "+DoubleToStr(i,0), i/Div);
}
}
}
}
if (ChartPeriod(0) < 1440)
{
if (StringSubstr(DoubleToStr(i/Div,iDigits),StringLen(DoubleToStr(i/Div,iDigits))-2,2) == "50")
{
if (ObjectFind("00 "+DoubleToStr(i,0)) != 0)
{
DrawHLine("00 "+DoubleToStr(i,0), i/Div);
}
}
}
if (ChartPeriod(0) < 10080)
{
if (MathMod(i, 10) == 0.0)
{
if (ObjectFind("000 " + DoubleToStr(i, 0)) != 0)
{
DrawHLine("000 " + DoubleToStr(i, 0), i/Div);
}
}
}
if (ChartPeriod(0) > 1140)
{
if (MathMod(i, 100) == 0.0)
{
if (ObjectFind("0000 " + DoubleToStr(i, 0)) != 0)
{
DrawHLine("0000 " + DoubleToStr(i, 0), i/Div);
}
}
}
if (ChartGetInteger(0, CHART_SCALE) < 1 && ChartPeriod(0) == 1) ObjectDelete(0,"0 "+DoubleToStr(i,0));
if (ChartGetInteger(0, CHART_SCALE) < 2 && ChartPeriod(0) == 5) ObjectDelete(0,"0 "+DoubleToStr(i,0));
if (ChartGetInteger(0, CHART_SCALE) < 2 && ChartPeriod(0) == 15) ObjectDelete(0,"0 "+DoubleToStr(i,0));
if (ChartGetInteger(0, CHART_SCALE) < 1 && ChartPeriod(0) == 60) ObjectDelete(0,"00 "+DoubleToStr(i,0));
if (ChartGetInteger(0, CHART_SCALE) < 2 && ChartPeriod(0) == 240) ObjectDelete(0,"00 "+DoubleToStr(i,0));
if (ChartGetInteger(0, CHART_SCALE) < 4 && ChartPeriod(0) == 1440) ObjectDelete(0,"000 "+DoubleToStr(i,0));
}
int shift;
for(shift = Bars(NULL,0) - 1; shift >= 0; shift--)
{
if(ChartPeriod(0) < 15)
{
if(TimeMinute(Time[shift]) == 30)
{
if(ObjectFind("Minute"+shift)!= 0)
{
DrawVLine("Minute"+shift,shift);
}
}
}
if(ChartPeriod(0) < 30)
{
if(TimeMinute(Time[shift]) == 0)
{
if(ObjectFind("Hour"+shift)!=0)
{
DrawVLine("Hour"+shift,shift);
}
}
}
if(ChartPeriod(0) < 240)
{
if (TimeMinute(Time[shift]) == 0)
{
if (TimeHour(Time[shift]) == 0 || TimeHour(Time[shift]) == 4 || TimeHour(Time[shift]) == 8 || TimeHour(Time[shift]) == 12 || TimeHour(Time[shift]) == 16 || TimeHour(Time[shift]) == 20)
{
if(ObjectFind("4Hour"+shift) != 0)
{
DrawVLine("4Hour"+shift,shift);
}
}
}
}
if(ChartPeriod(0) == 240)
{
if(TimeMinute(Time[shift]) == 0 && TimeHour(Time[shift]) == 0)
{
if(ObjectFind("Day"+shift)!= 0)
{
DrawVLine("Day"+shift,shift);
}
}
}
if (ChartGetInteger(0, CHART_SCALE) < 1 && ChartPeriod(0) == 1) ObjectDelete(0,"Minute"+shift);
if (ChartGetInteger(0, CHART_SCALE) < 3 && ChartPeriod(0) == 5) ObjectDelete(0,"Minute"+shift);
if (ChartGetInteger(0, CHART_SCALE) < 2 && ChartPeriod(0) == 5) ObjectDelete(0,"Hour"+shift);
if (ChartGetInteger(0, CHART_SCALE) < 3 && ChartPeriod(0) == 15) ObjectDelete(0,"Hour"+shift);
if (ChartGetInteger(0, CHART_SCALE) < 1 && ChartPeriod(0) == 15) ObjectDelete(0,"4Hour"+shift);
if (ChartGetInteger(0, CHART_SCALE) < 2 && ChartPeriod(0) == 30) ObjectDelete(0,"4Hour"+shift);
if (ChartGetInteger(0, CHART_SCALE) < 3 && ChartPeriod(0) == 60) ObjectDelete(0,"4Hour"+shift);
if (ChartGetInteger(0, CHART_SCALE) < 3 && ChartPeriod(0) == 240) ObjectDelete(0,"Day"+shift);
}
return (0);
}
//+------------------------------------------------------------------+
int init()
{
iDigits=Digits;
if(Digits==5 || Digits==3)dXPoint=10;
if(Digits==3) iDigits=2;
if(Digits==5) iDigits=4;
Div=0.1/(Point*dXPoint);
Print("AlterGrid ver. 2, build: ",__DATETIME__);
ChartSetInteger(0, CHART_SCALE, 3);
if(ChartGetInteger(0,CHART_SHOW_GRID))
{
ChartSetInteger(0,CHART_SHOW_GRID,0,0);
GetLastError();
}
return (0);
}
//+------------------------------------------------------------------+
int deinit()
{
ObjectsDeleteAll();
if(ChartGetInteger(0,CHART_SHOW_GRID))
{
Print("Grid detected.");
GetLastError();
}
else ChartSetInteger(0,CHART_SHOW_GRID,0,1);
return (0);
}
//+------------------------------------------------------------------+
void DrawVLine(string label, int shft)
{
ObjectCreate(label, OBJ_VLINE, 0, Time[shft], 0);
ObjectSet(label, OBJPROP_STYLE, Style);
ObjectSet(label, OBJPROP_COLOR, Color);
ObjectSet(label, OBJPROP_HIDDEN, true);
ObjectSet(label, OBJPROP_BACK, true);
ObjectSetString(0, label, OBJPROP_TOOLTIP, "\n");
}
//+------------------------------------------------------------------+
void DrawHLine(string labl, double price)
{
ObjectCreate(labl, OBJ_HLINE, 0, Time[1], price);
ObjectSet(labl, OBJPROP_STYLE, Style);
ObjectSet(labl, OBJPROP_COLOR, Color);
ObjectSet(labl, OBJPROP_HIDDEN, true);
ObjectSet(labl, OBJPROP_BACK, false);
ObjectSetString(0, labl, OBJPROP_TOOLTIP, "\n");
}
//+------------------------------------------------------------------+
Comments