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

 
Yes, of course. First: 0, last: OrdersTotal()-1
 
Aleksei Stepanenko #:
Yes, of course. First: 0, last: OrdersTotal()-1

Ah, there's an array, really from scratch...

 
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
                                                              
extern int RSIPERIOD=3;
extern double KOEFF1=2.5;
extern double KOEFF2=1.86; 
                                                                                                                                                                  
double mass0[],Buf1[],Buf2[];
double D10,D11,D12;
                                                                                                                                                                                                                                                                                                                                             
int init()
  {
   IndicatorDigits(0);
   string short_name="RSITEST";           
   IndicatorShortName("RSITEST");
   
   D10=RSIPERIOD;D11=D10*KOEFF1;D12=D11*KOEFF2;;
 
   SetIndexBuffer(0,mass0);
   SetIndexLabel (0,"Stoch "+Ds_0(D10)+")\n");
   SetIndexBuffer(1,Buf1);
   SetIndexLabel (1,"Stoch ("+Ds_0(D11)+")\n");
   SetIndexBuffer(2,Buf2);
   SetIndexLabel (2,"Stoch ("+Ds_0(D12)+")\n");
   return(0);
  }
                                                                                                               
int start()
  {
   if(Bars<=RSIPERIOD) return(0);
   int ExtCountedBars=IndicatorCounted();
   if (ExtCountedBars<0) return(-1);
   if (ExtCountedBars>0) ExtCountedBars--;
   for(int i=0;i<Bars-RSIPERIOD;i++)
      {
       mass0[i] = iRSI(NULL,0,D10,0,i);
       if(iRSI(NULL,0,D11,0,i)>iRSI(NULL,0,D12,0,i))
       Buf1[i] = Buf2[i];
       Buf1[i] = DRAW_LINE;
       Buf2[i] = EMPTY_VALUE;
      }
   return(0);
  }

string Ds_0(double DOUBLE) {return(DoubleToStr(DOUBLE,0));}
MakarFX #:
in your case it worked out only 2 of 3 lines, I adapted it to the task at hand and it turns out that the first line stay (as it should) and the level of the other two (red and blue) with the given conditions ( instead of red and blue line was a single line - and it was red ifRSI2>RSI3 and blue ifRSI2<RSI3) become straight and only red like it doesn't know it is RSI
I attach a screenshot.
Files:
 
Andrey Kipyatkov #:
in your case, it turns out that only 2 of the 3 lines, I adapted it to the problem, and it turns out that the first line stay (as it should) and the level of the other two (red and blue) with given conditions ( instead of a red and blue line was a single line - and it was red ifRSI2>RSI3 and blue ifRSI2<RSI3) become straight and only red like it doesn't know it is RSI
I attach a screenshot.

How do you equalise Buf1 and Buf2?

In your condition they are 0!

 
Andrey Kipyatkov #:
in your case it worked out only 2 of 3 lines, I adapted it to the task at hand and it turns out that the first line stay (as it should) and the level of the other two (red and blue) with the given conditions ( instead of red and blue line was a single line - and it was red ifRSI2>RSI3 and blue ifRSI2<RSI3) become straight and only red like it doesn't know it is RSI
I attach a screenshot.


Files:
RSITEST-1.mq4  4 kb
 
Hi all, can you tell me please what is the difference between a trading robot and an Expert Advisor?
 
Daniil Osipov #:
Hi all, can you please tell me the difference between a trading robot and a trading advisor?
It's the same thing... a play on words
 
MakarFX #:

Thanks for helping with the code but if it's not difficult I'd like to understand the point. When you write everything in one line you:
Buf0[i] = iRSI(NULL,0,D10,0,i); - you specify in this string that zero array is a rsy line with the parameter given above
if(iRSI(NULL,0,D11,0,i)>iRSI(NULL,0,D12,0,i)) then you are saying that Rsai with parameter D11 >D12
Buf1[i] = Buf0[i]; and then you match (superimpose one line over the other) psi with parameter D11 and D10
else
Buf1[i] = EMPTY_VALUE; and you tell it not to render xy with parameter D11.
but when you work with 3 lines
Buf0[i] = iRSI(NULL,0,D10,0,i); you say how to draw 1
line Buf1[i] = (iRSI(NULL,0,D11,0,i)+iRSI(NULL,0,D12,0,i))/2; next you add and divide by 2 2 and 3 - This action is not very clear to me because before you were equating arrays and superimposing one line over the other why this syntax.
if(iRSI(NULL,0,D11,0,i)>iRSI(NULL,0,D12,0,i)) then you repeat the example you say that Rsai with parameterD11>D12
Buf2[i] = Buf1[i]; and you equate
the
3rd and 2nd
lines
else
Buf2[i] = EMPTY_VALUE; and say not to draw the second line

I see correctly how you give the language "parameters" and why in the second case you added arrays and divided by 2

 
MakarFX #:
It's the same thing... play on words
Vitaly Muzichenko #:

A play on words.

From the next branch. Without colluding...

 
Andrey Kipyatkov #:
I thank you for your help with the code, but if it's not too much trouble, I'd like to understand the gist of it. When you write everything in one line you:

Andrew, let's first define your condition from the first post

I wanted to clarify whether there is a way to prescribe in the code instead of a red and blue line (RSI2 and RSI3 in the picture (attached as well), respectively) was one line - and it was red if RSI2>RSI3 and blue if RSI2 < RSI3

so, instead of red and blue one - we get the average of these lines, i.e.

Buf1[i] = (iRSI(NULL,0,D11,0,i)+iRSI(NULL,0,D12,0,i))/2;

and this line, by default, has red colour.

Further, when the condition is met

if(iRSI(NULL,0,D11,0,i)>iRSI(NULL,0,D12,0,i))

we do not change the line colour as it cannot be done in MT4,

we take and overlay another line with another colour

Buf2[i] = Buf1[i];
Reason: