Is sellsign a global variable?
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.
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); }
Did you try like this:
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;}} }
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.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Can somebody explain to me how iRSI indicator really work. pls check attached photo & code.
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.