MagicRSI





//+------------------------------------------------------------------+
//| Copyright 2006, Open Source                                      |
//| http://www.finanzaonline.com                                     |
//+------------------------------------------------------------------+
//Modified by KMRunner & Spider4896
//MagicRSI v5

#property copyright "Copyright 2006, Open Source"
#property link      " "
#include <stdlib.mqh>
#define MAGIC 943448
string Name_Expert   = "Magic RSI v5";

extern double Lots          = 1;
extern int    MaxBuyOrders  = 1;  //Leave at 1, no spacing between trades placed
extern int    MaxSellOrders = 1;  //Leave at 1, no spacing between trades placed
extern int    BuyRSI        = 20;
extern int    SellRSI       = 93;
extern double RSITF         = 15;
extern double RSIL          = 7;
extern int    MATF          = 15;
extern double MA1           = 13;
extern double MA2           = 25;
extern double StopLoss     = 34;
extern double TakeProfit    = 999;   //10 is best on EURUSD but if you use Targetlvl please change TP to "2000"
extern double TargetLevel   = 3; //Leave at 9999,This will be updated later (10 works well if wanted to use)     
extern int    Slippage      = 1;
extern bool   LotIncrease   = true;  
extern bool   IsAcctMini    = false;
extern bool   UseSound      = false;


color  clOpenBuy     = Blue;
color  clCloseBuy    = Aqua;
color  clOpenSell    = Red;
color  clCloseSell   = Violet;
color  clModiBuy     = Blue;
color  clModiSell    = Red;

string NameFileSound = "alert.wav";

double StartingBalance = 0;                 
bool   BuyTradeAllowed    = false;              
bool   SellTradeAllowed    = false;             

//+-------------+
//| Custom init |
//|-------------+
int init()
  {
   if(LotIncrease)
     {
      StartingBalance = AccountBalance()/Lots;
     }

  }

//+----------------+
//| Custom DE-init |
//+----------------+

int deinit()
  {
   return(0);
}
//+---------------------------------------------------+
//| Closes all Buys this symbol only                  |
//+---------------------------------------------------+
void CloseAllThisSymbolBuy()
{
 
   for(int i = 0; i < OrdersTotal(); i++)
       {
       OrderSelect(i, SELECT_BY_POS);
       bool result = false;
       if (OrderSymbol()==Symbol() && OrderMagicNumber() == MAGIC)  
         {
           if ( OrderType() == OP_BUY)  result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
         }
       }
     
  return; 
}
   
//+-----------------------------------------------------+
//| Closes all Sells this symbol only                   |
//+-----------------------------------------------------+
void CloseAllThisSymbolSell()
{

   for(int i = 0; i < OrdersTotal(); i++)
      {
      OrderSelect(i, SELECT_BY_POS);
      bool result = false;
      if (OrderSymbol()==Symbol() && OrderMagicNumber() == MAGIC) 
       {
         if ( OrderType() == OP_SELL)  result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
       }
     }
 
  return; 
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start(){
   
   double BuyLots, SellLots, BuyProfit, SellProfit, BuyTarget, SellTarget;
   double OrdersBUY, OrdersSELL;
   int    OrdersPerSymbol;
       
     
   for(int i=0;i<OrdersTotal();i++)
      {
         OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC)
           {
           OrdersPerSymbol++;
           if(OrderType()==OP_BUY)  OrdersBUY++;
           if(OrderType()==OP_SELL) OrdersSELL++;
           if(OrderType()==OP_BUY)  BuyLots += OrderLots();
           if(OrderType()==OP_SELL) SellLots += OrderLots();
           if (OrderType() == OP_BUY)  BuyProfit  +=  OrderProfit() + OrderSwap() + OrderCommission();
           if (OrderType() == OP_SELL) SellProfit +=  OrderProfit() + OrderSwap() + OrderCommission();
           }
      }
      
      BuyTarget  = Lots * TargetLevel;   
      SellTarget = Lots * TargetLevel;
   if(!IsAcctMini)
      {
      BuyTarget = BuyTarget * 10;
      SellTarget = SellTarget * 10;
      }
                      
   if(BuyProfit  > BuyTarget)  CloseAllThisSymbolBuy(); 
   if(SellProfit > SellTarget) CloseAllThisSymbolSell();
    
   if(StopLoss<10){
      Print("StopLoss less than 10");
      return(0);
   }

   if(StopLoss<10){
      Print("StopLoss less than 10");
      return(0);
   }

   double diRSI0=iRSI(NULL,RSITF,RSIL,PRICE_CLOSE,0);
   double diRSI1=iRSI(NULL,RSITF,RSIL,PRICE_CLOSE,0);
   double MA11 = iMA(NULL,MATF,MA1,0,MODE_LWMA,PRICE_CLOSE,0);
   double MA22 = iMA(NULL,MATF,MA2,0,MODE_LWMA,PRICE_CLOSE,0);

   if(AccountFreeMargin()<(1000*Lots)){
      Print("We have no money. Free Margin = ", AccountFreeMargin());
      return(0);
   }
   
    if(OrdersPerSymbol==0) BuyTradeAllowed=true;
    if(OrdersPerSymbol==0) SellTradeAllowed=true;
    if(OrdersBUY>MaxBuyOrders-1) BuyTradeAllowed=false;
    if(OrdersSELL>MaxSellOrders-1) SellTradeAllowed=false;
      
      if ((diRSI0<BuyRSI && MA11<MA22) && BuyTradeAllowed){   
         OpenBuy();
         return(0);
      }

      if ((diRSI1>SellRSI && MA11>MA22) && SellTradeAllowed){  
         OpenSell();
         return(0);
      }
   
   return (0);
}

void OpenBuy() { 
   double ldLot, ldStop, ldTake; 
   string lsComm; 
   ldLot = GetSizeLot(); 
    if(LotIncrease)
     {
      ldLot=NormalizeDouble(AccountBalance()/StartingBalance,2);
     }
   if(ldLot>50) ldLot = 50;  
   ldStop = GetStopLossBuy();
   ldTake = GetTakeProfitBuy(); 
   lsComm = GetCommentForOrder(); 
   OrderSend(Symbol(),OP_BUY,ldLot,Ask,Slippage,ldStop,ldTake,lsComm,MAGIC,0,clOpenBuy); 
   if (UseSound) PlaySound(NameFileSound); 
} 
void OpenSell() { 
   double ldLot, ldStop, ldTake; 
   string lsComm; 

   ldLot = GetSizeLot(); 
    if(LotIncrease)
     {
      ldLot=NormalizeDouble(AccountBalance()/StartingBalance,2);
     }
   if(ldLot>100) ldLot = 100;  
   ldStop = GetStopLossSell();
   ldTake = GetTakeProfitSell(); 
   lsComm = GetCommentForOrder(); 
   OrderSend(Symbol(),OP_SELL,ldLot,Bid,Slippage,ldStop,ldTake,lsComm,MAGIC,0,clOpenSell); 
   if (UseSound) PlaySound(NameFileSound); 
} 
string GetCommentForOrder() { 	return(Name_Expert); } 
double GetSizeLot()         { 	return(Lots); } 
double GetStopLossBuy()     { 	return(Bid-StopLoss*Point);} 
double GetStopLossSell()    { 	return(Ask+StopLoss*Point);}
double GetTakeProfitBuy()   { 	return(Ask+TakeProfit*Point);} 
double GetTakeProfitSell()  { 	return(Bid-TakeProfit*Point);} 





Sample





Analysis



Market Information Used:



Indicator Curves created:


Indicators Used:

Relative strength index
Moving average indicator


Custom Indicators Used:

Order Management characteristics:
Checks for the total of open orders
It Closes Orders by itself
It automatically opens orders when conditions are reached

Other Features:


It plays sound alerts

BackTest : USDJPY on H1

From 2009-11-01 to 2009-11-30 Profit Factor:0.59 Total Net Profit:-152.96

BackTest : EURUSD on H1

From 2009-12-01 to 2010-01-17 Profit Factor:4.78 Total Net Profit:14962.00

BackTest : USDCAD on H1

From 2009-12-01 to 2010-01-01 Profit Factor:0.00 Total Net Profit:0.00

BackTest : EURUSD on H1

From 2009-08-01 to 2009-10-01 Profit Factor:0.00 Total Net Profit:0.00

BackTest : GBPUSD on H1

From 2010-01-01 to 2010-02-27 Profit Factor:1.15 Total Net Profit:1486.10

BackTest : USDCAD on H1

From 2009-01-01 to 2010-01-01 Profit Factor:0.00 Total Net Profit:0.00

BackTest : EURUSD on H1

From 2010-03-01 to 2010-03-27 Profit Factor:2.28 Total Net Profit:5159.00

BackTest : GBPUSD on H1

From 2010-01-01 to 2010-04-16 Profit Factor:0.12 Total Net Profit:-9197.10

BackTest : EURUSD on H1

From 2010-04-01 to 2010-04-30 Profit Factor:2.45 Total Net Profit:4464.00

BackTest : EURUSD on H1

From 2010-05-01 to 2010-05-31 Profit Factor:4.86 Total Net Profit:18295.20

BackTest : EURUSD on H1

From 2010-06-01 to 2010-06-30 Profit Factor:4.88 Total Net Profit:9111.00

Request Backtest for MagicRSI


From : (yyyy/mm/dd) To: (yyyy/mm/dd)

Pair: Period: