RSI_lvl_close

Author: Copyright 2014, Igor Vedeneev
Profit factor:
0.00
9 Views
0 Downloads
0 Favorites
RSI_lvl_close
//+------------------------------------------------------------------+
//|                                                RSI_lvl_close.mq4 |
//|                                    Copyright 2014, Igor Vedeneev |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, Igor Vedeneev"
#property link      ""
#property version   "1.00"
//+------------------------------------------------------------------+
extern double lot          = 1;
extern double moneyclose   = 0;
extern int    period_RSI   = 14;
extern int    RSIup        = 65;
extern int    RSIdown      = 35;
extern int    sellclose    = 65;
extern int    buyclose     = 35;
extern double TP           = 1000;
extern double koof         = 1.7;
extern int    magic        = 7557;

extern string bez_ub = "Áåçóáûòîê";
extern bool   use_bezubitok = false;
extern int    Bez_Ub_Level = 500;
extern int    Bez_Ub_Size = 400;

//+------------------------------------------------------------------+
double pause_if_busy = 0.7; 
int    slippage = 2; //ïðîñêàëüçûâàíèå
extern int    MaxAttempts = 4; //ìàêñ êîëè÷åñòâî ïîïûòîê îòêðûòü èëè çàêðûòü îðäåð

double Balans, Sredstva ;
string    txt,txt1;
string    txt2="";
string    txt3="";
string    txt4="";
color col = ForestGreen;
//----
//+------------------------------------------------------------------+
int      NObay;
int      NOsell;
double   RSI;

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



//+------------------------------------------------------------------+
int deinit()
{
//----
  ObjectDelete("Lable");
  ObjectDelete("Lable1");
  ObjectDelete("Lable2");
  ObjectDelete("Lable3");
  ObjectDelete("Lable4");   
//----
  ObjectDelete("profit1");
  ObjectDelete("profit2");
  ObjectDelete("profit3");
  ObjectDelete("profit4");
  ObjectDelete("profit5");
  ObjectDelete("profit6");
  ObjectDelete("profit7");
   return(0);
}
//+------------------------------------------------------------------+
int start()
{
   int    counted_bars=IndicatorCounted();

//----
   Balans = NormalizeDouble( AccountBalance(),2);
  Sredstva = NormalizeDouble(AccountEquity(),2);  
 //-------------
    if (Sredstva >= Balans/6*5) col = DodgerBlue; 
    if (Sredstva >= Balans/6*4 && Sredstva < Balans/6*5)col = DeepSkyBlue;
    if (Sredstva >= Balans/6*3 && Sredstva < Balans/6*4)col = Gold;
    if (Sredstva >= Balans/6*2 && Sredstva < Balans/6*3)col = OrangeRed;
    if (Sredstva >= Balans/6   && Sredstva < Balans/6*2)col = Crimson;
    if (Sredstva <  Balans/5                           )col = Red;
 //-------------
ObjectDelete("Lable2");
ObjectCreate("Lable2",OBJ_LABEL,0,0,1.0);
   ObjectSet("Lable2", OBJPROP_CORNER, 3);
   ObjectSet("Lable2", OBJPROP_XDISTANCE, 20);
   ObjectSet("Lable2", OBJPROP_YDISTANCE, 51);
   txt2=(DoubleToStr(AccountBalance()/100, 2));
   ObjectSetText("Lable2","ÁÀËÀÍÑ     "+txt2+"$",18,"Times New Roman",DodgerBlue);
   //-------------------------   
ObjectDelete("Lable3");
ObjectCreate("Lable3",OBJ_LABEL,0,0,1.0);
   ObjectSet("Lable3", OBJPROP_CORNER, 3);
   ObjectSet("Lable3", OBJPROP_XDISTANCE, 20);
   ObjectSet("Lable3", OBJPROP_YDISTANCE, 31);
   txt3=(DoubleToStr(AccountEquity()/100, 2));
   ObjectSetText("Lable3","ÑÐÅÄÑÒÂÀ     "+txt3+"$",18,"Times New Roman",col);
//-------------------------
ObjectDelete("Lable4");
ObjectCreate("Lable4",OBJ_LABEL,0,0,1.0);
   ObjectSet("Lable4", OBJPROP_CORNER, 3);
   ObjectSet("Lable4", OBJPROP_XDISTANCE, 20);
   ObjectSet("Lable4", OBJPROP_YDISTANCE, 11);
   txt4=(DoubleToStr(AccountProfit()/100, 2));
   ObjectSetText("Lable4","ÏÐÎÑÀÄÊÀ      "+txt4+"$",18,"Times New Roman",col);
 //-------------

   double RSI = iRSI(Symbol(), 0, period_RSI, PRICE_CLOSE, 1);


   double lots;
   int tik=ticket_ord(lots);
   //......................................
   
   int step, step1, step2, step3, step4, step5, step6, step7, step8, step9, step10, step11, step12, step13, step14, step15;
   
   step  = 50;
   step1 = 150;
   step2 = 300;
   step3 = 500;
   step4 = 750;
   step5 = 1050;
   step6 = 1400;
   step7 = 1800;
   step8 = 2250;
   step9 = 2750; 
   step10= 3300;
   step11= 3900;
   step12= 4550;
   step13= 5250;
   step14= 6000;
   step15= 6800;
   
   double lot1, lot2, lot3, lot4, lot5, lot6, lot7, lot8, lot9, lot10, lot11, lot12, lot13, lot14, lot15, lot16;

   lot1  = lot   * koof;
   lot2  = lot1  * koof;
   lot3  = lot2  * koof;
   lot4  = lot3  * koof;
   lot5  = lot4  * koof;
   lot6  = lot5  * koof;
   lot7  = lot6  * koof;   
   lot8  = lot7  * koof;
   lot9  = lot8  * koof;
   lot10 = lot9  * koof;
   lot11 = lot10 * koof;
   lot12 = lot11 * koof;
   lot13 = lot12 * koof;
   lot14 = lot13 * koof;
   lot15 = lot14 * koof;   
   lot16 = lot15 * koof;
        
   if (tik == 0)  // îòêðûòü îðäåð
   {
      if (RSI < RSIdown)// âàðèàíò 1
      {
            NObay=OrderSend(Symbol(),OP_BUY,       lot,  Ask,              20, 0, NormalizeDouble(Bid+TP*Point,Digits), NULL, magic, 0, Red);
            NObay=OrderSend(Symbol(),OP_BUYLIMIT,  lot1, Bid-step  *Point, 20, 0, NormalizeDouble(Bid+TP*Point,Digits), NULL, magic, 0, Red);            
            NObay=OrderSend(Symbol(),OP_BUYLIMIT,  lot2, Bid-step1 *Point, 20, 0, NormalizeDouble(Bid+TP*Point,Digits), NULL, magic, 0, Red);            
            NObay=OrderSend(Symbol(),OP_BUYLIMIT,  lot3, Bid-step2 *Point, 20, 0, NormalizeDouble(Bid+TP*Point,Digits), NULL, magic, 0, Red);            
            NObay=OrderSend(Symbol(),OP_BUYLIMIT,  lot4, Bid-step3 *Point, 20, 0, NormalizeDouble(Bid+TP*Point,Digits), NULL, magic, 0, Red);            
            NObay=OrderSend(Symbol(),OP_BUYLIMIT,  lot5, Bid-step4 *Point, 20, 0, NormalizeDouble(Bid+TP*Point,Digits), NULL, magic, 0, Red);  
            NObay=OrderSend(Symbol(),OP_BUYLIMIT,  lot6, Bid-step5 *Point, 20, 0, NormalizeDouble(Bid+TP*Point,Digits), NULL, magic, 0, Red);  
            NObay=OrderSend(Symbol(),OP_BUYLIMIT,  lot7, Bid-step6 *Point, 20, 0, NormalizeDouble(Bid+TP*Point,Digits), NULL, magic, 0, Red);            
            NObay=OrderSend(Symbol(),OP_BUYLIMIT,  lot8, Bid-step7 *Point, 20, 0, NormalizeDouble(Bid+TP*Point,Digits), NULL, magic, 0, Red);            
            NObay=OrderSend(Symbol(),OP_BUYLIMIT,  lot9, Bid-step8 *Point, 20, 0, NormalizeDouble(Bid+TP*Point,Digits), NULL, magic, 0, Red);            
            NObay=OrderSend(Symbol(),OP_BUYLIMIT,  lot10,Bid-step9 *Point, 20, 0, NormalizeDouble(Bid+TP*Point,Digits), NULL, magic, 0, Red);            
            NObay=OrderSend(Symbol(),OP_BUYLIMIT,  lot11,Bid-step10*Point, 20, 0, NormalizeDouble(Bid+TP*Point,Digits), NULL, magic, 0, Red);  
         tik=ticket_ord(lots);
      }
      if (RSI > RSIup)//âàðèàíò 1
      {
            NOsell=OrderSend(Symbol(),OP_SELL,     lot,  Bid,              20, 0, NormalizeDouble(Ask-TP*Point,Digits), NULL, magic, 0, Red);
            NOsell=OrderSend(Symbol(),OP_SELLLIMIT,lot1, Ask+step  *Point, 20, 0, NormalizeDouble(Ask-TP*Point,Digits), NULL, magic, 0, Red);            
            NOsell=OrderSend(Symbol(),OP_SELLLIMIT,lot2, Ask+step1 *Point, 20, 0, NormalizeDouble(Ask-TP*Point,Digits), NULL, magic, 0, Red);            
            NOsell=OrderSend(Symbol(),OP_SELLLIMIT,lot3, Ask+step2 *Point, 20, 0, NormalizeDouble(Ask-TP*Point,Digits), NULL, magic, 0, Red);            
            NOsell=OrderSend(Symbol(),OP_SELLLIMIT,lot4, Ask+step3 *Point, 20, 0, NormalizeDouble(Ask-TP*Point,Digits), NULL, magic, 0, Red);            
            NOsell=OrderSend(Symbol(),OP_SELLLIMIT,lot5, Ask+step4 *Point, 20, 0, NormalizeDouble(Ask-TP*Point,Digits), NULL, magic, 0, Red);  
            NOsell=OrderSend(Symbol(),OP_SELLLIMIT,lot6, Ask+step5 *Point, 20, 0, NormalizeDouble(Ask-TP*Point,Digits), NULL, magic, 0, Red);  
            NOsell=OrderSend(Symbol(),OP_SELLLIMIT,lot7, Ask+step6 *Point, 20, 0, NormalizeDouble(Ask-TP*Point,Digits), NULL, magic, 0, Red);            
            NOsell=OrderSend(Symbol(),OP_SELLLIMIT,lot8, Ask+step7 *Point, 20, 0, NormalizeDouble(Ask-TP*Point,Digits), NULL, magic, 0, Red);            
            NOsell=OrderSend(Symbol(),OP_SELLLIMIT,lot9, Ask+step8 *Point, 20, 0, NormalizeDouble(Ask-TP*Point,Digits), NULL, magic, 0, Red);            
            NOsell=OrderSend(Symbol(),OP_SELLLIMIT,lot10,Ask+step9 *Point, 20, 0, NormalizeDouble(Ask-TP*Point,Digits), NULL, magic, 0, Red);            
            NOsell=OrderSend(Symbol(),OP_SELLLIMIT,lot11,Ask+step10*Point, 20, 0, NormalizeDouble(Ask-TP*Point,Digits), NULL, magic, 0, Red);  
         
         tik=ticket_ord(lots);
      }
      }
   //áåçóáûòîê
   if(use_bezubitok) BezUb();

   // çàêðûòü îðäåð
   if (AccountProfit()+OrderSwap()+OrderCommission() > moneyclose)
{
   if ((tik > 0 && RSI >= sellclose) || OrdersTotal() <= 11) Close_all(); 
   if ((tik < 0 && RSI <= buyclose)  || OrdersTotal() <= 11) Close_all();    
}
   //......................................
   return(0);
}
//+------------------------------------------------------------------+
int ticket_ord(double& lot)
{     // âîçâðàùàåò òèêåò Buy > 0 è Sell < 0 è 0, åñëè íåò îðäåðîâ
   int ticket = 0;
   lot=0;
   for (int trade = OrdersTotal() -1; trade >=0; trade --)
      if (OrderSelect (trade, SELECT_BY_POS, MODE_TRADES))
         if (OrderSymbol()==Symbol() && OrderMagicNumber()== magic)
         {  
            if (OrderType() ==  OP_BUY)
            {
               ticket=OrderTicket();
               lot=OrderLots();
               break;
            }
            if (OrderType() ==  OP_SELL)
            {
               ticket=-OrderTicket();
               lot=OrderLots();
               break;
            }
         }
      
   return(ticket);
}  


////////////////////////////////////////////////////////////////////////////////
void Close_all()
{
for(int i=OrdersTotal()-1; i>=0; i--)
 {
 if(OrderSelect(i, SELECT_BY_POS))
 {
 if(OrderMagicNumber()==magic)
 {
 if(OrderSymbol()==Symbol())
 {
 bool ticket_ex=false;
 for (int j_ex = 0;j_ex < MaxAttempts; j_ex++)
 {
 while(IsTradeContextBusy()) Sleep(pause_if_busy*1000);
 RefreshRates();
 
 if(OrderType()==OP_BUY ) ticket_ex=OrderClose(OrderTicket(),OrderLots(),Bid,slippage,Yellow); 
 if(OrderType()==OP_SELL) ticket_ex=OrderClose(OrderTicket(),OrderLots(),Ask,slippage,Yellow);
 if(OrderType()==OP_SELLSTOP || OrderType()==OP_BUYSTOP || OrderType()==OP_SELLLIMIT || OrderType()==OP_BUYLIMIT) ticket_ex=OrderDelete(OrderTicket(),CLR_NONE);
 if(ticket_ex==true)break;
 }
 }
 }
 }
 }
 
}

void BezUb()
{
  for (int i=OrdersTotal()-1; i>=0; i--) 
  {
  if(OrderSelect(i, SELECT_BY_POS)) 
  {
  if (OrderMagicNumber()==magic)
  {
  while(IsTradeContextBusy()) Sleep(pause_if_busy*1000);
  RefreshRates();
  
      if (OrderType()==OP_BUY) 
      {
      if(OrderStopLoss()!=OrderOpenPrice()+NormalizeDouble(Bez_Ub_Size*Point,Digits))
      {
      if (Bid>OrderOpenPrice()+Bez_Ub_Level*Point && (OrderStopLoss()<OrderOpenPrice() || OrderStopLoss()==0)) 
      {
      OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+NormalizeDouble(Bez_Ub_Size*Point,Digits),OrderTakeProfit(),0,Blue);       
      }
      }
      }
      

      if (OrderType()==OP_SELL) 
      {
      if(OrderStopLoss()!=OrderOpenPrice()-NormalizeDouble(Bez_Ub_Size*Point,Digits))
      {
      if (Ask<OrderOpenPrice()-Bez_Ub_Level*Point && (OrderStopLoss()>OrderOpenPrice() || OrderStopLoss()==0)) 
      {
      OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-NormalizeDouble(Bez_Ub_Size*Point,Digits),OrderTakeProfit(),0,Blue);
      }
      }  
      }   
  }
  }
  }
}

Comments