//+------------------------------------------------------------------+
//| Speedometr.mq5 |
//| Copyright 2016, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
#property indicator_chart_window
#property indicator_plots 0
input int FontSize = 12; // Ðàçìåð øðèôòà
input string FontName = "Arial"; // Íàèìåíîâàíèå øðèôòà
input color ClrWay = Red; // Öâåò ìåòêè - ïóòü öåíû â ïóíêòàõ
input color ClrSpeed = Yellow; // Öâåò ìåòêè - ñêîðîñòü ïóíêòû â ñåêóíäó
input color ClrTime = White; // Öâåò ìåòêè - èçìåíåíèå âðåìåíè â ìèêðîñåêóíäàõ
input int SpeedSound = 20; // Îïîâåùåíèå ïðåâûøåíèÿ ñêîðîñòè
input ENUM_BASE_CORNER Corner = CORNER_RIGHT_UPPER; // Óãîë äëÿ âûâîäà èíôîðìàöèè
input bool AlertOn = true; // Âêëþ÷åíèå îïîâåùåíèÿ
bool one=true;
double LastBid;
ulong LastTime=0,T=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
Comment("");
ObjectDelete(0,"Label1");
ObjectDelete(0,"Label2");
ObjectDelete(0,"Label3");
}
//+------------------------------------------------------------------+
//| Óñòàíîâêà ìåòîê |
//+------------------------------------------------------------------+
void PutLabel(string name,string text,int x,int y,color clr)
{
ObjectDelete(0,name);
//--- ñîçäàäèì òåêñòîâóþ ìåòêó
ObjectCreate(0,name,OBJ_LABEL,0,0,0);
//--- óñòàíîâèì êîîðäèíàòû ìåòêè
ObjectSetInteger(0,name,OBJPROP_XDISTANCE,x);
ObjectSetInteger(0,name,OBJPROP_YDISTANCE,y);
//--- óñòàíîâèì óãîë ãðàôèêà, îòíîñèòåëüíî êîòîðîãî áóäóò îïðåäåëÿòüñÿ êîîðäèíàòû òî÷êè
ObjectSetInteger(0,name,OBJPROP_CORNER,Corner);
//--- óñòàíîâèì òåêñò
ObjectSetString(0,name,OBJPROP_TEXT,text);
//--- óñòàíîâèì øðèôò òåêñòà
ObjectSetString(0,name,OBJPROP_FONT,FontName);
//--- óñòàíîâèì ðàçìåð øðèôòà
ObjectSetInteger(0,name,OBJPROP_FONTSIZE,FontSize);
//--- óñòàíîâèì öâåò
ObjectSetInteger(0,name,OBJPROP_COLOR,clr);
}
//+------------------------------------------------------------------+
//| 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[])
{
//---
double speed=0,way=0,Bid=0;
ulong dt=0;
T=GetMicrosecondCount();
Bid=SymbolInfoDouble(_Symbol,SYMBOL_BID);
if(LastBid!=Bid)
{
dt=T-LastTime;
way=(Bid-LastBid)/_Point;
speed=way/dt;
// Måòêè â ïðàâîé ïîëîâèíå ãðàôèêà
if(Corner==CORNER_RIGHT_UPPER || Corner==CORNER_RIGHT_LOWER)
{
PutLabel("Label1","Way: "+(string)NormalizeDouble(way,2),150,30,ClrWay);
PutLabel("Label2","Time: "+(string)NormalizeDouble(dt,2),150,55,ClrTime);
PutLabel("Label3","Speed: "+(string)NormalizeDouble(speed*1000000,2),150,80,ClrSpeed);
}
else // Måòêè â ëåâîé ïîëîâèíå ãðàôèêà
{
PutLabel("Label1","Way: "+(string)NormalizeDouble(way,2),20,30,ClrWay);
PutLabel("Label2","Time: "+(string)NormalizeDouble(dt,2),20,55,ClrTime);
PutLabel("Label3","Speed: "+(string)NormalizeDouble(speed*1000000,2),20,80,ClrSpeed);
}
}
LastTime=T;
LastBid=Bid;
if(MathAbs(speed*1000000)<SpeedSound) one=true;
// Îïîâåùåíèÿ ïðè âêëþ÷åííîé îïöèè AlertOn
if((MathAbs(speed*1000000)>SpeedSound && one && AlertOn))
{
Alert("Ñêîðîñòü âûøå "+(string)SpeedSound+" ïóíêòîâ â ñåêóíäó!");
SendNotification("Ñêîðîñòü âûøå: "+(string)SpeedSound+" ïóíêòîâ â ñåêóíäó!");
SendMail("Ñèãíàë èíäèêàòîðà","Ñêîðîñòü âûøå: "+(string)SpeedSound+" ïóíêòîâ â ñåêóíäó!");
one=false;
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
Comments