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

 
Andrei Gerasimenko:

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);
  }
//+------------------------------------------------------------------+
Files:
SVA_02.mq4  4 kb
SVA_03.mq4  4 kb
 
-Aleks-:

Please help - I'm trying to lighten the indicator - conversion 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.
 
-Aleks-:

Please help - I'm trying to lighten the indicator - converted from RSI, but I can't understand why the indicator values are different?

In 03 positive and negative calculated for bar and immediately used them to calculate average. In 02 calculation of average in a separate cycle, in positive and negative what? Something is there, but not for the bar being calculated.
 
Artyom Trishkin:
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:

   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--;
     }

PosBuffer[i] andNegBuffer[i] are actually pastpositive andnegativevalues, which deeper than one bar are not used, but consume memory, became:

   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--;
     }

And further, I trim part for my indicator (provided problematic part of code), which in identical loop makes further calculation SVA_02

   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--;
     }

And then I thought that since the loop is identical, I could just put the calculation into the first loop - I gotSVA_03

   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);
  }

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.

 
Dmitry Fedoseev:
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 it is, but in fact what is the difference? The cycles are the same - please help me understand what the logical error is.
 
-Aleks-:
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? Already explained here. What is unclear in this explanation? Is it a way of life - to be a fool and play dumb? How is it possible to explain something after that? With a sledgehammer to the head? Well, take your helmet off.
 
Dmitry Fedoseev:
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.
Because the phrase, "There's something, but it's not for the bar being counted. " sounds strange, because the loop has a value from the last looppositive andnegative.
 
-Aleks-:
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 there, but you apply it for every bar. In the correct variant, nothing is left in the variables, but it is calculated for each bar and immediately used to calculate the average.
 
Dmitry Fedoseev:
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?

Reason: