Coding multiple strategy according to RSI level

Back to topics list To post a new topic, please log in or register
avatar
5
pipokito 2016.07.20 10:21
 

Dear all,

I'm building a multiple strategy based on the RSI  levels:

Between 30 and 70 use a certain strategy: Strategy N°0

Between 70 and 85 or 30 and 15 I use strategy N°1

And between 0 and 15 or 85 and 100 I use strategy N°2 (Although in order to move back to another strategy from srategy N°2 the RSI level has to reach the opposite RSI limit)

 I have tried to code this with the following MQL4 code but it didn't work. The value of X was stuck to 1 or 2 or -2 and 1 depending on the order of my instructions.

The idea was then to say if X = ... then use strategy N°... 

Can someone enlight me or advise me on a simpler way to translate these instructions in MQL4

 

Thanks!

Andrea 

 

int X=0;
extern int RSIU1=70;
extern int RSIU2=85;
extern int RSID1=30;
extern int RSID2=15;

double RSIX=iRSI(Symbol(),0,RSIXPeriod,0,0);

if ((X=1)&&((RSIX<RSIU1)&&(RSIX>RSID1))) X=0;
if ((X=0)&&(((RSIX>RSIU1)&&(RSIX<RSIU2))||((RSIX<RSID1)&&(RSIX>RSID2)))) X=1;
if ((X=1)&&(RSIX>RSIU2)) X=2;
if ((X=1)&&(RSIX<RSID2)) X=-2;
if ((X=-2)&&(RSIX>RSIU1)) X=1;
if ((X=2)&&(RSIX<RSID1)) X=1
avatar
26
ceaser234 2016.07.20 12:30 #
 

Why are you declaring x to numbers inside the if else conditions.

if ((X=1)&&((RSIX<RSIU1)&&(RSIX>RSID1))) X=0;
if ((X=0)&&(((RSIX>RSIU1)&&(RSIX<RSIU2))||((RSIX<RSID1)&&(RSIX>RSID2)))) X=1;
if ((X=1)&&(RSIX>RSIU2)) X=2;
if ((X=1)&&(RSIX<RSID2)) X=-2;
if ((X=-2)&&(RSIX>RSIU1)) X=1;
if ((X=2)&&(RSIX<RSID1)) X=1


Shouldn't they be like this

if ((X==1)  && ((RSIX<RSIU1)&&(RSIX>RSID1))) X=0;
if ((X==0)  && (((RSIX>RSIU1)&&(RSIX<RSIU2))||((RSIX<RSID1)&&(RSIX>RSID2)))) X=1;
if ((X==1)  && (RSIX>RSIU2)) X=2;
if ((X==1)  && (RSIX<RSID2)) X=-2;
if ((X==-2) && (RSIX>RSIU1)) X=1;
if ((X==2)  && (RSIX<RSID1)) X=1
avatar
5
pipokito 2016.07.20 13:07 #
 
ceaser234:

Why are you declaring x to numbers inside the if else conditions.


Shouldn't they be like this

Thanks, it looks so obvious I couldn't see it by myself.

 I'm sure it will work fine now, I will implement the changes.

 Bests,

Andrea 

avatar
26
ceaser234 2016.07.20 13:56 #
 
pipokito:

Thanks, it looks so obvious I couldn't see it by myself.

 I'm sure it will work fine now, I will implement the changes.

 Bests,

Andrea 

Wishes you Best :D
Back to topics list  

To add comments, please log in or register