Hi,
I'm a newbie.
I'm using the following code to capture the prices (open, close, max and min) every time a new candle is detected.
<SNIP>
looking in Journal messages, I always find the same price for max, min, open and close price.
the function isnewcandle() works good; it recognizes new candle so the prices printed in journal change every new candle but there are no differences between the prices above.
Please use this to post code . . . it makes it easier to read.
Hi,
I'm a newbie.
I'm using the following code to capture the prices (open, close, max and min) every time a new candle is detected.
looking in Journal messages, I always find the same price for max, min, open and close price.
the function isnewcandle() works good; it recognizes new candle so the prices printed in journal change every new candle but there are no differences between the prices above.
RaptorUK:
You are getting the data from Bar 0 when it has just opened . . . so all the values will be the same as it's Open price. You should be getting the values from Bar 1 when Bar 0 has just opened . . . then you will be getting the correct OHLC values for a completed bar.
Thanks RaptorUK.
Now it work well.
You can find my code with your suggestions.
Alex.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I'm a newbie.
I'm using the following code to capture the prices (open, close, max and min) every time a new candle is detected.
...........
int init()
{
lastCandleOpenTime = Time[0];
return(0);
}
int deinit()
{
return(0);
}
int start()
int start()
{
if (isNewCandle())
{
Print("***************** New Candle *****************");
datetime T_Bar=Time [0]; // Bar opening time
double O_Bar=Open [0]; // Bar open price
double C_Bar=Close[0]; // Bar close price
double H_Bar=High [0]; // Bar maximum price
double L_Bar=Low [0]; // Bar minimum price
Print("Bar opening time = ", TimeToStr(T_Bar));
Print("Bar open price = ", DoubleToStr(O_Bar,5));
Print("Bar close price = ", DoubleToStr(C_Bar,5));
Print("Bar maximum price = ", DoubleToStr(H_Bar,5));
Print("Bar minimum price = ", DoubleToStr(L_Bar,5));
Print("Bid = ", DoubleToStr(Bid,5));
Print("Ask = ", DoubleToStr(Ask,5));
Print("Total Orders = ", DoubleToStr(OrdersTotal(),5));
......
return(0);
}
}
bool isNewCandle()
{
//TRUE if New Candle
//FALSE if Old Candle
bool isNewCandle = false;
int v_shift = iBarShift(NULL, 0, lastCandleOpenTime, true);
if (v_shift == 0)
{
isNewCandle = false;
}
else
{
isNewCandle = true;
lastCandleOpenTime = Time[0];
}
return (isNewCandle);
}
looking in Journal messages, I always find the same price for max, min, open and close price.
the function isnewcandle() works good; it recognizes new candle so the prices printed in journal change every new candle but there are no differences between the prices above.
Can you help me?
Thanks in advance.
Alex