#property copyright "(c) 2019 さいとさんにぃまる"
#property link "https://site-320.com/mt4/"
#property version "1.00"
#property strict
#property description "マウスの位置の価格を表示するインジケーター"
#property indicator_plots 0
#property indicator_chart_window
enum EPos{
LeftView=1,
CenterView,
RightView
};
enum ESize{
NoView=0,
VerySmall,
Small,
Medium,
Large,
VeryLarge
};
enum ELineS{
Solid = 0,
Dash,
Dot,
DashDot,
DashDotDot
};
enum ELineW{
Width0 = 0,
Width1,
Width2,
Width3,
Width4,
Width5
};
const string cstPrefix = "320_MPP_";
bool HLineShow = false;
int SaveX = 0;
int SaveY = 0;
input color mppFontColor = clrNONE;
input color mppBackColor = clrNONE;
input bool mppBackFill = true;
input ESize mppSize = Small;
input EPos mppPos = CenterView;
input int mppX = 0;
input int mppY = 0;
input color mppLineColor = clrNONE;
input ELineS mppLineStyle = Dot;
input ELineW mppLineWidth = Width1;
int OnInit() {
IndicatorSetString(INDICATOR_SHORTNAME,cstPrefix);
int wCount = 0;
for (int i = 0; i < ChartIndicatorsTotal(0,0); i++)
if (cstPrefix == ChartIndicatorName(0,0,i)) wCount++;
if (wCount >= 2) {
Alert("Only one can be inserted.");
return (INIT_FAILED);
}
ChartSetInteger(0,CHART_EVENT_MOUSE_MOVE,true);
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason) {
if (reason != REASON_INITFAILED) {
ChartSetInteger(0,CHART_EVENT_MOUSE_MOVE,false);
ObjectsDeleteAll(0,cstPrefix);
}
}
void OnChartEvent(const int id,
const long &lparam,
const double &dparam,
const string &sparam)
{
if ((id == CHARTEVENT_KEYDOWN) && (lparam == 65)) {
HLineShow = !HLineShow;
MPPD(SaveX,SaveY);
} else if ((id == CHARTEVENT_MOUSE_MOVE) || (id == CHARTEVENT_CHART_CHANGE)){
MPPD((int)lparam,(int)dparam);
}
}
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[])
{
return(rates_total);
}
void MPPD(const int X,const int Y) {
static int SaveWidth = 0;
static color SaveBack = -1;
static color SaveFore = -1;
static color SaveLine = -1;
int wWin;
string wObj;
datetime wTime;
double wPrice;
if (ChartXYToTimePrice(0,X,Y,wWin,wTime,wPrice)) {
if (wWin == 0) {
SaveX = X;
SaveY = Y;
if (mppSize >= VerySmall) {
wObj = cstPrefix+"PBK";
if (ObjectFind(0,wObj) == -1) {
if (mppBackFill) {
ObjectCreate(0,wObj,OBJ_LABEL,0,0,0);
ObjectSetInteger(0,wObj,OBJPROP_SELECTABLE,false);
ObjectSetInteger(0,wObj,OBJPROP_FONTSIZE,(mppSize+1) * 6);
ObjectSetInteger(0,wObj,OBJPROP_ANCHOR,ANCHOR_UPPER);
ObjectSetInteger(0,wObj,OBJPROP_YDISTANCE,mppY);
ObjectSetString(0,wObj,OBJPROP_FONT,"Webdings");
ObjectSetString(0,wObj,OBJPROP_TEXT,"gggg");
}
wObj = cstPrefix+"PRC";
ObjectCreate(0,wObj,OBJ_LABEL,0,0,0);
ObjectSetInteger(0,wObj,OBJPROP_SELECTABLE,false);
ObjectSetInteger(0,wObj,OBJPROP_FONTSIZE,(mppSize+1) * 6);
ObjectSetInteger(0,wObj,OBJPROP_ANCHOR,ANCHOR_UPPER);
ObjectSetInteger(0,wObj,OBJPROP_YDISTANCE,mppY);
}
int wkWidth = (int)ChartGetInteger(0,CHART_WIDTH_IN_PIXELS,0);
if (SaveWidth != wkWidth) {
SaveWidth = wkWidth;
int wkX = 0;
if (mppPos == RightView) {
wkX = wkWidth - (mppSize+1) * 16;
} else if (mppPos == CenterView) {
wkX = (int)MathFloor(wkWidth / 2);
} else {
wkX = (mppSize+1) * 16;
}
if (mppBackFill) ObjectSetInteger(0,cstPrefix+"PBK",OBJPROP_XDISTANCE,wkX+mppX);
ObjectSetInteger(0,cstPrefix+"PRC",OBJPROP_XDISTANCE,wkX+mppX);
}
color wkBack = (color)ChartGetInteger(0,CHART_COLOR_FOREGROUND,0);
color wkFore = (color)ChartGetInteger(0,CHART_COLOR_BACKGROUND,0);
if (mppBackColor != clrNONE) wkBack = mppBackColor;
if (mppFontColor != clrNONE) wkFore = mppFontColor;
if ((SaveBack != wkBack) || (SaveFore != wkFore)) {
SaveBack = wkBack;
SaveFore = wkFore;
if (mppBackFill) ObjectSetInteger(0,cstPrefix+"PBK",OBJPROP_COLOR,wkBack);
ObjectSetInteger(0,cstPrefix+"PRC",OBJPROP_COLOR,wkFore);
}
ObjectSetString(0,cstPrefix+"PRC",OBJPROP_TEXT,DoubleToString(wPrice,_Digits));
} else {
wObj = cstPrefix+"PBK";
if (ObjectFind(0,wObj) != -1) ObjectDelete(0,wObj);
wObj = cstPrefix+"PRC";
if (ObjectFind(0,wObj) != -1) ObjectDelete(0,wObj);
}
wObj = cstPrefix+"HL";
if ((HLineShow) && (mppLineWidth >= Width1)) {
if (ObjectFind(0,wObj) == -1) {
ObjectCreate(0,wObj,OBJ_HLINE,0,0,0);
ObjectSetInteger(0,wObj,OBJPROP_STYLE,mppLineStyle);
ObjectSetInteger(0,wObj,OBJPROP_WIDTH,mppLineWidth);
ObjectSetInteger(0,wObj,OBJPROP_SELECTABLE,false);
}
#ifdef __MQL5__
color wkLine = (color)ChartGetInteger(0,CHART_COLOR_BID,0);
#else
color wkLine = (color)ChartGetInteger(0,CHART_COLOR_GRID,0);
#endif
if (mppLineColor != clrNONE) wkLine = mppLineColor;
if (SaveLine != wkLine) {
SaveLine = wkLine;
ObjectSetInteger(0,wObj,OBJPROP_COLOR,wkLine);
}
ObjectSetDouble(0,wObj,OBJPROP_PRICE,wPrice);
} else {
if (ObjectFind(0,wObj) != -1) ObjectDelete(0,wObj);
SaveLine = -1;
}
ChartRedraw(0);
}
}
}