//+------------------------------------------------------------------+ //| OptionLine.mq4 | //| Rondo | //| http://fx-dollaryen.seesaa.net/ | //+------------------------------------------------------------------+ #property copyright "Rondo" #property link "http://fx-dollaryen.seesaa.net/" #property version "1.0" #property indicator_chart_window #property strict input ENUM_LINE_STYLE LineStyle = STYLE_DASHDOTDOT; //ラインスタイル input int LineWidth = 1; //幅 input color LineColor = clrWhite; //色 input ENUM_BASE_CORNER Corner = CORNER_RIGHT_LOWER; //ラベル表示位置 input int InpX = 3; //横軸 input int InpY = 3; //縦軸 input int InpFontSize = 8; //大きさ input color InpColor = clrGray; //色 string fileName = ""; string IndicatorName = "OptionLine"; bool DisplayON = true; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init(){ if(StringFind(_Symbol, "USDJPY") >= 0) fileName = "OP_USDJPY.txt"; else if(StringFind(_Symbol, "EURJPY") >= 0) fileName = "OP_EURJPY.txt"; else if(StringFind(_Symbol, "EURUSD") >= 0) fileName = "OP_EURUSD.txt"; else if(StringFind(_Symbol, "GBPUSD") >= 0) fileName = "OP_GBPUSD.txt"; else if(StringFind(_Symbol, "AUDUSD") >= 0) fileName = "OP_AUDUSD.txt"; else fileName = "OP_others.txt"; LabelCreate("OP_Label", Corner, InpX, InpY, InpFontSize, InpColor); if(!FileIsExist(fileName)){ int file_handle = FileOpen(fileName, FILE_READ | FILE_WRITE | FILE_CSV); FileClose(file_handle); } return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit(){ for(int i=ObjectsTotal();i>=0;i--){ string ObjName = ObjectName(i); if(StringFind(ObjName, IndicatorName) >=0) ObjectDelete(ObjName); } ObjectDelete("OP_Label"); return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start(){ return(0); } void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam){ if(id == CHARTEVENT_OBJECT_CLICK){ if(sparam == "OP_Label"){ if(DisplayON){ int file_handle; int counts = 0; file_handle = FileOpen(fileName, FILE_READ | FILE_WRITE | FILE_CSV); string str; while(!FileIsEnding(file_handle)){ str = FileReadString(file_handle); if(str == "") continue; string strPrice = ""; for(int i=1; i<=StringLen(str); i++){ string strBuf = StringSubstr(str, 0, i); if(StringFind(str, "ドル") >= 0){ strPrice = StringSubstr(str, 0, StringFind(str, "ドル")); strPrice = StringSubstr(strPrice, 0, StringFind(strPrice, "-")); break; } if(StringFind(str, "円") >= 0){ strPrice = StringSubstr(str, 0, StringFind(str, "円")); strPrice = StringSubstr(strPrice, 0, StringFind(strPrice, "-")); break; } //半角スペース if(StringFind(str, " ") >= 0){ strPrice = StringSubstr(str, 0, StringFind(str, " ")); strPrice = StringSubstr(strPrice, 0, StringFind(strPrice, "-")); break; } //全角スペース if(StringFind(str, " ") >= 0){ strPrice = StringSubstr(str, 0, StringFind(str, " ")); strPrice = StringSubstr(strPrice, 0, StringFind(strPrice, "-")); break; } } double Price = StringToDouble(strPrice); LineCreate(IndicatorName+IntegerToString(counts), Price, LineStyle, LineWidth, LineColor); TextCreate(IndicatorName+"Text"+IntegerToString(counts), str, Time[WindowBarsPerChart()/2], Price, 8, LineColor); counts++; } FileClose(file_handle); DisplayON = false; } else{ for(int i=ObjectsTotal();i>=0;i--){ string ObjName = ObjectName(i); if(StringFind(ObjName, IndicatorName) >=0) ObjectDelete(ObjName); } DisplayON = true; } } } } void LabelCreate(string Label_name, int pos_corner, int pos_x, int pos_y, int font_size, color text_color){ long current_chart_id = ChartID(); if(ObjectFind(Label_name) != 0){ ObjectCreate(Label_name, OBJ_LABEL, 0, 0, 0); ObjectSetText(Label_name, "[ OP表示 ]", font_size, "MS ゴシック", text_color); ObjectSet(Label_name, OBJPROP_CORNER, pos_corner); ObjectSet(Label_name, OBJPROP_XDISTANCE, pos_x); ObjectSet(Label_name, OBJPROP_YDISTANCE, pos_y); ObjectSetInteger(current_chart_id, Label_name, OBJPROP_BACK, true); ObjectSetInteger(current_chart_id, Label_name, OBJPROP_SELECTABLE, false); ObjectSetInteger(current_chart_id, Label_name, OBJPROP_HIDDEN, true); } else{ ObjectSet(Label_name, OBJPROP_CORNER, pos_corner); ObjectSet(Label_name, OBJPROP_XDISTANCE, pos_x); ObjectSet(Label_name, OBJPROP_YDISTANCE, pos_y); } WindowRedraw(); } void LineCreate(string Line_Name, double price, int Line_Style, int Line_Width, color Line_Color){ long current_chart_id = ChartID(); if(ObjectFind(current_chart_id, Line_Name) != 0){ ObjectCreate(current_chart_id, Line_Name, OBJ_HLINE, 0, 0, price); ObjectSetInteger(current_chart_id, Line_Name, OBJPROP_STYLE, Line_Style); ObjectSetInteger(current_chart_id, Line_Name, OBJPROP_WIDTH, Line_Width); ObjectSetInteger(current_chart_id, Line_Name, OBJPROP_COLOR, Line_Color); ObjectSetInteger(current_chart_id, Line_Name, OBJPROP_BACK, false); ObjectSetInteger(current_chart_id, Line_Name, OBJPROP_SELECTABLE, false); ObjectSetInteger(current_chart_id, Line_Name, OBJPROP_HIDDEN, true); } else{ ObjectMove(current_chart_id, Line_Name, 0, 0, price); ObjectSetInteger(current_chart_id, Line_Name, OBJPROP_STYLE, Line_Style); ObjectSetInteger(current_chart_id, Line_Name, OBJPROP_WIDTH, Line_Width); ObjectSetInteger(current_chart_id, Line_Name, OBJPROP_COLOR, Line_Color); } ChartRedraw(current_chart_id); } void TextCreate(string Text_name, string content, datetime time, double price, int Text_Size, color Text_Color){ long current_chart_id = ChartID(); if(ObjectFind(Text_name) != 0){ ObjectCreate(current_chart_id, Text_name, OBJ_TEXT, 0, time, price); ObjectSetString(current_chart_id, Text_name, OBJPROP_TEXT, content); ObjectSetString(current_chart_id, Text_name, OBJPROP_FONT, "メイリオ"); ObjectSetInteger(current_chart_id, Text_name, OBJPROP_FONTSIZE, Text_Size); ObjectSetInteger(current_chart_id, Text_name, OBJPROP_COLOR, Text_Color); ObjectSetInteger(current_chart_id, Text_name, OBJPROP_BACK, false); ObjectSetInteger(current_chart_id, Text_name, OBJPROP_SELECTABLE, false); ObjectSetInteger(current_chart_id, Text_name, OBJPROP_HIDDEN, true); } else{ ObjectSetString(current_chart_id, Text_name, OBJPROP_TEXT, content); ObjectSetInteger(current_chart_id, Text_name, OBJPROP_WIDTH, Text_Size); ObjectSetInteger(current_chart_id, Text_name, OBJPROP_COLOR, Text_Color); } ChartRedraw(current_chart_id); }