Download MetaTrader 5

Calculate the daily difference between highest price and lowest price, how to?

To add comments, please log in or register
nicolasxu
304
nicolasxu  

I have a simple task: Calculate the daily difference between highest price and lowest difference and print the result in the console.

 

 

So far I can only successfully do:

void OnTick()
  {
//---
   SymbolInfoTick("EURUSD", tickInfo);
   Print(tickInfo.last);
  }

Can anybody give a sample code for this simple task?

Thanks!

Dua Yong Rew
5476
Dua Yong Rew  
nicolasxu:

I have a simple task: Calculate the daily difference between highest price and lowest difference and print the result in the console.

 

 

So far I can only successfully do:

Can anybody give a sample code for this simple task?

Thanks!

you need to loop for the number of days you need else just copy the daily rates and do a high minus low

or even atr can suit 

nicolasxu
304
nicolasxu  
doshur:

you need to loop for the number of days you need else just copy the daily rates and do a high minus low

or even atr can suit 

Thanks a lot for helping. How do I copy the daily rates? 

Use SymbolInfoTick?  

Irwan Adnan
921
Irwan Adnan  
you can use periods of one day and substract the high with the low. Or search the market to use already coded indicator/script.
nicolasxu
304
nicolasxu  
belido:
you can use periods of one day and substract the high with the low. Or search the market to use already coded indicator/script.

 void OnTick()

  {

//---

   Print("The Period() returns: " + Period());

  }

Above are my code. The value Period() returns is always 16385, no matter how I set the period of the chart.

I set the chart period by clicking right button on chart, e.g.: EURUSD, and then select Periodicity-> M1.

No matter how I set the Periodicity, M1, Daily, Weekly. Period() always returns 16385. I am using test data. 

What did I do wrong?  Should I expect Period() to change if I change Periodicity? 

Jose Miguel Soriano
5003
Jose Miguel Soriano  
nicolasxu:

I have a simple task: Calculate the daily difference between highest price and lowest difference and print the result in the console.

 

 

So far I can only successfully do:

Can anybody give a sample code for this simple task?

Thanks!

 Is this what you want?

//+---------------------------------------  iHIGH ---------------------------+
double iHigh(string simb, ENUM_TIMEFRAMES marcoTmp, int nVela= 0)
  {
   double array[1]= {0};
   int nCopiado= CopyHigh(simb, marcoTmp, nVela, 1, array);
   return(array[0]);       //si el valor devuelto es cero, falló la función
  }

//+------------------------------------------- iLOW -----------------------+

double iLow(string simb, ENUM_TIMEFRAMES marcoTmp, int nVela= 0)
  {
   double array[1]= {0};
   int nCopiado= CopyLow(simb, marcoTmp, nVela, 1, array);
   return(array[0]);       //si el valor devuelto es cero, falló la función
  }

//...
double difPrecio= iHigh(simb, PERIOD_D1, 0) - iLow(simb, PERIOD_D1, 0);
Print(DoubleToString(difPrecio));
//...
To add comments, please log in or register