Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1730

 
anrei2002 #:

The irrelevant arrows disappeared immediately!!!

I don't expect you to understand, I had a customer with a similar problem, I couldn't explain it to him for a year, there was a different indicator, but also with a peek. He seems to be a smart guy, but apparently his thirst for profit really turned off his logic and thinking... He eventually realised everything when he emptied a lot of money. I don't know what to do... If you reset it, the indicator will stop working. If you reset it, only the right arrows remain, but in history... I've seen a lot of these indicators

 
MakarFX #:
Show what you've already done.
#property description "Stochastic Oscillator"
#property strict

#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_buffers 2
#property indicator_color1 LightSeaGreen
#property indicator_color2 Red
#property indicator_level1 20.0
#property indicator_level2 80.0
#property indicator_levelcolor clrSilver
#property indicator_levelstyle STYLE_DOT
//--- input parameters
input int InpKPeriod=5; // input K Period
input int InpDPeriod=3; // input D Period
input int InpSlowing=3; // Slowing

input string PARA_Ref = "$USDX";
//input string PARA_Ref = "ETHUSD";


//--- buffers
double ExtMainBuffer[];
double ExtSignalBuffer[];
double ExtHighesBuffer[];
double ExtLowesBuffer[];

double cl[];
double hi[];
double lo[];



