|
Programmierung MQL4 Hier gehts rund ums Programmieren in MQL4. |
|
Themen-Optionen | Thema durchsuchen | Ansicht |
|
|||
Hilfe bei Code für Multi-Symbol-Chart-Changer
Hallo alle zusammen,
ich möchte ein Tool programmieren, welches auf allen offen Charts das gleiche Symbol anzeigt, jedoch die jeweiligen Timeframes beibehält. Dazu habe ich einen ganz simplen EA mit zwei Buttons geschrieben. Der eine setzt das Symbol EURUSD und der andere USDJPY. Der EA ändert auf Knopfdruck das Symbol bei allen Charts. Das was ich leider nicht hinbekomme ist das mit dem Timeframe. Ich schaffe es nicht die jeweilige Chartperiod zu "speichern". Es wird jedes Mal auch das Timeframe des FirstChart verwendet. Kann mir jemand helfen? Hier der Code: Code:
//+------------------------------------------------------------------+ //| TEST_Button-Symbol-Changer_th.mq4 | //+------------------------------------------------------------------+ #property description "Buttons für das Ändern des Symbols auf dem gleichen Chart." #property strict #include <stderror.mqh> #include <stdlib.mqh> int OnInit() { ButtonCreate(); return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { ObjectDelete("Change_EURUSD"); ObjectDelete("Change_USDJPY"); } void OnTick() { } void OnChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam) { if(id == CHARTEVENT_OBJECT_CLICK && sparam == "Change_EURUSD") Change_EURUSD(); if(id == CHARTEVENT_OBJECT_CLICK && sparam == "Change_USDJPY") Change_USDJPY(); } void Change_EURUSD() { //--- long firstChart=ChartFirst(); while(firstChart>0) { ChartSetSymbolPeriod(firstChart,"EURUSD",0); firstChart=ChartNext(firstChart); Print(firstChart); } //--- } void Change_USDJPY() { //--- long firstChart=ChartFirst(); int timeframe=ChartPeriod(); while(firstChart>0) { ChartSetSymbolPeriod(firstChart,"USDJPY",timeframe); timeframe=(int)ChartNext(timeframe); firstChart=ChartNext(firstChart); Print(firstChart); } //--- } void ButtonCreate() { int chart_ID=0; string name="Change_EURUSD"; if(!ObjectCreate(0,name,OBJ_BUTTON,0,0,0)){Print(__FUNCTION__,": failed to create the Change_EURUSD-Button! Error code = ",GetLastError()); return;} ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,200); ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,16); ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,90); ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,30); ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,0); ObjectSetString(chart_ID,name,OBJPROP_TEXT,"EURUSD"); ObjectSetString(chart_ID,name,OBJPROP_FONT,"Arial"); ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,12); ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clrWhite); ObjectSetInteger(chart_ID,name,OBJPROP_BGCOLOR,clrSlateGray); ObjectSetInteger(chart_ID,name,OBJPROP_BORDER_COLOR,clrSlateGray); ObjectSetInteger(chart_ID,name,OBJPROP_BACK,false); ObjectSetInteger(chart_ID,name,OBJPROP_STATE,false); ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,false); ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,false); ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,false); ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,0); string name2="Change_USDJPY"; if(!ObjectCreate(0,name2,OBJ_BUTTON,0,0,0)){Print(__FUNCTION__,": failed to create the Change_USDJPY-Button! Error code = ",GetLastError()); return;} ObjectSetInteger(chart_ID,name2,OBJPROP_XDISTANCE,300); ObjectSetInteger(chart_ID,name2,OBJPROP_YDISTANCE,16); ObjectSetInteger(chart_ID,name2,OBJPROP_XSIZE,90); ObjectSetInteger(chart_ID,name2,OBJPROP_YSIZE,30); ObjectSetInteger(chart_ID,name2,OBJPROP_CORNER,0); ObjectSetString(chart_ID,name2,OBJPROP_TEXT,"USDJPY"); ObjectSetString(chart_ID,name2,OBJPROP_FONT,"Arial"); ObjectSetInteger(chart_ID,name2,OBJPROP_FONTSIZE,12); ObjectSetInteger(chart_ID,name2,OBJPROP_COLOR,clrWhite); ObjectSetInteger(chart_ID,name2,OBJPROP_BGCOLOR,clrSlateGray); ObjectSetInteger(chart_ID,name2,OBJPROP_BORDER_COLOR,clrSlateGray); ObjectSetInteger(chart_ID,name2,OBJPROP_BACK,false); ObjectSetInteger(chart_ID,name2,OBJPROP_STATE,false); ObjectSetInteger(chart_ID,name2,OBJPROP_SELECTABLE,false); ObjectSetInteger(chart_ID,name2,OBJPROP_SELECTED,false); ObjectSetInteger(chart_ID,name2,OBJPROP_HIDDEN,false); ObjectSetInteger(chart_ID,name2,OBJPROP_ZORDER,0); } |
|
|||
Diese Funktion musst Du
ENUM_TIMEFRAMES ChartPeriod( long chart_id=0 // Chart ID ); hier dazwischenschieben. while(firstChart>0) { //hier muss die Chartperiode abgefragt werden und dann statt der 0 verwendet werden ChartSetSymbolPeriod(firstChart,"EURUSD",0); firstChart=ChartNext(firstChart); Print(firstChart); } traderdoc
__________________
Ich erfülle Euch gern Eure EA-, Indikator- und Script-Programmierungswünsche auf Honorarbasis. |
|
|||
Hallo traderdoc,
danke für deine Antwort. Also das mit der Position für die Abfrage des Timeframes begreife ich, aber leider stehe ich irgendwie komplett auf dem Schlauch. Ich frage das Timeframe in der while-Schleife folgendermaßen ab: timeframe=(int)ChartNext(timeframe); So sieht meine while-Schleife aus dann aus: while(firstChart>0) { timeframe=(int)ChartNext(timeframe); ChartSetSymbolPeriod(firstChart,"EURUSD",timeframe ); firstChart=ChartNext(firstChart); Print(firstChart); } Ist die while-Schleife so richtig? Doch wo setzte ich diese Zeilen ein: ENUM_TIMEFRAMES ChartPeriod( long chart_id=0 // Chart ID ); Werden diese Zeilen genauso in die while-Schleife oder davor geschrieben? |
|
|||
Code:
void Change_EURUSD() { long firstChart=ChartFirst(); while(firstChart>0) { int tf = ChartPeriod(firstChart); ChartSetSymbolPeriod(firstChart,"EURUSD",tf); firstChart=ChartNext(firstChart); Print(firstChart); } }
__________________
Ich erfülle Euch gern Eure EA-, Indikator- und Script-Programmierungswünsche auf Honorarbasis. |
Lesezeichen |
Stichworte |
chart, chart symbol, mql4, programmierung, programmierung metatrader, programmierung mql4, symbol, tool programmieren |
|
|