![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I don't understand different.
Probably void function is not available
On Tick function is available but I want to do it in the void function
Close[0] is the bid price, easy
Yes,it's easy to get in the On Tick function, But Close[0] and Bid can't get close price of the current bar in the void function.
The close price of the current chart (Close[0]) equals Bid, always.
You can read any bar in any function; void function is irrelevant.
The close price of the current chart (Close[0]) equals Bid, always.
You can read any bar in any function; void function is irrelevant.
#11 and #12 are same code, but got different price. Why are the same code but different results?
Here is the entire code.
Since Close [0] in the if statement of Order send does not get the price of Bid, a becomes 0 and entry is not possible in the first place.
double a = MathAbs(Close[0]-Open[0]);← I don’t understand (Close[0] = Open[0])
so ↑a=0 that's why a*3.0>average = 0
Fernando explained already that you code only runs for first Tick at every bar.
When new Tick comes to your code, it means new price is coming. During a period of time ( Timeframe) many ticks will come, and High Low Open Close will be defined for the current Bar. High, means the Highest price during that particular Bar, Low means the Lowest price, Open is the Opening price of the Bar, and Close is the closing price ( as explained above, if the Bar is not yet closed, Close[0] == Bid ). So we will use Bid instead of Close[0].
No we go back again to the example above. You are on 1Hr Timeframe, and it is 13:00 and new Bar is starting:
First Tick of the new Bar arrived ( Tick == new price). So for the current Bar we only have one price. Lets say first price of the new bar is 0.12345.
Now we analize :
What is Opening Price ? is very first price arrived for the current Bar = 0.12345
What is High : as stated above High is Highest price received for this Bar. But for our Bar we only received one price ( first Tick) so High it will be also 0.12345
What is Low : as stated above Low is Lowest price received for this Bar. But for our Bar we only received one price ( first Tick) so Low it will be also 0.12345
And what is Bid : Bid is last price received, which is also 0.12345 and since bar is not yet closed, we said that Close[0] == Bid.
So you see, as Fernando said, at very first tick all price calculation for the Bar are equal. Close[0] == Open[0] == High[0] == Low[0]; because it is only one price available.
You Code only runs only for the first Tick of every bar, so always Open[0] == Close[0].
That is why in your code, if you want to test if price crossed over MA, you should compare Close[2] with Close[1]
Fernando explained already that you code only runs for first Tick at every bar.
When new Tick comes to your code, it means new price is coming. During a period of time ( Timeframe) many ticks will come, and High Low Open Close will be defined for the current Bar. High, means the Highest price during that particular Bar, Low means the Lowest price, Open is the Opening price of the Bar, and Close is the closing price ( as explained above, if the Bar is not yet closed, Close[0] == Bid ). So we will use Bid instead of Close[0].
No we go back again to the example above. You are on 1Hr Timeframe, and it is 13:00 and new Bar is starting:
First Tick of the new Bar arrived ( Tick == new price). So for the current Bar we only have one price. Lets say first price of the new bar is 0.12345.
Now we analize :
What is Opening Price ? is very first price arrived for the current Bar = 0.12345
What is High : as stated above High is Highest price received for this Bar. But for our Bar we only received one price ( first Tick) so High it will be also 0.12345
What is Low : as stated above Low is Lowest price received for this Bar. But for our Bar we only received one price ( first Tick) so Low it will be also 0.12345
And what is Bid : Bid is last price received, which is also 0.12345 and since bar is not yet closed, we said that Close[0] == Bid.
So you see, as Fernando said, at very first tick all price calculation for the Bar are equal. Close[0] == Open[0] == High[0] == Low[0]; because it is only one price available.
You Code only runs only for the first Tick of every bar, so always Open[0] == Close[0].
That is why in your code, if you want to test if price crossed over MA, you should compare Close[2] with Close[1]
Ok, Thank you. So does this code mean that BId (Close [0]) only get the first tick?
How can I get the last tick?
I want to get the last Tick (ex100, not closed) of the Bar with the Order Send above and complete it.
Ok, Thank you. So does this code mean that BId (Close [0]) only get the first tick?
How can I get the last tick?
You can't know when a candle closes. Only when a new tick arrives that starts a new bar is the old bar closed.
For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart), volume is unreliable (miss ticks), Price is unreliable (duplicate prices and The == operand. - MQL4 programming forum.) Always use time.
MT4: New candle - MQL4 programming forum #3 (2014)
MT5: Accessing variables - MQL4 programming forum #3 (2022)
I disagree with making a new bar function, because it can only be called once per tick (second call returns false). A variable can be tested multiple times.
Running EA once at the start of each bar - MQL4 programming forum (2011)