- MQL5 Wizard: Development of trading robots for MetaTrader 5
- Always ready for a good trade - Web Trading with MetaTrader 5
- When MetaTrader 5 Web Terminal is indispensable
I want my indicator to make calculations every 1-2mins and not on every tick. I tried using OnTimer but couldn't get it to work for the life of me. Is there a way? I'd be happy if the calculation was done on the closing of a candle...
Personally didn't have a need for such stuff, but perhaps you could make some use of this.
Thanks for your help. My problem is this, when I use this indicator, the page loads, but then when I move my screen with my mouse, the cpu goes insane. Does Metrader intall all the data, or just the page that it sees? I've had a lot of problems recently with crazy CPU reactions to my programs. I think that the indicator itself is ok... but perhaps someone can find a problem...
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots 1
//---- plot Label1
#property indicator_label1 "1"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrWhite
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
input int period=360; //Period
//--- indicator buffers
double buffer1[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,buffer1,INDICATOR_DATA);
IndicatorSetInteger(INDICATOR_DIGITS,0);
IndicatorSetString(INDICATOR_SHORTNAME,"calc");
ResetLastError();
//---
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
//--- Copy the values of the indicator Custom Moving Average to our indicator buffer
//--- variables
//--- check for bars count
if(rates_total<1000)
return(0);
for(int i=1000;i<rates_total;i++)
{
buffer1[i]= sum(high,low,close,i,period);
}
return(rates_total);
}
//+------------------------------------------------------------------+
int stoch(const double &high1[],const double &low1[],const double &close1[],int j,int period1)
{
double max = high1[j];
double min = low1[j];
for(int k=0;k<period1;k++)
{
if(high1[j-k]>max){max = high1[j-k];}
if(low1[j-k]<min){min = low1[j-k];}
}
double stoch = (close1[j]-min)/(max-min);
int x = 0;
if(stoch>0.5){ x=1;}
if(stoch<0.5){ x=-1;}
return(x);
}
int sum(const double &high1[],const double &low1[],const double &close1[],int j,int period1)
{
int y=0;
int l=0;
for(int k=0; k<period1/5;k++)
{
l=5*k;
y += stoch(high1,low1,close1,j,period1-l);
}
return(y);
}
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use