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
const int LB_MA = LengthMMA-1;
int iMA = rates_total - 1 - MathMax(LB_MA, prev_calculated);
int iLast = MathMax(LAST, iMA - 2000); // Do in groups
for(; iMA >= iLast; --iMA){
:
} // iMA
//----
#define REDRAW_BAR_ZERO true // Redraw Bar zero.
return rates_total - MathMax(REDRAW_BAR_ZERO, iLast);
extern ENUM_TIMEFRAMES TimeFrame = PERIOD_CURRENT;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit(){
if(TimeFrame == PERIOD_CURRENT) TimeFrame = (ENUM_TIMEFRAMES) _Period;
if(TimeFrame < _Period) return INIT_PARAMETERS_INCORRECT;
int iBar = Rates_total - 1 - MathMax(lookback, prev_calculated);
#define LAST 0
int iLast = MathMax(LAST, iBar - 2000); // Do in groups
for(; iBar >= iLast; --iBar){
int iTF = iBarShift(NULL, TimeFrame, Time[iBar]);
double hiCur = iHigh(NULL, TimeFrame, iTF), //High[iBar],
hiPre = iHigh(NULL, TimeFrame, iTF+1); //High[iBar+1];
:
(See images Multi TimeFrame Moving Average or Moving Average Ex from the codebase)
iLast = iBarShift(NULL, 0, Time[iLast] - Time[iLast] % (TimeFrame * 60));
return rates_total - REDRAW_BAR_ZERO - iLast;
The lookback limit works very well for me in MT5 to limit the number of bars drawn by the custom indicator and save resources. However, when a new chart is downloading new data, I can sometimes witness garbled data appearing past bar 1000, which was never filled in by the custom indicator. I know that the indicator didn't fill in those values, as it never looked past 1000 bars, and it cancels if it cannot access any price data yet (downloading a new chart). Where does the garbled data come from? Of course, I found an easy way to fix this, which was to fill all 50,000 bars on the chart with EMPTY_VALUE. That solves the problem. The fix looks like this:
if (prev_calculated==0) for (j=0; j<rates_total; j++) indicatorBuffer[j]=EMPTY_VALUE;
This works, and is fast because it only has to loop once on the first tick, or only a few times when new data is being downloaded to a new chart. However, it looks a bit messy and has to loop 50,000 bars, or even 500,000 if that many are on the chart. Is there a nicer, cleaner solution for this?
Always set buffer values, do not assume that they are empty values.
The lookback limit works very well for me in MT5 to limit the number of bars drawn by the custom indicator and save resources. However, when a new chart is downloading new data, I can sometimes witness garbled data appearing past bar 1000, which was never filled in by the custom indicator. I know that the indicator didn't fill in those values, as it never looked past 1000 bars, and it cancels if it cannot access any price data yet (downloading a new chart). Where does the garbled data come from? Of course, I found an easy way to fix this, which was to fill all 50,000 bars on the chart with EMPTY_VALUE. That solves the problem. The fix looks like this:
if (prev_calculated==0) for (j=0; j<rates_total; j++) indicatorBuffer[j]=EMPTY_VALUE;
This works, and is fast because it only has to loop once on the first tick, or only a few times when new data is being downloaded to a new chart. However, it looks a bit messy and has to loop 50,000 bars, or even 500,000 if that many are on the chart. Is there a nicer, cleaner solution for this?
Is there a nicer, cleaner solution for this?
Yes, there is a cleaner (and extremely faster) solution to do that, and without using a loop:
Goodmo
To get the values of HA you have to immitate the MT way
If you use Array Notsetasserie, your last bar is not 0 zéro bar, but rates_totalnow you have your values for HA and if you want to do further caculation you have to use this loop:
for(i=prev_calculated-1; i<rates_total; i++)
i am not sure that ArrayMaximum will work in this case
#14 can be simplified
Regular indicator:
MTF indicator:
// buffer[i+2] has look back of 2 (as TimeSeries)
// buffer[i-2] has look back of 2 (not TimeSeries)
// use maximum of all.
Returning rates_total-1 makes prev_calculated the same as IndicatorCounted().
Alternatively if you return rates_total then must decrement prev_calculated if non-zero at the beginning of On_Calculate to recalculate the current bar.
Always count down so you're not using future values.
Hi william. Hope you are doing good.
can you please provide any code example like any demo indicator file from start.
Because I'm having the same issue, that my indicator is working perfectly good in live chart, while in tester it only plots on the history data, not on the new data.
I was using ArraySetAsSeries() as true, as soon as after reading this post i commented out the ArraySetAsSeries() portion, now my indicator buffers are not even showing values nor plotting on chart. Please help me with this. I'll really be grateful. Thanks.