Einzelnen Beitrag anzeigen
  #1 (permalink)  
Alt 12.12.17
dundale dundale ist offline
Neues Mitglied
 
Registriert seit: Oct 2016
Beiträge: 25
dundale befindet sich auf einem aufstrebenden Ast
Standard 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);
}