"How can Close[0] return the closing price of a current bar, when current bar is not yet closed"
fwiw:
it cannot - it always the close of last/current data tick from server
[0] is currently 'building' bar
[1] is latest 'complete' bar
think:
EA start() run 'each' data tick
>= 0 data ticks per bar
am i working on data ticks OR closed/completed bars?
how i 'know' when bar complete? search site = masses info on this
.
just thots
hth
Close[0] = Bid
Thanks guys.
Other than that, does the EA seem to be doing the job of alerting when Price is very close to the BB? Not sure if the last parm in iBand(...) should be 0 or 1.
"does the EA seem to be doing the job of alerting when Price is very close to the BB?"
well - u could just run the code to answer that question ;)
"Not sure if the last parm in iBand(...) should be 0 or 1"
why not try both values in 2 EAs on 2 charts with same sym/period - u find out then...
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- 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,
The goal of my simple EA is to Print when the Price is very close to the Bollinger Bands.
Can someone review if this is correct? My primary doubt is about using Close[0] or Close[1]. How can Close[0] return the closing price of a current bar, when current bar is not yet closed.
Thanks,
JForex.
static int curr_bar;
int start()
{
double UBand = iBands (NULL,0,20,2,0,PRICE_CLOSE,MODE_UPPER,0);
double LBand = iBands (NULL,0,20,2,0,PRICE_CLOSE,MODE_LOWER,0);
double lGap = Close[0] - LBand; // Distance between price and lower BB.
double uGap = UBand - Close[0]; // Distance between price and upper BB.
if (curr_bar < Bars){ // Notify only once per Bar.
if ( lGap <= 0.0002 ) { // If distance is very close, notify.
Print("LowBB: " + LBand + " Close[0]: " + Close[0] + " Gap: " + lGap);
}
if ( uGap <= 0.0002 ) { // If distance is very close, notify.
Print("UppBB: " + UBand + " Close[0]: " + Close[0] + " Gap: " + uGap );
}
curr_bar = Bars; // Update that current bar has been considered.
}
return(0);
}