Download MetaTrader 5
To add comments, please log in or register
Have you just installed MetaTrader 5? Learn it in details!
Philb1
33
Philb1 2016.06.25 11:36 

Hi.. This is my first post here so apologies if it's in the wrong place

I'm a reasonably competent self taught VBA coder & thought that as the syntax is sort of similar to VBA, that I'd have a go at MQL4.

I've written some code that places a label on the chart which is dependent on the chart shift. The problem I have is the label is being displayed in different places, and the cause seems to be related to the differences in chart size when MT4 opens, and the chart size when MT4 is already open & the Compile button is pressed. The chart width is 1564 on open and when the compile button is pressed it's 1854. To get around this I'm trying to use ChartTimePriceToXY, the problem I have is I can't get any output from it and the same goes with iOpen. I've tried entering the values directly in both functions/operations and both functions/operations report multiple errors. I created variables and loaded them with a value, then entered them as in the code below to get rid of the errors. It is the only way I can find to stop errors but the problem is I get no x or y output from ChartTimePriceToXY and no price from iOpen, so something's wrong. The markets are closed at the moment and I presuming the last server time & price would be used for the functions?

I'm completely stuck, can someone help me with a working example, or point out what I've done wrong in layman's terms with the functions/operations please.

Thanks

long ChartNm = ChartID();
int SubWin = 1;
datetime GimmeTime = TimeCurrent();
double CurrPrice = MarketInfo(Symbol(),MODE_BID);
string AssetName = Symbol();
int Per = Period();
int Shft = 1;

double iOpen(string AssetName,int Per,int Shft);
bool ChartTimePriceToXY(long ChartNm,int SubWin,datetime GimmeTime,double CurrPrice,int x,int y);
Ernst Van Der Merwe
4629
Ernst Van Der Merwe 2016.06.25 13:00  
   long ChartNm = ChartID();
   int SubWin = 0;
   //datetime GimmeTime = TimeCurrent();
   //double CurrPrice = MarketInfo(Symbol(),MODE_BID);
   string AssetName = Symbol();
   int Per = Period();
   int Shft = 10;
   datetime GimmeTime = iTime(AssetName,Per,Shft);
   double CurrPrice = iOpen(AssetName,Per,Shft);
   int x,y;
   ChartTimePriceToXY(ChartNm,SubWin,GimmeTime,CurrPrice,x,y);
   if(ObjectFind(ChartNm,"my Label")!=-1)
      ObjectDelete(ChartNm,"my Label");
   if(!ObjectCreate(ChartNm,"my Label",OBJ_LABEL,SubWin,0,0))
      return(0);
   ObjectSetInteger(ChartNm,"my Label",OBJPROP_XDISTANCE,x);
   ObjectSetInteger(ChartNm,"my Label",OBJPROP_YDISTANCE,y);
   ObjectSetInteger(ChartNm,"my Label",OBJPROP_XSIZE,50);
   ObjectSetInteger(ChartNm,"my Label",OBJPROP_YSIZE,30);
   ObjectSetInteger(ChartNm,"my Label",OBJPROP_COLOR,clrRed);
   ObjectSetString(ChartNm,"my Label",OBJPROP_TEXT,"some text");
Philb1
33
Philb1 2016.06.26 08:14  

Hi pipPod.. Thanks for the reply

I've had a play with your code and have got it working with  ObjectCreate("TestLabel",OBJ_LABEL,SubWin,0,0);  It didn't matter what I did I couldn't get the ObjectSetInteger way of doing it to work properly. I did get text on the screen once with it once, but it was jammed in the top left corner.

You've helped me get it working and now it's working I can experiment more :)

Thanks

Phil

/
To add comments, please log in or register