Hi, everybody.
Can anybody help me understand how to make things right in my script?
I'm trying to use several indicators at once, and naturally I got the problem of "your indicator is too slow..."
How can I solve this problem?
I NEED TO STUDY 5 PREVIOUS CANDLES. That is why I call [i+n] in each indicator.
The code is as follows:
- Moneymanagement Tool as an indicator. How to get the information about the secondary currency?
- BUG - Notifications: not enough space for notification ...
- ho i can call supertrend indicator?
llaabbss:
Can anybody help me understand how to make things right in my script?
I'm trying to use several indicators at once, and naturally I got the problem of "your indicator is too slow..."
I NEED TO STUDY 5 PREVIOUS CANDLES. That is why I call [i+n] in each indicator.
int OnCalculate(const int rates_total, … const int &spread[]){ int toCount = Bars - IndicatorCounted(); for (int i = toCount - 6; i >= 0 ; i--){
You should stop using the old IndicatorCounted and start using the new Event Handling Functions.
Event Handling Functions - Functions - Language Basics - MQL4 Reference
How to do your lookbacks correctly.- After the first run, toCount will be zero and your loop stops working. Do your lookbacks
correctly.
if (lastTradeBarTime != Time[i]) {
Drop new bar code - That is used in EAs. Indicators should evaluate all bars and reevaluate bar zero each tick. If you don't want to process bar zero, change your loop exit.- llaabbss: I NEED TO STUDY 5 PREVIOUS CANDLES. That is why I call [i+n] in each indicator.
double OPEN_BACK0 = Open[i+1]; ⋮ double OPEN_BACK4 = Open[i+5];
Don't SHOUT at us, that is RUDE. - You are processing candle i. Therefor you should be looking at that (plus the previous four candles.) I.e. [i+0 … i+4] not [i+1 … i+5].
- As for being too slow, if it takes too long to compute, reduce Tools → Options (control-O) → Charts → Max bars in chart to something reasonable (like 1K.) Or, as a last resort, use my attached include.
- It starts the timer, and merges OnTimer and OnCalculate calls to the function OnCalculateSegment(int rates_total, int prev_calculated).
- At the start of each iteration, you check to see if your indicator is taking too long and if so, exit and resume on the next call.
- Reread lookbacks correctly.
- I recommend you test for time out at start of the loop and after each indicator group.
if(gSegmentedCalculation.is_timeout() ) return rates_total-iBar-REDRAW_BAR;
Files:
common_utilities.mqh
12 kb
William Roeder:
-
You should stop using the old IndicatorCounted and start using the new
Event Handling Functions.
Event Handling Functions - Functions - Language Basics - MQL4 Reference
How to do your lookbacks correctly. - After the first run, toCount will be zero and your loop stops working. Do your lookbacks
correctly.
- Drop new bar code - That is used in EAs. Indicators should evaluate all bars and reevaluate bar zero each tick. If you don't want to process bar zero, change your loop exit.
- Don't SHOUT at us, that is RUDE.
- You are processing candle i. Therefor you should be looking at that (plus the previous four candles.) I.e. [i+0 … i+4] not [i+1 … i+5].
- As for being too slow, if it takes too long to compute, reduce Tools → Options (control-O) → Charts → Max bars in chart to something reasonable (like 1K.) Or, as a last resort, use my attached include.
- It starts the timer, and merges OnTimer and OnCalculate calls to the function OnCalculateSegment(int rates_total, int prev_calculated).
- At the start of each iteration, you check to see if your indicator is taking too long and if so, exit and resume on the next call.
- Reread lookbacks correctly.
- I recommend you test for time out at start of the loop and after each indicator group.
Dear William,
Thank you. It helped a lot!
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