Download MetaTrader 5

YTD % changed - or in points

To add comments, please log in or register
Vantages
148
Vantages 2015.02.12 08:27 

Hi. May I ask if there's anyone who knows how to write the 

 YTD % changed - or in points of any particular symbol ?

Example:

EURUSD YTD% changed = Current Price - December 31,2014

 

Thanks. 

Stuart Browne
5887
Stuart Browne 2015.02.12 08:53  
Vantages:

Hi. May I ask if there's anyone who knows how to write the 

 YTD % changed - or in points of any particular symbol ?

Example:

EURUSD YTD% changed = Current Price - December 31,2014

 

Thanks. 

Hi Vantages

Sorry, are you talking about how to write it in code? MT4 or 5?

Cheers
Vantages
148
Vantages 2015.02.12 09:03  
Filter:
Hi Vantages

Sorry, are you talking about how to write it in code? MT4 or 5?

Cheers

Thank you for your response.

Yes. Right now, I only know for monthly:

 MTD = ( MarketInfo ( Symb1,MODE_BID ) - iClose ( Symb1,PERIOD_MN1,1 ) );

It would be much useful to me if I would know the YTD% & YTD points.

Thanks.

Vantages
148
Vantages 2015.02.12 09:07  
It's for MT4.
Stuart Browne
5887
Stuart Browne 2015.02.12 10:33  
Vantages:
It's for MT4.

You could try something like this. I'm not at my trading PC so can't confirm if this compiles but it should do the trick.

Do the standard 4/5 digit broker check in OnInit() (after declaring the variable "point" in your declarations):

// Broker digits
   point=Point;
   if((Digits==3) || (Digits==5))
     {
      point*=10;
     }

 Then add this in your main iteration:

   datetime EndOfYear=D'2014.12.31 00:00';
   int      EndOfYearShift=iBarShift(NULL,PERIOD_D1,EndOfYear);
   double   EndOfYearClose=iClose(Symbol(),PERIOD_D1,EndOfYearShift);
   double   CurrentPrice=MarketInfo(Symbol(),MODE_BID);
   double   YTDPoints=( (CurrentPrice - EndOfYearClose)/point );
   double   YTDPercent = ( (CurrentPrice - EndOfYearClose) ) / (CurrentPrice )* 100;
   Comment  ("Points: ", YTDPoints, " Percent: ", YTDPercent, "%");

 

Hope that points you in the right direction

Cheers
Stu

Vantages
148
Vantages 2015.02.12 13:07  

Hello. Thank you very much.

It was written perfectly!

Stuart Browne
5887
Stuart Browne 2015.02.12 23:04  
Vantages:

Hello. Thank you very much.

It was written perfectly!

Good stuff :) You're very welcome
To add comments, please log in or register