Features of the mql5 language, subtleties and tricks - page 32
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 check if the indicator is ready (at the beginning ofOnCalculate)
You can also add a Period check
1. Just a clarification. Now it is clear that we are talking about the same thing.
2) I understand that, but I do not agree that it is necessary to flip arrays. Is it necessary to have one indicator for two terminals? It's almost like making a 2in1 scythe and an axe.
3. as I understand Buffer[] is used by the receiver in the CopyBuffer() function to get only 1 indicator value.
4. You have not paid attention to the main thing. The start of copying of the indicator values should not be determined by the bar index, but by the time of the i-th bar.
Okay.
2. I reversed the array because I rewrote the indicator from the 4 because everything is working properly in it and all data is correct. It's all about getting data in the exact sequence in which they are read in the loop. If you don't flip the buffer, you have to write the indicator from scratch - what for? It's quite complicated. This indicator was given only as an example of how erroneous is the reception of data from a non-native cf.
No. You write data into Buffer[] in the loop one by one - at each iteration of the loop you write one value taken from AO().
4. What do you mean by "start of copying"?
1. okay.
2. I'm flipping the array because I'm rewriting the indicator from the four - everything works properly in it and all the data are correct. It's all about getting data in the exact sequence in which they are read in the loop. If you don't flip the buffer, you have to write the indicator from scratch - what for? It's quite complicated. This indicator was given only as an example of how erroneous is the reception of data from a non-native cf.
No. In Buffer[] data is inserted into the loop one by one - at each iteration of the loop one value taken from AO() is inserted
4. What do you mean by "start of copying"?
2. Nothing prevents you from building a loop from 0 to rates_total-1
3. Yes, I messed something up somewhere.
4.In your code
should be changed to
"Where do we start from" or "from what date" this is the start of copying the indicator values into the receiver array.
3. Yes, I messed something up somewhere.
4.In your code.
should be changed to
"Where do we start from" or "from what date" this is the start of copying the indicator values into the receiver array.
Why pass the date, if I read the value by the loop index? Did you run this test indicator? It always draws AO only from one - the specified timeframe in the settings. No matter how you switch the current timeframe, the AO chart always corresponds to the one specified in the settings.
In my indicator, which I am modifying, the data doesn't come back from the non-native current price, despite the fact that it's coming back.
This test indicator is not needed anymore - data from nonnative cf is already returned. But data in mine are not, but I get them the same way.
Why pass the date if I'm reading the value from the loop index? Did you run this test indicator? It always plots AO only from one - the specifiedfactor in the settings. No matter how you switch the current timeframe, the AO chart always corresponds to the one specified in the settings.
In my indicator, which I am modifying, the data doesn't come back from the non-native current price, despite the fact that it's coming back.
This test indicator is not needed anymore - data from nonnative cf is already returned. But data in mine is not, but I get it the same way.
Because the zero bar H4 contains FOUR H1 bars. And if you request index 2 of period H1 to get the indicator value at period H4, then you will get the indicator value at bar 2 at period H4.
I hardly understand what I was able to write...
At the moment it is 13:35. Opening time of the current bar H1 = 13:00. You try to copy the indicator values of the bar index = 1, i.e. the bar 12:00 of the current H1 period. But instead of the 12:00 of the H4 period you get the 8:00
For H1 the first bar is 12:00
For H4 the first bar is 8:00
Both of them have the first bar index...
Forum on trading, automated trading systems and trading strategies testing
Bugs, bugs, questions
fxsaber, 2017.04.12 08:38
A little tip of the hat. Bypassing the assignment operatorForum on trading, automated trading systems and trading strategies testing
I can't get indicator data from older timeframe
Artyom Trishkin, 2017.04.14 01:23
For the fourth day in the indicator I'm trying to get the data of the standard AO indicator from the senior timeframe, and still nothing...
I read AO data in the loop, but exactly in the loop there is no historical data. There is data on the current bar. What is the problem? What am I doing wrong?
Forum on trading, automated trading systems and trading strategies testing
Peculiarities of mql5 language, tips and tricks
fxsaber, 2017.02.27 18:40
Thanks for the tip! In the wilderness it is SymbolInfoMarginRate. So now it's like thisdouble GetMarginRequired( const string Symb )
{
MqlTick Tick;
double MarginInit, MarginMain;
return((SymbolInfoTick(Symb, Tick) && SymbolInfoMarginRate(Symb, ORDER_TYPE_BUY, MarginInit, MarginMain)) ? MarginInit * Tick.ask *
SymbolInfoDouble(Symb, SYMBOL_TRADE_TICK_VALUE) / (SymbolInfoDouble(Symb, SYMBOL_TRADE_TICK_SIZE) * AccountInfoInteger(ACCOUNT_LEVERAGE)) : 0);
}
You have to clearly understand that in MT5 there may be completely different margin requirements in different directions. That is, a single MT4 variant may not work. On Forex, of course, this will not be the case. But you have to remember. Therefore, in the general case it should be written like this
bool MyOrderCalcMargin( const ENUM_ORDER_TYPE action, const string symbol, const double volume, const double price, double &margin )
{
double MarginInit, MarginMain;
const bool Res = SymbolInfoMarginRate(symbol, action, MarginInit, MarginMain);
margin = Res ? MarginInit * price * volume * SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_VALUE) /
(SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_SIZE) * AccountInfoInteger(ACCOUNT_LEVERAGE)) : 0;
return(Res);
}
Highlighted can return 0. In BCS encountered.
Made it like this:
I think you are doing a lot of things "wrong". Please describe what you need to do: step by step, point by point.
What exactly is wrong? That was the question - what am I doing wrong to get indicator data from a non-native timeframe?
Example: The indicator is running on М1, while the data from AO should be obtained from М5. So - while we have limit>1 (history needs to be recalculated), then АО from M5 returns zeros with error of no data. As soon as all the history is calculated (limit==0), the data from AO from M5 starts to arrive.