How to calculate the Close and Open price of candle?

 

Hey,

I'm a little stuck here while making a modification in broker interface. Now I need to write a function that correctly recalculate the OHLC prices of candles in metatrader platform.

Metatrader 3 chart combines both Bid and Ask price in the same candle (High of candle is the highest ask price, Low is the lowest bid price, Open and Close = Bid + Ask / 2). What I'd like to do here is to recalculate candle OHLC to be based in Bid price only. It seems easy, but...

The problem here is how to calculate the Open and Close price when the result of Bid + Ask / 2 is need to be round up (has a value smaller in a pip). Example, Bid + Ask /2 of EURUSD = 1.24485. This price cannot be display on chart, so what is the way to round it? I've observed this for a day now, and i'm still very confused. Sometimes, MetaTrader round it down to 1.2448, but sometimes round it up to 1.2449.

Hope you can help me with this.

 

isnt the difference between bid and ask alwasy 2 pips? for example the Ask = Bid+2 and Bid = Ask-2 I think thats what I understood last time I checked...

 

as far as i heard the difference between bid and ask price is the spread. if it is 2 then its 2 , if 4 then 4 and so on.

 
Ravique:
as far as i heard the difference between bid and ask price is the spread. if it is 2 then its 2 , if 4 then 4 and so on.

Ooops i was concentrating on Interbankfx's EUR/USD which is 2. Yeh I saw that ask - bid = spread

 

You don't understand what I said. Let's take a close-up look on how MetaTrader display the Close price of the last candle in EURUSD chart.

I thought MetaTrader display the latest Close price = (latest Bid + latest Ask) / 2. Example 1: Bid = 1.2000, Ask = 1.2002, then Close = 1.2001. But what if the spread is 3 pips. Example 2: Bid = 1.2000, Ask =1.2003, then Close = 1.20015. Have you seen MetaTrader displayed 1.20015 (it contains undisplayable 0.5 pip) in EURUSD chart? never. It's because MetaTrader rounds up the price to a displayable price.

I figured it out last two days that MetaTrader uses the Normalize() function to round up the undealable or undisplayable price. That for sure means Close = Normalize((Bid + Ask) / 2).

What I wanted to do here is to reverse Close price back to Bid. This means I have to reverse the price rounding (denomalize). Unfortunately reverse the priceing rounding is only 50% accurate which is unacceptable.

 

I get what you mean, sorry I couldn't help

 

Hi,

What Do I Have To Do TO Get My Ea To Work On A Real Acct With Micro Acct. I've Got A Number Of Eas That Won't Work On The Real ACCT But Worked Well On The Demos- What Seems To Be The Problem Here, Help And Fast Please.

ADEBOWALE