Jump to content

Percentage gain/loss from yesterday close


Recommended Posts

I think you're missing a variable.

 

Do you mean percentage of yesterdays range? Increase or decrease from yesterdays close wouldn't be possible as you don't have a range from which to gauge a percentage increase/decrease.

 

For example if yesterdays close was 10 and today is 12 what percentage would that be?

 

Hope that makes sense.

 

Lux

Link to comment
Share on other sites

What does LTP stand for?

 

Put this together quickly based on your above formula but not sure what it's supposed to be showing.

 

//+------------------------------------------------------------------+
//|                                                   #krishna79.mq4 |
//|                      
//+------------------------------------------------------------------+


/*
  Yesterday close = 4921 (A)
  Current price (LTP) = 4863 (B)

  1. Percentage = ((B-A)/B)*100

  2. Price difference = B - A
*/

#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
 {
//---- indicators
//----
  return(0);
 }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
 {
//----
  
//----
  return(0);
 }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
 {
  
//----
  static double dYesterdaysClose;
  
  // check for new day 
  if(dYesterdaysClose == 0 || NewDay()){
     dYesterdaysClose = iClose(Symbol(),PERIOD_D1,1);
  }
  
  Comment(DoubleToStr(((dYesterdaysClose-Bid)/Bid)*100,2));
  
//----
  return(0);
 }
//+------------------------------------------------------------------+

bool NewDay(){
static datetime LastTime = 0;

if (iTime(Symbol(),PERIOD_D1,0) != LastTime) {
	LastTime = iTime(Symbol(),PERIOD_D1,0) ;		
	return (true);
} else
	return (false);
}

 

Lux

Edited by luxinterior
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...