Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 9
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
I'm trying to make sense of it. So in your opinion the correct option is SVA_03, right?
Yeah, I guess so. But _02 is definitely wrong.
Hmmm... found one mistake in myself, now there is almost no discrepancy, here is the original
//| SVA_04.mq4 |
//| Copyright © 2006, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
#property strict
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Yellow
//---- input parameters
extern int RSIPeriod=14;
extern int Levl=50;
extern int TF=0;
//---- buffers
double MABuffer[];
double PosBuffer[];
double NegBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
IndicatorBuffers(1);
SetIndexBuffer(0,MABuffer);
SetIndexBuffer(1,PosBuffer);
SetIndexBuffer(2,NegBuffer);
//---- indicator line
SetIndexStyle(0,DRAW_LINE);
//----
//---- name for DataWindow and indicator subwindow label
// short_name="RSI("+IntegerToString(RSIPeriod)+")";
short_name="RSI("+RSIPeriod+")";
IndicatorShortName(short_name);
SetIndexLabel(0,short_name);
SetIndexLabel(1,"U");
SetIndexLabel(2,"D");
return(0);
}
//+------------------------------------------------------------------+
//| Relative Strength Index |
//+------------------------------------------------------------------+
int start()
{
int i,counted_bars=IndicatorCounted();
double rel,negative,positive,sma,x,y,Pos,Neg;
//----
if(Bars<=RSIPeriod) return(0);
if(TF!=0)
{
string name=WindowExpertName();
for(i=0; i<Bars-counted_bars+1; i++)
{
int barIndex=iBarShift(NULL,TF,Time[i],false);
MABuffer[i]=iCustom(Symbol(),TF,name,RSIPeriod,Levl,0,0,barIndex);
}
return(0);
}
i=Bars-RSIPeriod-1;
if(counted_bars>=RSIPeriod) i=Bars-counted_bars-1;
while(i>=0)
{
double sumn=0.0,sump=0.0;
if(i==Bars-RSIPeriod-1)
{
int k=Bars-2;
//---- initial accumulation
while(k>=i)
{
rel=Close[k]-Close[k+1];
if(rel>0) sump+=rel;
else sumn-=rel;
k--;
}
positive=sump/RSIPeriod;
negative=sumn/RSIPeriod;
}
else
{
//---- smoothed moving average
rel=Close[i]-Close[i+1];
if(rel>0) sump=rel;
else sumn=-rel;
positive=(PosBuffer[i+1]*(RSIPeriod-1)+sump)/RSIPeriod;
negative=(NegBuffer[i+1]*(RSIPeriod-1)+sumn)/RSIPeriod;
}
PosBuffer[i]=positive;
NegBuffer[i]=negative;
i--;
}
i=Bars-RSIPeriod-1;
if(counted_bars>=RSIPeriod) i=Bars-counted_bars-1;
while(i>=0)
{
x=PosBuffer[i+1];
y=NegBuffer[i+1];
if(x>0)sma=Close[i+1]+x;
else sma=Close[i+1]-y;
MABuffer[i]=sma;
i--;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Here's SVA_03's version with the correction
//| SVA_03.mq4 |
//| Copyright © 2006, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
#property strict
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Yellow
//---- input parameters
extern int RSIPeriod=14;
extern int Levl=50;
extern int TF=0;
//---- buffers
double MABuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
IndicatorBuffers(1);
SetIndexBuffer(0,MABuffer);
//---- indicator line
SetIndexStyle(0,DRAW_LINE);
//----
//---- name for DataWindow and indicator subwindow label
// short_name="RSI("+IntegerToString(RSIPeriod)+")";
short_name="RSI("+RSIPeriod+")";
IndicatorShortName(short_name);
SetIndexLabel(0,short_name);
return(0);
}
//+------------------------------------------------------------------+
//| Relative Strength Index |
//+------------------------------------------------------------------+
int start()
{
int i,counted_bars=IndicatorCounted();
double rel,negative,positive,sma,x,y,Pos,Neg;
//----
if(Bars<=RSIPeriod) return(0);
if(TF!=0)
{
string name=WindowExpertName();
for(i=0; i<Bars-counted_bars+1; i++)
{
int barIndex=iBarShift(NULL,TF,Time[i],false);
MABuffer[i]=iCustom(Symbol(),TF,name,RSIPeriod,Levl,0,0,barIndex);
}
return(0);
}
i=Bars-RSIPeriod-1;
if(counted_bars>=RSIPeriod) i=Bars-counted_bars-1;
while(i>=0)
{
double sumn=0.0,sump=0.0;
if(i==Bars-RSIPeriod-1)
{
int k=Bars-2;
//---- initial accumulation
while(k>=i)
{
rel=Close[k]-Close[k+1];
if(rel>0) sump+=rel;
else sumn-=rel;
k--;
}
positive=sump/RSIPeriod;
negative=sumn/RSIPeriod;
}
else
{
//---- smoothed moving average
rel=Close[i]-Close[i+1];
if(rel>0) sump=rel;
else sumn=-rel;
positive=(Pos*(RSIPeriod-1)+sump)/RSIPeriod;
negative=(Neg*(RSIPeriod-1)+sumn)/RSIPeriod;
}
x=Pos;
y=Neg;
Pos=positive;
Neg=negative;
if(x>0)sma=Close[i+1]+x;
else sma=Close[i+1]-y;
MABuffer[i]=sma;
i--;
}
//----
return(0);
}
//+------------------------------------------------------------------+
there replaced
y=negative;
to .
y=Neg;
Good afternoon!
Help! I need code to open a pending order. And in 20 min after the order is opened, if it is not closed, it will change the SL to 50 pips. Thank you!
Good afternoon
Please help with a very simple (probably) question. There is a standard function:
What does "const void &" mean and how to use it? ? Even a simple attempt to write a similar function leads to a compilation error:
return ArraySize(array);
}
Compilation error: 'const' - illegal use of 'void' type
How can I use "const void &"correctly when writing my own code? Can it be done at all ?
Good afternoon
Please help with a very simple (probably) question. There is a standard function:
What does "const void &" mean and how to use it? ? Even a simple attempt to write a similar function leads to a compilation error:
return ArraySize(array);
}
Compilation error: 'const' - illegal use of 'void' type
How can I use "const void &"correctly when writing my own code? Or can it be used at all?
Replace void with the data type that should store the array. The standard function is designed as a template.
In fact, this system function is an overloaded function, and the whole implementation of such an overloading is hidden from the MQL4 developer:
intArraySize(
void&array[]// array to be checked
);
The MQL4 compiler actually substitutes a needed implementation for each call of this function, for example, for arrays of integer type like this
intArraySize(
int&array[]// array with elements of int type
);
And for an array of MqlRates type for working with quotes in history data format, the ArraySize() function can be represented as follows
intArraySize(
MqlRates&array[]// array filled with values of MqlRates type
);
Good afternoon!
Help! I need code to open a pending order. And in 20 min after the order is opened, if it is not closed, it will change the SL to 50 pips. Thank you!
Replace void with the data type that should store the array. The standard function is designed as a template.
In fact, this system function is an overloaded function, and the entire implementation of such an overload is hidden from the developer of programs in MQL4.
Did I understand correctly that in MQL4/MQL5 the "const void &" construct - is in fact a symbolic notation for the reference and in practice it can't be written in your own functions?
Thanks in advance
Did I understand correctly that in MQL4/MQL5 the "const void &" structure - is in fact a symbolic notation for the reference book and in practice it cannot be used in your own functions?
Thank you in advance