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

Do you need a programmer? Freelance service will find the developer you need!
296
2014.09.27 19:06

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!

5423
2014.09.28 02:43
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

296
2014.09.28 05:10
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?

886
2014.09.28 05:55
you can use periods of one day and substract the high with the low. Or search the market to use already coded indicator/script.
296
2014.09.28 15:39
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?

4963
2014.09.28 17:26
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));
//...```