Navigation:Home > Content >

VR---STEALS-2.mq4

Time: 2010-06-16 | Download file:VR---STEALS-2.mq4

//========================================================================================================================//
//|                                                VR---STEALS-2.mq4 |
//|                                                      Voldemar227 |
//|                                         http://www.trading-go.ru |
//========================================================================================================================//
#property copyright "Voldemar227"
#property link      "http://www.trading-go.ru"
extern double TakeProfit = 0   ;// Если 0 то не используется
extern double StopLoss   = 0   ;// Если 0 то не используется
extern double Bezubitok  = 300 ;// Если 0 то не используется
extern double BezMinDis  = 50  ;// Минимальная фиксация прибыли при переводе в безубыток
extern double Magic      = -1  ;// Если -1 то по всем меджикам 
extern double Slip       = 20  ;// Проскальзывания
extern double coment     = 2   ;// Количество строк сообщений если 0 сообщения не выводятся
int i;
//========================================================================================================================//
int init ()
{
// Выведем при старте на экран наши установленные параметры
pr(StringConcatenate("TakeProfit = ",TakeProfit));
pr(StringConcatenate("StopLoss   = ",StopLoss));
pr(StringConcatenate("Bezubitok  = ",Bezubitok));
if (Magic==-1)
pr(StringConcatenate("По всем меджик номерам  = ",Magic));
else 
pr(StringConcatenate("Меджик номер  = ",Magic));
}
//========================================================================================================================//
int start()
  {
// Перебираем ордера и работаем с ними
for (int i=0; iNormalizeDouble(OrderOpenPrice()+Bezubitok*Point,Digits)&&OrderStopLoss()==0)
       // Если цена больше заданного значения , выставим безубыток с небольшой фиксацией прибыли
       if (OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()+BezMinDis*Point,Digits),OrderTakeProfit(),0,Green)==true)
       // Раскоментируем происходящее
       pr("Безубыток выставлен");else pr(Error(GetLastError()));
       }else ObjectDelete("bz"+OrderTicket());
       
       if (TakeProfit!=0)
       {
       // Нарисуем метку Тейк Профита
       arrov("tp"+OrderTicket(), 6, Time[0],NormalizeDouble(OrderOpenPrice()+TakeProfit*Point,Digits), 1, Blue);
       // Проверим расположение цены относительно Тейк Профита
       if(Ask>NormalizeDouble(OrderOpenPrice()+TakeProfit*Point,Digits))
       // Если цена больше заданного значения , закроем ордер
       if (OrderClose(OrderTicket(),OrderLots(),Bid,Slip,Red)==true) 
       // Раскоментируем происходящее                                   
       pr("Ордер закрыт");       else pr(Error(GetLastError()));
       }else ObjectDelete("tp"+OrderTicket());

       if (StopLoss!=0)
       {
       // Нарисуем метку Стоп Лосса
       arrov("sl"+OrderTicket(), 6, Time[0],NormalizeDouble(OrderOpenPrice()-StopLoss*Point,Digits), 1, Red);
       // Проверим расположение цены относительно Стоп Лосса
       if(BidNormalizeDouble(OrderOpenPrice()+StopLoss*Point,Digits))
       if (OrderClose(OrderTicket(),OrderLots(),Ask,Slip,Red)==true)                                    
       pr("Ордер закрыт");       else pr(Error(GetLastError())); 
       }else ObjectDelete("sl"+OrderTicket());
     }
   }
// В случае если ордер закрыт удалим его метки   
objdel();
}
//========================================================================================================================//
int deinit ()
{
// Удаление меток созданных советником при удалении советника
   int d=OrdersTotal(),i;
   for( i=0;i<=d;i++)               
   if ( OrderSelect(i,SELECT_BY_POS) == true )
   { 
   ObjectDelete("bz"+OrderTicket());
   ObjectDelete("tp"+OrderTicket());
   ObjectDelete("sl"+OrderTicket());
   ObjectDelete("txtw"+i);
   }
}
//========================================================================================================================//
void objdel()
{  // В случае если ордер закрыт удалим его метки  
   int d=OrdersHistoryTotal(),i;
   for( i=0;i<=d;i++)               
   if ( OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) == true )
   { 
   ObjectDelete("bz"+OrderTicket());
   ObjectDelete("tp"+OrderTicket());
   ObjectDelete("sl"+OrderTicket());
   }
}
//========================================================================================================================//
// Функция отрисовки меток
//========================================================================================================================//
void arrov(string n, int typ, int tim, double pri, int wid, color cv)
{  if(ObjectFind(n)==-1)
   ObjectCreate(n,OBJ_ARROW      ,0,0,0  );
   ObjectSet   (n,OBJPROP_ARROWCODE,typ  );
   ObjectSet   (n,OBJPROP_TIME1    ,tim  );
   ObjectSet   (n,OBJPROP_PRICE1   ,pri  );
   ObjectSet   (n,OBJPROP_COLOR    ,cv   );
   ObjectSet   (n,OBJPROP_WIDTH    ,wid  );
}
//========================================================================================================================//
// Функция отрисовки сообщений
//========================================================================================================================//
void pr (string txt)
{
string info [];
ArrayResize(info,coment);
string h,m,s,cm; int i;
h=DoubleToStr(Hour(),0);    if (StringLen(h)<2) h="0"+h;
m=DoubleToStr(Minute(),0);  if (StringLen(m)<2) m="0"+m;
s=DoubleToStr(Seconds(),0); if (StringLen(s)<2) s="0"+s;
txt=h+":"+m+":"+s+"  "+txt;
for(i=coment-1; i>=1; i--)
info[i]=info[i-1];
info[0]=txt;
for(i=coment-1; i>=0; i--)
if(info[i]!=""){
cm=info[i];
ObjectCreate ("txtw"+i,OBJ_LABEL,0,0,0);
ObjectSet    ("txtw"+i,OBJPROP_CORNER,0);
ObjectSet    ("txtw"+i,OBJPROP_XDISTANCE,10);
ObjectSet    ("txtw"+i,OBJPROP_YDISTANCE,15*i);
ObjectSetText("txtw"+i,cm, 10, "Times New Roman", Green);}}
//========================================================================================================================//
// Список ошибок
//========================================================================================================================//
string Error(int error_code)
  {
   string error_string;
   switch(error_code)
     {
      case 0:   error_string="No error returned.";                                                            break;
      case 1:   error_string="No error returned, but the result is unknown.";                                 break;
      case 2:   error_string="Common error.";                                                                 break;
      case 3:   error_string="Invalid trade parameters.";                                                     break;
      case 4:   error_string="Trade server is busy.";                                                         break;
      case 5:   error_string="Old version of the client terminal.";                                           break;
      case 6:   error_string="No connection with trade server.";                                              break;
      case 7:   error_string="Not enough rights.";                                                            break;
      case 8:   error_string="Too frequent requests.";                                                        break;
      case 9:   error_string="Malfunctional trade operation.";                                                break;
      case 64:  error_string="Account disabled.";                                                             break;
      case 65:  error_string="Invalid account.";                                                              break;
      case 128: error_string="Trade timeout.";                                                                break;
      case 129: error_string="Invalid price.";                                                                break;
      case 130: error_string="Invalid stops.";                                                                break;
      case 131: error_string="Invalid trade volume.";                                                         break;
      case 132: error_string="Market is closed.";                                                             break;
      case 133: error_string="Trade is disabled.";                                                            break;  
      case 134: error_string="Not enough money.";                                                             break;
      case 135: error_string="Price changed.";                                                                break;
      case 136: error_string="Off quotes.";                                                                   break;
      case 137: error_string="Broker is busy.";                                                               break;
      case 138: error_string="Requote.";                                                                      break;
      case 139: error_string="Order is locked.";                                                              break;
      case 140: error_string="Long positions only allowed.";                                                  break;
      case 141: error_string="Too many requests.";                                                            break;
      case 145: error_string="Modification denied because an order is too close to market.";                  break;
      case 146: error_string="Trade context is busy.";                                                        break;
      case 147: error_string="Expirations are denied by broker.";                                             break;
      case 148: error_string="The amount of opened and pending orders has reached the limit set by a broker.";break;
      case 4000: error_string="No error.";                                                                    break;
      case 4001: error_string="Wrong function pointer.";                                                      break;
      case 4002: error_string="Array index is out of range.";                                                 break;
      case 4003: error_string="No memory for function call stack.";                                           break;
      case 4004: error_string="Recursive stack overflow.";                                                    break;
      case 4005: error_string="Not enough stack for parameter.";                                              break;
      case 4006: error_string="No memory for parameter string.";                                              break;
      case 4007: error_string="No memory for temp string.";                                                   break;
      case 4008: error_string="Not initialized string.";                                                      break;
      case 4009: error_string="Not initialized string in an array.";                                          break;
      case 4010: error_string="No memory for an array string.";                                               break;
      case 4011: error_string="Too long string.";                                                             break;
      case 4012: error_string="Remainder from zero divide.";                                                  break;
      case 4013: error_string="Zero divide.";                                                                 break;
      case 4014: error_string="Unknown command.";                                                             break;
      case 4015: error_string="Wrong jump.";                                                                  break;
      case 4016: error_string="Not initialized array.";                                                       break;
      case 4017: error_string="DLL calls are not allowed.";                                                   break;
      case 4018: error_string="Cannot load library.";                                                         break;
      case 4019: error_string="Cannot call function.";                                                        break;
      case 4020: error_string="EA function calls are not allowed.";                                           break;
      case 4021: error_string="Not enough memory for a string returned from a function.";                     break;
      case 4022: error_string="System is busy.";                                                              break;
      case 4050: error_string="Invalid function parameters count.";                                           break;
      case 4051: error_string="Invalid function parameter value.";                                            break;
      case 4052: error_string="String function internal error.";                                              break;
      case 4053: error_string="Some array error.";                                                            break;
      case 4054: error_string="Incorrect series array using.";                                                break;
      case 4055: error_string="Custom indicator error.";                                                      break;
      case 4056: error_string="Arrays are incompatible.";                                                     break;
      case 4057: error_string="Global variables processing error.";                                           break;
      case 4058: error_string="Global variable not found.";                                                   break;
      case 4059: error_string="Function is not allowed in testing mode.";                                     break;
      case 4060: error_string="Function is not confirmed.";                                                   break;
      case 4061: error_string="Mail sending error.";                                                          break;
      case 4062: error_string="String parameter expected.";                                                   break;
      case 4063: error_string="Integer parameter expected.";                                                  break;
      case 4064: error_string="Double parameter expected.";                                                   break;
      case 4065: error_string="Array as parameter expected.";                                                 break;
      case 4066: error_string="Requested history data in updating state.";                                    break;
      case 4067: error_string="Some error in trade operation execution.";                                     break;
      case 4099: error_string="End of a file.";                                                               break;
      case 4100: error_string="Some file error.";                                                             break;
      case 4101: error_string="Wrong file name.";                                                             break;
      case 4102: error_string="Too many opened files.";                                                       break;
      case 4103: error_string="Cannot open file.";                                                            break;
      case 4104: error_string="Incompatible access to a file.";                                               break;
      case 4105: error_string="No order selected.";                                                           break;
      case 4106: error_string="Unknown symbol.";                                                              break;
      case 4107: error_string="Invalid price.";                                                               break;
      case 4108: error_string="Invalid ticket.";                                                              break;
      case 4109: error_string="Trade is not allowed.";                                                        break;
      case 4110: error_string="Longs are not allowed.";                                                       break;
      case 4111: error_string="Shorts are not allowed.";                                                      break;
      case 4200: error_string="Object already exists.";                                                       break;
      case 4201: error_string="Unknown object property.";                                                     break;
      case 4202: error_string="Object does not exist.";                                                       break;
      case 4203: error_string="Unknown object type.";                                                         break;
      case 4204: error_string="No object name.";                                                              break;
      case 4205: error_string="Object coordinates error.";                                                    break;
      case 4206: error_string="No specified subwindow.";                                                      break;
      default:   error_string="Some error in object operation.";
     }
   return(error_string);
  }
//========================================================================================================================//  

Recommend