EA7-XRSI47_MT4

extern double Lots=0.1;
extern int Slippage=2;
int init()
{
Print("Init happened");
}
int deinit()
{
Print("DE-Init happened");
Comment(" ");
}
int start()
{
double p=Point();
int cnt=0;
int OrdersPerSymbol=0;
double pRSI4=0, RSI4=0;
double pRSI7=0, RSI7=0;
bool Rising=false, Falling=false;
string TradeComment = "XRSI47";
if(AccountFreeMargin()<(1000*Lots)) {Print("-----NO MONEY"); return(0);}
if(Bars<100) {Print("-----NO BARS "); return(0);}
RSI4=iRSI(Symbol(),0,4,PRICE_CLOSE,1);
pRSI4=iRSI(Symbol(),0,4,PRICE_CLOSE,2);
RSI7=iRSI(Symbol(),0,7,PRICE_CLOSE,1);
pRSI7=iRSI(Symbol(),0,7,PRICE_CLOSE,2);
if(pRSI4RSI7) {Rising=true; Falling=false;}
if(pRSI4>pRSI7 && RSI4<RSI7) {Rising=false; Falling=true;}
OrdersPerSymbol=0;
for(cnt=OrdersTotal();cnt>=0;cnt--)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if ( OrderSymbol() == Symbol())
{
OrdersPerSymbol++;
}
}
if(OrdersPerSymbol==0)
{
if(Rising) { OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,Ask-(50*p),Ask+(50*p),TradeComment,10101,White); Print("Initial BUY"); } if(Falling) { OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,Bid+(50*p),Bid-(50*p),TradeComment,10101,Red); Print("Initial SELL"); } }
for(cnt=OrdersTotal();cnt>=0;cnt--)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if ( OrderSymbol()==Symbol())
{
if (OrderType() == OP_BUY && Falling) { OrderClose(OrderTicket(),Lots,Bid,Slippage,White); OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,Bid+(50*p),Bid-(50*p),TradeComment,10101,Red); } if (OrderType() == OP_SELL && Rising) { OrderClose(OrderTicket(),Lots,Ask,Slippage,Red); OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,Ask-(50*p),Ask+(50*p),TradeComment,10101,White); } } }
return(0);
}