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.
//Preparation of arrayArraySetAsSeries(bar_info,true);
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
//Function BUY_pendingbool BUY_pending(string symbol,double volume,ulong magic = 0)
{
//----------------------------------------------------------------------------////Work variablesdouble price = 0, sl = 0, tp = 0; //Prices: Open, Sell stop, Take profitdouble High = 0; //The maximum value of bid for the current dayint Dig = 0; //Digitsbool Result = true; //Returned importance//----------------------------------------------------------------------------//ResetLastError();
//Checking the signal to stopping the trading systemif(IsStopped()) return(false);
//Preparation of structuresZeroMemory(TradeRequest);
ZeroMemory(TradeResult);
ZeroMemory(CheckResult);
//Calculations
High = SymbolInfoDouble(symbol,SYMBOL_BIDHIGH);
Dig = (int)SymbolInfoInteger(symbol,SYMBOL_DIGITS);
price = NormalizeDouble(High + 500*_Point,Dig);
sl = NormalizeDouble(price - 200*_Point,Dig);
tp = NormalizeDouble(price + 1000*_Point,Dig);
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)
High = SymbolInfoDouble(symbol,SYMBOL_BIDHIGH);
Although yes, it works fine without ArraySetAsSeries at this point
//+------------------------------------------------------------------+//Function BUY_pendingbool BUY_pending(string symbol,ENUM_TIMEFRAMES period,double volume,ulong magic = 0)
{
//----------------------------------------------------------------------------////Work variablesdouble price = 0, sl = 0, tp = 0; //Prices: Open, Sell stop, Take profitint ResCopy = -1; //Result of copying the data into an arrayint Dig = 0; //Digitsdouble bar_info[1];
bool Result = true; //Returned importance//----------------------------------------------------------------------------//ResetLastError();
//Checking the signal to stopping the trading systemif(IsStopped()) return(false);
//Preparation of structuresZeroMemory(TradeRequest);
ZeroMemory(TradeResult);
ZeroMemory(CheckResult);
//Copying the data into an array
ResCopy = CopyHigh(symbol,period,0,1,bar_info);
if(ResCopy==-1)return(false);
//Calculations
Dig = (int)SymbolInfoInteger(symbol,SYMBOL_DIGITS);
price = NormalizeDouble(bar_info[0] + 500*_Point,Dig);
PS
That is, if you want to get the current bar, you needlessly copy three bars into the array on this line.
//Это не правильноint ResCopy = CopyHigh("EURUSD",PERIOD_D1,0,3,bar_info);
//так правильноint ResCopy = CopyHigh("EURUSD",PERIOD_D1,0,1,bar_info);
//если PERIOD_D1 не меняется вот идеальный вариант
High = SymbolInfoDouble(symbol,SYMBOL_BIDHIGH);
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
int ResCopy = CopyHigh("EURUSD",PERIOD_D1,0,2,bar_info);
price = NormalizeDouble(bar_info[0] + 500*_Point,Dig);
and this one with the current bar
int ResCopy = CopyHigh("EURUSD",PERIOD_D1,0,2,bar_info);
price = NormalizeDouble(bar_info[1] + 500*_Point,Dig);
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.
Thus, there is a code on the previous page where there is an array of 3 elements. When outputting it with Prints, we get that Bid = 1.29709, while bar_info[n-1] stores 1.29220
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
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.