Metatrader Forum | Forex Expert-Advisor | Broker & Forex Tools

Metatrader Forum | Forex Expert-Advisor | Broker & Forex Tools (http://www.expert-advisor.com/forum/index.php)
-   Programmierung MQL4 (http://www.expert-advisor.com/forum/forumdisplay.php?f=220)
-   -   Hilfe bei Code für Multi-Symbol-Chart-Changer (http://www.expert-advisor.com/forum/showthread.php?t=5946)

dundale 12.12.17 21:56

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);
}


traderdoc 13.12.17 12:32

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

dundale 13.12.17 22:40

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?

traderdoc 13.12.17 22:53

Code:

void Change_EURUSD() {
  long firstChart=ChartFirst();
  while(firstChart>0) {
      int tf = ChartPeriod(firstChart);
      ChartSetSymbolPeriod(firstChart,"EURUSD",tf);
      firstChart=ChartNext(firstChart);
      Print(firstChart);
  }
}

traderdoc

dundale 14.12.17 00:06

Es funktioniert, ich bin begeistert.
Vielen Dank.


Alle Zeitangaben in WEZ +2. Es ist jetzt 10:48 Uhr.

Powered by vBulletin® Version 3.8.5 (Deutsch)
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.6.1
Powered by vBCMS® 2.7.0 ©2002 - 2024 vbdesigns.de
Copyright ©2009 - 2023 by Expert-Advisor.com - Das Metatrader Forum