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
ilunga:
P.S. Am I correct in assuming that in my (and your) code bar_info[1] is the maximum of the current bar?
Nobody said anything about current bar. :)
I just re-did your example. If you want exactly current bar, you have to:
1. define direction of series of array (0 bar - current or highest).
If, as in our case, the array is moved out, you can do it once in the initialization block. If we hide the array in a function, we define it in place.
2. If the array is declared as a series, the current bar will be zero, and the one closed before it will be 1.
At least as I remember.
I may have missed something, but in order to open on the current bar (taking into account all additions) it should be like this.
Move the array to the function!
And no one said anything about the current one. :)
I just reworked your example. If you need current one, you have to:
1. Define direction of array series (0 bar - current or the latest).
If, as in our case, the array is moved out, you can do it once in the initialization block. If we hide the array in a function, we define it in place.
2. If the array is declared as a series, the current bar will be zero, and the bar closed before that will be 1.
At least as I remember it.
I expanded the array to 3 elements. I got a mismatch between the current price and what's in it. This is most likely the reason.
Results (testing was done on GBPUSD):
We get that both Ask and Bid are greater than the maximum of zero and greater than the maximum of the second bar
If we run the test on EURUSD, everything is OK:
I have a feeling that when testing "not my" pair the situation "information on bars has been updated, but the tick is absent yet".
I have expanded the array to 3 elements. I get inconsistency between the current price and the array contents. That's most likely the reason.
Results:
We obtain that Ask and Bid are both greater than the zero bar maximum and greater than the second bar maximum
You don't consider the seriality of the arrays, in your code. No one can guarantee that with this outcome 0 bar will not be in say the year 2000.
I gave the code above it is suitable for all TFs in the array variant.
This code is there for a reason.
If you need only a daily timeframe (D1) to identify the bar maximum you don't need to deal with the array at all, just change the first part of the function to this one
You don't consider the seriality of arrays in your code. No one can guarantee that at this outcome 0 bar will not be in say 2000.
I gave the code above it is suitable for all TFs in the array variant.
This code is there for a reason
You don't consider the seriality of arrays in your code. No one can guarantee that at this outcome 0 bar will not be in say the year 2000.
I gave the code above it is suitable for all TFs in the array variant.
This code is there for a reason.
Ok, make the array dynamic.
Instead of xxx we put true and false.
The results:
и
The order in the array is changed, the result is not. Bid is greater than the maximum [0]-th bar of the array
ArraySetAsSeries only for dynamic arrays?
I don't remember to be honest. But the result of the code I cited above coincides with the one we get (for EUR the open price is 1.24516 for GBP 1.56721)
Although yes, it works fine without ArraySetAsSeries at this point
PS
That is, if you want to get the current bar, you needlessly copy three bars into the array on this line.
PS
I.e. if you need to get the current bar you absolutely in vain copy three bars in this line to the array
Thank you! This option works without errors and is fully sufficient in this case.
However, the question left hanging just above is how the Bid can be greater than the maximum =(
ilunga:
However, the question left hanging above is how the Bid can be greater than the maximum =(
First of all, we need to determine for which period this maximum is taken.
If the array is declared as double bar_info[n] then the current bar in it will be the largest index.
if n = 2 this code will work with yesterday's daily bar
and this one with the current bar
I.e., if you copy several bars, you should arrange something like this to get the current bar (though you may need additional checks of how many bars have been copied into the array)
The first thing to do is to define the period over which this maximum is taken.
If the array is declared as double bar_info[n] then the current bar in it will be the largest index.