//---
int draw_begin1=0;
int draw_begin2=0;
//+------------------------------------------------------------------+
//| Custom indicator initialisation function |
//+------------------------------------------------------------------+
int OnInit(void)
{
string short_name;
//--- 2 additional buffers are used for counting.
IndicatorBuffers(4);
SetIndexBuffer(2, ExtHighesBuffer);
SetIndexBuffer(3, ExtLowesBuffer);
//--- indicator lines
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ExtMainBuffer);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,ExtSignalBuffer);
//--- name for DataWindow and indicator subwindow label
short_name="Stochastic_Mult_1("+IntegerToString(InpKPeriod)+", "+IntegerToString(InpDPeriod)+", "+IntegerToString(InpSlowing)+")";
IndicatorShortName(short_name);
SetIndexLabel(0,short_name);
SetIndexLabel(1, "Signal");
//---
draw_begin1=InpKPeriod+InpSlowing;
draw_begin2=draw_begin1+InpDPeriod;
SetIndexDrawBegin(0,draw_begin1);
SetIndexDrawBegin(1,draw_begin2);
//--- initialization done
return(INIT_SUCCEED);
}
//+------------------------------------------------------------------+
//| Stochastic oscillator |
//+------------------------------------------------------------------+
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[])
{
int i,k,pos,n;

//--- check for bars count
if(rates_total<=InpKPeriod+InpDPeriod+InpSlowing)
return(0);
//--- counting from 0 to rates_total
ArraySetAsSeries(ExtMainBuffer,false);
ArraySetAsSeries(ExtSignalBuffer,false);
ArraySetAsSeries(ExtHighesBuffer,false);
ArraySetAsSeries(ExtLowesBuffer,false);
ArraySetAsSeries(low,false);
ArraySetAsSeries(high,false);
ArraySetAsSeries(close,false);

//---
pos=InpKPeriod-1;
if(pos+1<prev_calculated)
pos=prev_calculated-2;
else
{
for(i=0; i<pos; i++)
{
ExtLowesBuffer[i]=0.0;
ExtHighesBuffer[i]=0.0;
}
}
//--- calculate HighesBuffer[] and ExtHighesBuffer[]
for(i=pos; i<rates_total && !IsStopped(); i++)
{
double dmin=1000000.0;
double dmax=1000000.0;
for(k=i-InpKPeriod+1; k<=i; k++)
{
n = i-k;
if(dmin>iLow(PARA,0,n)* iLow(PARA_Ref,0,n)) // original: if(dmin>low[k])
dmin=iLow(PARA,0,n)* iLow(PARA_Ref,0,n); // original: dmin=low[k];
if(dmax<iHigh(PARA,0,n)* iHigh(PARA_Ref,0,n)) // original: if(dmax<high[k])
dmax=iHigh(PARA,0,n)* iHigh(PARA_Ref,0,n); // original: dmax=high[k];

}
ExtLowesBuffer[i]=dmin;
ExtHighesBuffer[i]=dmax;
}
//--- %K line
pos=InpKPeriod-1+InpSlowing-1;
if(pos+1<prev_calculated)
pos=prev_calculated-2;
else
{
for(i=0; i<pos; i++)
ExtMainBuffer[i]=0.0;
}
//--- main cycle
for(i=pos; i<rates_total && !IsStopped(); i++)
{
double sumlow=0.0;
double sumhigh=0.0;
for(k=(i-InpSlowing+1); k<=i; k++)
{
n = i-k;
sumlow +=((iClose(PARA,0,n) * iClose(PARA_Ref,0,n))-ExtLowesBuffer[k]); // original: sumlow +=(close[k]-ExtLowesBuffer[k]);
sumhigh+=(ExtHighesBuffer[k]-ExtLowesBuffer[k]);
}
if(sumhigh==0.0)
ExtMainBuffer[i]=100.0;
else
ExtMainBuffer[i]=sumlow/sumhigh*100.0;
}
//--- signal
pos=InpDPeriod-1;
if(pos+1<prev_calculated)
pos=prev_calculated-2;
else
{
for(i=0; i<pos; i++)
ExtSignalBuffer[i]=0.0;
}
for(i=pos; i<rates_total && !IsStopped(); i++)
{
double sum=0.0;
for(k=0; k<InpDPeriod; k++)
sum+=ExtMainBuffer[i-k];
ExtSignalBuffer[i]=sum/InpDPeriod;
}
//--- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+
 
It can be fixed without losing logic, but it will draw the arrow on the 8th bar, or even on the 9th bar (but without re-drawing and without left signals). You will need it like this, i.e. the new and freshest arrow will be on the 9th bar. And the delay of opening will also be 9 bars.
 
Nikolay Ivanov #:

I don't expect you to understand, I had a customer with a similar problem, I couldn't explain it to him for a year, there was a different indicator, but also with a peeping device. He seems to be a smart guy, but apparently his thirst for profit really turned off his logic and thinking... He eventually realised everything when he emptied a lot of money. I don't know what to do... If you reset it, the indicator will stop working. If you reset it, only the right arrows remain, but in history... I've seen a lot of these indicators.

I'm not a programmer, but I still don't understand why the arrow cannot be corrected with the appearance of a new candle.

The world is full of indicators with re-crossing and it works fine for all of them! The arrow moves along with the set crossover and there is no oscillation.

They all have the same code...

Files:
02.png  15 kb
 
asdkika1 #:

Better write down what you want to do...point by point

 
anrei2002 #:

I am not a programmer, but I still don't understand why the arrow cannot be corrected with the appearance of a new candle?

The world is full of indicators with re-crossing and it works fine for all of them! The arrow moves along with the set crossover and there is no oscillation.

They all have the same code.

Normal rerolling is when the signal bar (where the arrow is) is involved in the calculation of the signal and may have the index 0... That is, the current bar... It is re-drawn every tick and, respectively, the signal may also be re-drawn...

But in addition to the 0th bar, you use -1 -2 -3 -4 -5 -6 -7... Where will the minus 8th bar come from? It's bad form to use even 0th bar... and bars with minus indices is simply unacceptable...

I wrote above how to fix it... It will work right if you wait for the signal to the right of 8 bars, then it will be ok, does not think that the arrow will always be 9 bars late, do you want that?

 
MakarFX #:

Better write down what you want to do...point by point

Calculating Stochastic from the multiplication of two pairs.
Just took the standard Stochastic indicator and changed
input data (lines marked).
I never used OnCalculate - apparently this is where the dog is buried.
Doesn't work - can't figure out why.
I hoped that I wouldn't have to
I hope I won't have to redesign it myself.
 
Nikolay Ivanov #:

Normal overshooting is when the signal bar itself (where the arrow is) is involved in the calculation for the signal to appear and can have an index of 0... That is the current bar... It is re-drawn every tick and, consequently, the signal may also be re-drawn...

But in addition to the 0th bar, you use -1 -2 -3 -4 -5 -6 -7... Where will the minus 8th bar come from? It's bad form to use even 0th bar... and bars with minus indices is simply unacceptable...

I wrote above how to fix it... It will work correctly if you wait for the signal to the right of 8 bars, then everything will be fine, does not think that the arrow will always be 9 bars late, do you need it?

Here is an example of another such indicator!

He has in addition to the arrows on the chart, there are circles at the intersection of lines in the basement.

And the circles, in contrast to the arrows are strictly behind the intersection of lines! There are no extra circles.

Why are there no arrows?

Files:
03.png  98 kb
EATA__Alert.mq4  20 kb
 
anrei2002 #:

Here's an example of another one of these indicators!

In addition to the arrows on the chart, it has circles at the intersection of the lines in the basement.

And the circles, unlike the arrows are strictly behind the intersection of the lines! There are no extra circles.

Why is there something wrong with the arrows?

run this indicator in the tester and observe the lines and the circles in the visualisation at accelerated speed... If it doesn't make sense even after that, I don't know how else to explain it simply...

 
asdkika1 #:
Stochastic calculation from the multiplication of two pairs.
Just took the standard Stochastic indicator and changed
input data (lines marked).
I never used OnCalculate - I guess this is where the problem lies.
Doesn't work - can't figure out why.
I hoped that I wouldn't have to
I was hoping I wouldn't have to redo it myself. It should be very simple.

Multiply what? Open? Close? Stoch?