need help for iRSI indicator

 

Can somebody explain to me how iRSI indicator really work. pls check attached photo & code.

iRSI 

    double sarMA1=iSAR(symb,0,0.02,0.2,1);
    double sarMA2=iSAR(symb,0,0.02,0.2,2);
    double rsiMA=iRSI(symb,0,14,PRICE_MEDIAN,1);
    double marH=60.0;
    double marL=40.0;

    if((rsiMA>=marH)){
      if(sarMA2<=Low[2] && sarMA1>High[1]) {sellsign=true; buysign=false;}}
    if((rsiMA<=marL)){
      if(sarMA2>=High[2] && sarMA1<Low[1]) {sellsign=false; buysign=true;}}

    Comment("buysign: ",buysign,"  sellsign: ",sellsign,"  sarMA1: ",sarMA1,"  sarMA2: ",sarMA2,"  rsiMA: ",rsiMA);

 As you can see on the photo they open "sell order" while as per on my code sell will be open when "rsiMA>=marH", but on the photo value of rsiMA=33.9861.

I am confuse, is there something wrong with my code. 

 
Is sellsign a global variable?
 
ubzen:
Is sellsign a global variable?

no ubzen. should i make it as global variable? but how?
 
05121981: no ubzen. should i make it as global variable? but how? 

https://book.mql4.com/variables/types

int Tick;                              // Global variable
//--------------------------------------------------------------------
int start()                            // Special function start()
Global variables keep their values between start runs. My guess was that it-is a global variable and sellsign stays true.
 
ubzen:

https://book.mql4.com/variables/types

Global variables keep their values between start runs. My guess was that it-is a global variable and sellsign stays true.

 i try like this but still the same result.. also i try all as global variable.. but i still have the same result.. i dont know whats happening here.
 bool buysign=false;
 bool sellsign=false;

 int int()
 int start()
  {
    double sarMA1=iSAR(symb,0,0.02,0.2,1);
    double sarMA2=iSAR(symb,0,0.02,0.2,2);
    double rsiMA=iRSI(symb,0,14,PRICE_MEDIAN,1);
    double marH=60.0;
    double marL=40.0;
    if((rsiMA>=marH)){
      if(sarMA2<=Low[2] && sarMA1>High[1]) {sellsign=true; buysign=false;}}
    if((rsiMA<=marL)){
      if(sarMA2>=High[2] && sarMA1<Low[1]) {sellsign=false; buysign=true;}}

  return();
  }
 bool buysign=false;
 bool sellsign=false;
 double sarMA1;
 double sarMA2;
 double rsiMA;
 double marH;
 double marL;

 int int()
 int start()
  {
    sarMA1=iSAR(symb,0,0.02,0.2,1);
    sarMA2=iSAR(symb,0,0.02,0.2,2);
    rsiMA=iRSI(symb,0,14,PRICE_MEDIAN,1);
    marH=60.0;
    marL=40.0;
    if((rsiMA>=marH)){
      if(sarMA2<=Low[2] && sarMA1>High[1]) {sellsign=true; buysign=false;}}
    if((rsiMA<=marL)){
      if(sarMA2>=High[2] && sarMA1<Low[1]) {sellsign=false; buysign=true;}}

  return();
  }
 

Did you try like this:


 int start()
  {
    bool buysign=false;   //Local Variables
    bool sellsign=false;  //Instead Of Global

    double sarMA1=iSAR(symb,0,0.02,0.2,1);
    double sarMA2=iSAR(symb,0,0.02,0.2,2);
    double rsiMA=iRSI(symb,0,14,PRICE_MEDIAN,1);
    double marH=60.0;
    double marL=40.0;
    if((rsiMA>=marH)){
      if(sarMA2<=Low[2] && sarMA1>High[1]) {sellsign=true; buysign=false;}}
    if((rsiMA<=marL)){
      if(sarMA2>=High[2] && sarMA1<Low[1]) {sellsign=false; buysign=true;}}

  return(0);
  }
 
ubzen:

Did you try like this:

 


 thanks ubzen, i think it is working now.. so i dont need to put it as global variable.
 
05121981: thanks ubzen, i think it is working now.. so i dont need to put it as global variable. 

I cannot tell you how to program your variables. Just remember that global variables are static. Local variables are not. Global variables can be used within other functions. Local variables are limited within the start() or whatever function it's defined. You could use global variables within your codes above if you reset the variables [usually at the beginning of the function]. Example.

bool buysign=false;
bool sellsign=false;

int start(){
    Trade_Logic();
    if( buysign ){ OrderSend(buy); }
    if( sellsign){ OrderSend(sell); }
    return(0);
}

void Trade_Logic(){
    buysign=false;   //Reset To False
    sellsign=false;  //Reset To False

    double sarMA1=iSAR(symb,0,0.02,0.2,1);
    double sarMA2=iSAR(symb,0,0.02,0.2,2);
    double rsiMA=iRSI(symb,0,14,PRICE_MEDIAN,1);
    double marH=60.0;
    double marL=40.0;
    if((rsiMA>=marH)){
      if(sarMA2<=Low[2] && sarMA1>High[1]) {sellsign=true; buysign=false;}}
    if((rsiMA<=marL)){
      if(sarMA2>=High[2] && sarMA1<Low[1]) {sellsign=false; buysign=true;}}
}
 
ubzen:

I cannot tell you how to program your variables. Just remember that global variables are static. Local variables are not. Global variables can be used within other functions. Local variables are limited within the start() or whatever function it's defined. You could use global variables within your codes above if you reset the variables [usually at the beginning of the function]. Example.


 


 thanks ubzen, now i know now what is difference between Local & Global Variable. thanks again. 
Reason: