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

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 have a great desire to use mql4 to implement such an algorithm:
There are two MT4 terminals from different brokers. In one of them there is an "exclusive" indicator, which cannot be moved to another terminal (like in Market).
So what! Is it possible to take the readings of the "exclusive" indicator buffers and implement them in your own indicator in your own terminal?
Resources do not work somehow.
Option number 1 = open an account with Mikhalych (was it right?)
Option number 2 = write an indicator that will save the indicator data in a file and save it, then read this file with another indicator in another terminal and create lines with it.
Please help - I'm trying to lighten the indicator - converted from RSI, but I can't understand why the indicator values are different?
//| SVA_02.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;
}
Pos=positive;
Neg=negative;
i--;
}
i=Bars-RSIPeriod-1;
if(counted_bars>=RSIPeriod) i=Bars-counted_bars-1;
while(i>=0)
{
x=positive;
y=negative;
if(x>0)sma=Close[i+1]+x;
else sma=Close[i+1]-y;
MABuffer[i]=sma;
i--;
}
//----
return(0);
}
//+------------------------------------------------------------------+
и
//| 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=positive;
y=negative;
Pos=positive;
Neg=negative;
if(x>0)sma=Close[i+1]+x;
else sma=Close[i+1]-y;
MABuffer[i]=sma;
i--;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Please help - I'm trying to lighten the indicator - conversion from RSI, but I can't understand why the indicator values are different?
...
и
...
Please help - I'm trying to lighten the indicator - converted from RSI, but I can't understand why the indicator values are different?
It's just not at all clear what you were trying to do, what you did wrong and what you wanted to get in the end.
Initially I am trying to get rid of unnecessary buffers when calculating the RSI part by removing theoretically unnecessary buffers were:
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--;
}
PosBuffer[i] andNegBuffer[i] are actually pastpositive andnegativevalues, which deeper than one bar are not used, but consume memory, became:
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;
}
Pos=positive;
Neg=negative;
i--;
}
And further, I trim part for my indicator (provided problematic part of code), which in identical loop makes further calculation SVA_02
if(counted_bars>=RSIPeriod) i=Bars-counted_bars-1;
while(i>=0)
{
x=positive;
y=negative;
if(x>0)sma=Close[i+1]+x;
else sma=Close[i+1]-y;
MABuffer[i]=sma;
i--;
}
And then I thought that since the loop is identical, I could just put the calculation into the first loop - I gotSVA_03
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=positive;
y=negative;
Pos=positive;
Neg=negative;
if(x>0)sma=Close[i+1]+x;
else sma=Close[i+1]-y;
MABuffer[i]=sma;
i--;
}
//----
return(0);
}
Here is the last step, it turns out thatMABuffer[i] results aredifferent in SVA_02 and SVA_03 - I can't understand logically what the error is.
In 03 the positive and negative were calculated for the bar and immediately used to calculate the average. In 02 the average calculation is in a separate cycle, in positive and negative what? There is something, but not for the bar being calculated.
Yes, that's true, but what's the actual difference? The cycles are the same - please help me understand what the logical error is.
How can anything be explained to you? It has already been explained here. What's unclear about this explanation? Is it a way of life to be a fool and make a fool of yourself? How can you explain anything after that? With a sledgehammer to the head? Well, take your helmet off.
Yes because the phrase"Something is there, but not for the bar being counted." sounds strange because the cycle has a value from the last cyclepositive andnegative.
From the last cycle for some last bar, something is left in it, and you apply it for each bar. In the correct variant nothing is left in the variables, but is calculated for each bar and immediately used to calculate the average.
I'm trying to make sense of it. So in your opinion the correct option is SVA_03, right?