[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 11
![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 tried to open orders on a new bar there using the NewBar() function. If it is used for this purpose?
For example if (NewBar())i++; Something like this.
I didn't notice NewBar, sorry.
Then change the following: You don't need to calculate the whole indicator every tick, if you only open trades on a new bar.
So, move the entire indicator calculation before checking conditions for opening a deal and do not count as many bars as you need (20 if I am not mistaken)
So the strategy is as follows:
1) new bar? no - walk
2) yes - calculate everything we need (MA, indicator, everything else for the conditions)
3) Check the conditions - no - walk
4) Yes - open at the current price (Ask or Bid, respectively)
NewBar didn't notice, I apologise.
Then change the following: You don't need to count the whole indicator every tick if you only open trades on a new bar.
So, move the whole indicator calculation before checking conditions of trade opening and count not as many bars, but as many as you need (20 if I am not mistaken).
That's right 20. I understand roughly how to do it. Please explain me the difference between my calculation and the calculation of 20 bars for Expert Advisors.
I just want to understand the essence of the error.
I do not know how to use it.
Z.U. I am sure there are many silly mistakes, please shoot blanks.
It's easier to rewrite the code as you see it than to sort out "what are you dancing around" here, for example:
I haven't encountered how the function used in the indicators in the EA will work out:
But, if "whatever", the loop you organise:
Where limit = Bars - counted_bars, on the 2nd tick will take a value equal to 0, then by code it will be assigned a value... OPA - and this is a NEW WORLD in programming:
...try writing this condition like this, if it doesn't break the whole strategy:
I.e. use this condition for recalculation of bars?
But in my indicator, at every tick the arrays TP_UP and TP_DN are calculated.Therefore, they must be calculated first.
Again, the opening price of OP_BUY==Ask, OP_SELL==Bid.
And you have Close[i].
That's right 20. I understand roughly how to do this. Please explain the difference between my calculation and the calculation of 20 bars for Expert Advisor ONLY.
I just want to understand the essence of the error.
There is no error as such in calculation of the entire indicator. Just think what is faster:
1) to count Bars (approximately 10000) bars every tick
2) to count 20 bars 1 time per minute (or even more)
I do not know how to use it.
Z.I. I'm sure there are a lot of mistakes and stupid, please shoot blanks.
NOT PRINCIPAL, but to simplify the code, this construct:
should have been replaced with a simple array declaration with dimensionality:
double delta,price,old_price,col_bar,sum_tick,sum_pip,TP_UP[20],TP_DN[20],TP_UPMin[20],TP_DNPl[20];
That's right 20. I understand roughly how to do this. Please explain the difference between my calculation and the calculation of 20 bars for Expert Advisor ONLY.
I just want to understand the essence of the error.
indicator code, everything works. Here is the library code.
This is a call in the indicator code:
Vadim, you put such a small (&) that you can't see it straight away!..! :)))
I wonder how the author (in the author's version) this function was performed in one place and not in another! ;)
That's right 20. I understand roughly how to do this. Please explain the difference between my calculation and the calculation of 20 bars for Expert Advisor ONLY.
I just want to understand the essence of the error.
By the way, I noticed that you declare working arrays of size 20:
And your library calculates 21 elements:
I can assume that the loop should start from 1: