I wrote an EA that I put on a graph (M1). I want it to put a line (object) on another graph (M5) which already exists. Is it possible ? How can I do that ?
Christian
Hi,
Thanks for your reply. That's what I did, but seems not to run fine.
It's OK on the graph which receives th EA, but not on others.
Here's my code, in a class (would you have a tip ?) :
CCrossHair::CCrossHair(void)
{
long ChartId=0;
string HLineName;
for (ChartId=0; ChartId < ChartsCount(); ChartId++)
{
HLineName = cHLineName + ChartId;
ObjectCreate(ChartId,HLineName,OBJ_HLINE,0,0,0);
ObjectSetDouble(ChartId,HLineName,OBJPROP_PRICE,0,1.3273);
}
}
long ChartsCount(void)
{
long currChart,prevChart=ChartFirst();
long ChartsCount=0,limit=100, ChartId=0;
while(ChartsCount<limit)// We have certainly not more than 100 open charts
{
currChart=ChartNext(prevChart); // Get the new chart ID by using the previous chart ID
if(currChart<0) break; // Have reached the end of the chart list
prevChart=currChart;// let's save the current chart ID for the ChartNext()
ChartsCount++;// Do not forget to increase the counter
}
return (ChartsCount);
}
1. Would you please edit your code using SRC button, it will make easier for other user, reading your code
Move and hover your cursor on bottom right of your comment and you will find edit link,
2. Why are you using CCrossHair to draw a horizontal line ?, Why don't you use ChartObject.mqh or ChartObjectsLines.mqh or simply using Object Functions ?
3. I don't have CCrossHair, so I use Object Functions in my script below.
First find the ID of the chart with the same symbol like ours but with 5 minute time frame, when found, draw the lines. Read that again, because that's the error of your code.
long Next_Chart, Curr_Chart; int i, limit = 100; MqlTick current_price; SymbolInfoTick(_Symbol,current_price); Curr_Chart = ChartFirst(); for(i = 0; i < limit; i++) // We have certainly not more than 100 open charts { if (ChartPeriod(Curr_Chart) == PERIOD_M5 && ChartSymbol(Curr_Chart) == _Symbol) { // Found chart that have the same symbol and period is 5 minuts Print(current_price.bid); ObjectCreate(Curr_Chart,"Object Name", OBJ_HLINE, 0, 0, current_price.bid - 50*_Point); break; } Next_Chart = ChartNext(Curr_Chart); // Get the new chart ID by using the previous chart ID if(Next_Chart < 0) break; // Have reached the end of the chart list Curr_Chart = Next_Chart; // let's save the current chart ID for the ChartNext() }
Thanks : it's running fine.
Christian
//+------------------------------------------------------------------+ //| Cross Hair.mq5 | //| Copyright France, 02 Jan 2013 , Christian | //| https://www.mql5.com/en/users/c2h | //+------------------------------------------------------------------+ #property copyright "Copyright France, 02 Jan 2013 , Christian" #property link "https://www.mql5.com/en/forum/9805#comment_398422" #property version "1.00" #include "_c2h_crosshair.mqh" CCrossHair CrossHair; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { return (0); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { } void OnChartEvent(const int id, // event ID const long& lparam, // event parameter of the long type const double& dparam, // event parameter of the double type const string& sparam) // event parameter of the string type { CrossHair.ChartEvent(id,lparam,dparam,sparam); } & the class : #include <ChartObjects\ChartObject.mqh> class CCrossHair { private: public: CCrossHair(void); ~CCrossHair(void); void ChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam); protected: }; const string cHLineName="H Line"; const string cVLineName="V Line"; const color cCrossHairColor = clrBlack; const int cCrossHairStyle = STYLE_DOT; //+------------------------------------------------------------------+ //| Constructor | //+------------------------------------------------------------------+ CCrossHair::CCrossHair(void) { string HLineName, VLineName; long currChart,i; long limit=100; currChart = ChartFirst(); for(i = 0; i < limit; i++)// We have certainly not more than 100 open charts { HLineName = cHLineName + currChart; VLineName = cVLineName + currChart; ObjectCreate(currChart,HLineName,OBJ_HLINE,0,0,0); ObjectCreate(currChart,VLineName,OBJ_VLINE,0,0,0); ObjectSetInteger(currChart,HLineName,OBJPROP_STYLE,cCrossHairStyle); ObjectSetInteger(currChart,VLineName,OBJPROP_STYLE,cCrossHairStyle); ObjectSetInteger(currChart,HLineName,OBJPROP_COLOR,cCrossHairColor); ObjectSetInteger(currChart,VLineName,OBJPROP_COLOR,cCrossHairColor); ChartSetInteger(currChart,CHART_EVENT_MOUSE_MOVE,true); currChart = ChartNext(currChart); // Get the new chart ID by using the previous chart ID if(currChart < 0) break; // Have reached the end of the chart list } return; } //+------------------------------------------------------------------+ //| Destructor | //+------------------------------------------------------------------+ CCrossHair::~CCrossHair(void) { string HLineName, VLineName; long currChart,i; long limit=100; currChart = ChartFirst(); for(i = 0; i < limit; i++)// We have certainly not more than 100 open charts { HLineName = cHLineName + currChart; VLineName = cVLineName + currChart; ObjectDelete(currChart,HLineName); ObjectDelete(currChart,VLineName); currChart = ChartNext(currChart); // Get the new chart ID by using the previous chart ID if(currChart < 0) break; // Have reached the end of the chart list } return; } //+------------------------------------------------------------------+ //| code | //+------------------------------------------------------------------+ void CCrossHair::ChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { if(id==CHARTEVENT_MOUSE_MOVE) { int x =(int)lparam; int y =(int)dparam; datetime dt =0; double price =0; int window=0; string HLineName, VLineName; long currChart,i; long limit=100; ChartXYToTimePrice(0,x,y,window,dt,price); currChart = ChartFirst(); for(i = 0; i < limit; i++) // We have certainly not more than 100 open charts { HLineName = cHLineName + currChart; VLineName = cVLineName + currChart; ObjectCreate(currChart,HLineName,OBJ_HLINE,0,0,0); ObjectCreate(currChart,VLineName,OBJ_VLINE,0,0,0); ObjectSetInteger(currChart,VLineName,OBJPROP_TIME,dt); ObjectSetDouble(currChart,HLineName,OBJPROP_PRICE,0,price+.00005); ChartRedraw(currChart); currChart=ChartNext(currChart); // Get the new chart ID by using the previous chart ID if(currChart<0) break; // Have reached the end of the chart list } } }
Thanks : it's running fine.
Christian
You're welcome :D.
However, if you open several chart with different symbols and time frames, your code there, will draw object on each and every charts.
Are you trying to draw cross hairs on all different charts or just the same symbol ?.
BTW, FinGeR already created one https://www.mql5.com/en/forum/4709
I trade only on one symbol. I think it's possible to improve code.
I saw the tool of FinGeR, but because I already have other EA, I couldn't use it. That's why I'm trying to create a new one I can implement in my other tools.
Christian
I trade only on one symbol. I think it's possible to improve code.
I saw the tool of FinGeR, but because I already have other EA, I couldn't use it. That's why I'm trying to create a new one I can implement in my other tools.
Christian
OK Christian,
Good luck and may the pips be with you.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I wrote an EA that I put on a graph (M1). I want it to put a line (object) on another graph (M5) which already exists. Is it possible ? How can I do that ?
Christian