Learning MQL4. Stuck on a very simple thing

 

I'm slowly learning MQL4 and I would prefer to learn for myself rather than have everything handed to me on a platter. If anyone can help me on the following sticking point, that would be greatly appreciated.

I am basically trying to display the current exchange rate of a particular currency pair as a Comment at the top left. Here is what I have so far:

int init()
  {

double eurate=iClose("EURUSD",0,0); 

Comment("EU rate is ",DoubleToStr(eurate,4));


   return(0);
}

I know this is a very simple problem but as somebody who only started learning MQL4 a few days ago, this is a mountain of a task! I'm not even sure if iClose was the right thing to choose.

 
eempc:

I'm slowly learning MQL4 and I would prefer to learn for myself rather than have everything handed to me on a platter. If anyone can help me on the following sticking point, that would be greatly appreciated.

I am basically trying to display the current exchange rate of a particular currency pair as a Comment at the top left. Here is what I have so far:

<CODE DELETED> 

I know this is a very simple problem but as somebody who only started learning MQL4 a few days ago, this is a mountain of a task! I'm not even sure if iClose was the right thing to choose.

Please edit your post . . . 

 

Use SRC 

 
eempc:

I'm slowly learning MQL4 and I would prefer to learn for myself rather than have everything handed to me on a platter. If anyone can help me on the following sticking point, that would be greatly appreciated.

I am basically trying to display the current exchange rate of a particular currency pair as a Comment at the top left. Here is what I have so far:

I know this is a very simple problem but as somebody who only started learning MQL4 a few days ago, this is a mountain of a task! I'm not even sure if iClose was the right thing to choose.

Code in  init()  just gets called when the Indicator/EA  foirst runs or is re-initialised,  your code should go in start()

The current price of the symbol that your code is running on is Bid,  if you specifically want the Bid price for a different symbol you can use MarketInfo()  with    MODE_BID  

 
RaptorUK:

Code in  init()  just gets called when the Indicator/EA  foirst runs or is re-initialised,  your code should go in start()

The current price of the symbol that your code is running on is Bid,  if you specifically want the Bid price for a different symbol you can use MarketInfo()  with    MODE_BID  


Thanks for letting me know about both SRC and Marketinfo() :)

 
RaptorUK:

Please edit your post . . . 

 

 



Nice done Simon this explanation how to use SRC button 
 
deVries:

Nice done Simon this explanation how to use SRC button 
Thank you :-)  I created it last night with a few layers in PhotoShop, exported to jpg, then combined into an animated GIF,  I've been itching to use it all day  :-D  
 

And on other news, I completed my Comment-based lot size calculator. A very proud moment for me!

I wish you happy trades :)

 
eempc:

And on other news, I completed my Comment-based lot size calculator. A very proud moment for me!

I wish you happy trades :)

Well done  :-)   what's next ?
 

Not sure, lol

When I was reading C for dummies, the author said that step 1 was to think of something to programme and that it was also the hardest step! I think I have to agree.

 
mop0:
int init(){
double eurate=iClose("EURUSD",0,0); 

Don't try to use any price (or indicator) or server related functions in OnInit (or on load or in OnTimer before you've received a tick), as there may be no connection/chart yet:

  1. Terminal starts.
  2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
  3. OnInit is called.
  4. For indicators OnCalculate is called with any existing history.
  5. Human may have to enter password, connection to server begins.
  6. New history is received, OnCalculate called again.
  7. New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.