Implementing a simple RSI strategy test - first program

 

I am attempting to creating a simple EA in MQL4 that sells a pair when the RSI rises above 75 and sells when it falls below 60, while only being in one trade at a time. For some reason, it will only continuously selling without ever closing a position on the strategy tester. Any ideas?

 

Here is the code:

 

#property version   "1.00"

#property strict

//-------------------------------------------------+


int ticket;

int x = 0; // variable created earlier with no current use.

/*

double RSI = iRSI(_Symbol, 0, 3, PRICE_OPEN, 1); 


void init()

   {

      double RSI = iRSI(_Symbol, 0, 3, PRICE_OPEN, 1);    

   }

*/

void OnTick()

   {

//---


   double RSI = iRSI(_Symbol, 0, 3, PRICE_OPEN, 1); 


   

   if( RSI>75 & ticket==NULL) {

      int ticket = OrderSend(_Symbol,OP_SELL,0.01, Bid,300,NULL,NULL,"My order",16384,0,clrGreen);

      x = 1;

      }

 

if (RSI<60 & ticket!=NULL)

      {

       OrderClose(ticket, 0.01, Ask, 300, clrGreen);

       x=0;

      }      

 

   }


       

 

your ticket does not != differ from NULL once you ticket=OrderSend(..

so the OrderClose(... will never be executed.

if (RSI<60 & ticket!=NULL)
 

I've tried to switch out ticket for just changing x between 0 and 1 depending on if I have a position open but there are still no trades being closed. Any ideas?

 


#property version   "1.00"

#property strict

//-------------------------------------------------+


int ticket;

int x;

/*

double RSI = iRSI(_Symbol, 0, 3, PRICE_OPEN, 1); 


void init()

   {

      double RSI = iRSI(_Symbol, 0, 3, PRICE_OPEN, 1);    

   }

*/

void start()

   {

//---


   double RSI = iRSI(_Symbol, 0, 3, PRICE_OPEN, 1); 

   

   if( RSI>75.0 & x==1) {

      int ticket = OrderSend(_Symbol,OP_SELL,0.01, Bid,300,NULL,NULL,"My order",16384,0,clrGreen);

      x = 0;

      } 

   

   if (RSI<60.0 & x==0)

      {

      OrderClose(ticket, 0.01, Ask, 300, clrGreen);

      ticket = 0;

      x=1;

      }

   


      

   }


      

   

 
#property version   "1.00"

#property strict

//-------------------------------------------------+



int ticket;

int x;

void init()

   {
    
      x=1;

   }

void start()

   {

//---



   double RSI = iRSI(_Symbol, 0, 3, PRICE_OPEN, 1); 

   

   if( RSI>75.0 & x==1) {

      int ticket = OrderSend(_Symbol,OP_SELL,0.01, Bid,300,NULL,NULL,"My order",16384,0,clrGreen);

      x = 0;

      } 

   

   if (RSI<60.0 & x==0)

      {

      OrderClose(ticket, 0.01, Ask, 300, clrGreen);

      ticket = 0;

      x=1;

      }

   



      

   }
Reason: