sosinsky: difftime1 = TimeSeconds(Time[i+j])-TimeSeconds(Time[i+j+1]);
Play videoPlease edit your post.
For large amounts of code, attach it.- All bars start at zero seconds. The difference between 11:53:00 and 9:54:00 is 7260.
- You are calculating the difference between HH:MM:00 and hh:mm:00 which is ALWAYS zero.
- If you used TimeMinutes() instead you would be calculating the difference between HH:53:00 and hh:54:00 which is minus one.
- If you used TimeHours() instead you would be calculating the difference between 11:MM:00 and 9:MM:00 which is two.
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
Hi, I have a problem with a divide. I hope someone could help me.
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 Yellow
#property indicator_color2 Crimson
#property indicator_color3 OliveDrab
#property indicator_color4 Aqua
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 1
#property indicator_width4 1
extern int media1 = 10;
extern int sommaforze1=10;
extern int media2 = 10;
extern int sommaforze2=20;
extern int media3 = 0;
extern int sommaforze3=0;
extern int media4 = 0;
extern int sommaforze4=0;
//---- indicator buffers
double ind_buffer1[];
double ind_buffer2[];
double ind_buffer3[];
double ind_buffer4[];
double suma1=0;
double suma2=0;
double suma3=0;
double suma4=0;
double sumb1=0;
double vela1=0;
double acc1=0;
double forza1=0;
double forza2=0;
double forza3=0;
double forza4=0;
double average1=0;
double average2=0;
double veloci=0;
int difftime1=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- drawing settings
IndicatorBuffers(4);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+7);
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID);
SetIndexBuffer(0,ind_buffer1);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID);
SetIndexBuffer(1,ind_buffer2);
SetIndexStyle(2,DRAW_LINE,STYLE_SOLID);
SetIndexBuffer(2,ind_buffer3);
SetIndexStyle(3,DRAW_LINE,STYLE_SOLID);
SetIndexBuffer(3,ind_buffer4);
IndicatorShortName("Quotes Average");
SetIndexLabel(0,"Average "+media1);
SetIndexLabel(1,"Average "+media2);
SetIndexLabel(2,"Average "+media3);
SetIndexLabel(3,"Average "+media4);
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence |
//+------------------------------------------------------------------+
int start()
{
int limit,i,j,k;
int counted_bars=IndicatorCounted();
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- macd counted in the 1-st buffer
for(i=0; i<limit; i++)
{
forza1=0;
forza2=0;
forza3=0;
forza4=0;
suma1=0;
sumb1=0;
for(j=0;j<sommaforze1;j++){
suma1=0;
sumb1=0;
for(k=0;k<media1;k++)
{
suma1 += Close[i+j+k];
sumb1 += Close[i+j+k+1];
}
average1 = suma1/media1;
average2 = sumb1/media1;
difftime1 = TimeSeconds(Time[i+j])-TimeSeconds(Time[i+j+1]);
vela1 = (average1-average2)/difftime1;
/*
acc1 = vel1/(Time[i+j]-Time[i+j+1]);
forza1+= acc1 * average1;
*/
}
//Comment(suma1 + " " + sumb1 + " " + average1 + " " + average2 + " " + vela1 + " " + velb1);
Comment(average1 +" " +average2 + " " + DoubleToStr(vela1,8)+ " " + vela1 + " " + difftime1 + " " + veloci);
if(media1>0) ind_buffer1[i] = forza1; else ind_buffer1[i]=EMPTY_VALUE;
if(media2>0) ind_buffer2[i] = forza2; else ind_buffer2[i]=EMPTY_VALUE;
if(media3>0) ind_buffer3[i] = forza3; else ind_buffer3[i]=EMPTY_VALUE;
if(media4>0) ind_buffer4[i] = forza4; else ind_buffer4[i]=EMPTY_VALUE;
}
//---- done
return(0);
}
The problem is here
vela1 = (average1-average2)/difftime1;
with this the indi stop to work.