Профи, не проходите мимо, оцените пожалуйста эксперта - страница 3

 
Vitya писал(а) >>

Похоже разобрался.

Это у вас происходит от того что не совсем верно задано условие постом выше

Нужно учесть что при открытии первого ордера на покупку его таке профит равен нулю, от сюда вся дальнейшая цепочка в buy не модифицируется.

Да, да. Это от спешки, приношу извинения. После того ответа увидел причину, но, к сожалению, до понедельника остался без интернета.

 

Вот из ветки https://www.mql5.com/ru/forum/122700/page2 решил попробовать добавить фильтр, не знаю, при оптимизации за 4 месяца там где раньше сливал без фильтров, просадка составила около 24%

хотя может и подгонка

Посмотрите, что думаете 

 

Vitya писал(а) >>
Usrednenie_test_tp_control_2_vol_filter.mq4 (0.00 KB)

 
сори
Файлы:
 
Всем здраствуйте,помогите разобраться с кодом советника , я не очень силен в программировании. Читал учебник но так понять и не смог по какой причине он у меня не открывает ордера.Есть подозрения на переменную  oLots . По чему не работает,повторюсь я так не понял.
//+------------------------------------------------------------------+
//|                                               Проба Кукловод.mq4 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
extern bool   Korzina_JPY           = true;
extern bool   Korzina_JPY_Martin    = false;
extern double Lots                  = 0.1;
extern double Multipler             = 1.68;
extern int    Slippage              = 5;
extern int    Magic_jpy             = 33333;
extern double Percent_Risk          = 20.0;
extern double indi_jpy_plus_10_30   = 10.0;
extern double indi_jpy_plus_10_30a  = 30.0;
extern double indi_jpy_TakeProfit   = 70.0;
extern double indi_jpy_StopLoss     = -10;
extern double indi_jpy_StopLoss_1   = -11;
//----------------------------------------+
extern double indi_jpy_Minus_10_30  = -10.0;
extern double indi_jpy_Minus_10_30c = -30.0;
extern double indi_jpy_TakeProfit_b = -70.0;
extern double indi_jpy_StopLoss_b   =  10;
extern double indi_jpy_StopLoss_b_1 =  11;
////////////////////////////////////////////
extern double indi_jpy_martin_70_M  = -70; 
extern double indi_jpy_martin_70_M1 = -71; 
extern double indi_jpy_martin_80_M  = -80;
extern double indi_jpy_martin_80_M1 = -81;
extern double indi_jpy_martin_90_M  = -90;
extern double indi_jpy_martin_90_M1 = -91;
//-----------------------------------------
extern double indi_jpy_martin_70_P  = 70; 
extern double indi_jpy_martin_70_P1 = 71; 
extern double indi_jpy_martin_80_P  = 80; 
extern double indi_jpy_martin_80_P1 = 81; 
extern double indi_jpy_martin_90_P  = 90; 
extern double indi_jpy_martin_90_P1 = 91;
extern double MartinTakeProfiteM    = 1;
extern double MartinTakeProfiteM1   = 5;
extern double MartinTakeProfiteP    = -1;
extern double MartinTakeProfiteP1   = -5;
int ticket,size_jpy,retries,Total,pairCount_JPY,Nusr;
double indi_jpy,oLots;
datetime timeprev;
string jpy[] = {"AUDJPY","CADJPY","CHFJPY","EURJPY","GBPJPY","NZDJPY","USDJPY"};
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
 if(Digits == 5 || Digits == 3)  
      {
      if(Digits == 4 || Digits == 2)
      {
       Slippage *= 10;
        }
       }  
  size_jpy = ArraySize(jpy);
  pairCount_JPY = size_jpy; 
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   oLots=Lots;
   indi_jpy = iCustom(Symbol(),PERIOD_D1,"Kuklovod_JPY",7,0);
   bool plus = false,minus = false,plusx = false,minusx = false,stoploss=false,takeprofite=false;
   Total=CountTrades();

   if(Time[0] == timeprev) return;
   timeprev=Time[0];
 if(Korzina_JPY == true){  
  if(Total == 0 &&  timeprev && indi_jpy >= indi_jpy_plus_10_30 && indi_jpy <= indi_jpy_plus_10_30a)    plus = true;
   if(Total == 0 &&  timeprev && indi_jpy <= indi_jpy_Minus_10_30 && indi_jpy >= indi_jpy_Minus_10_30c) minus = true;
    if(!plus && !minus) return;
     if(plus == true)  { Open_Sell_JPY();}
      if(minus == true) { Open_Buy_JPY(); }
       if(Total > 0 && indi_jpy >= indi_jpy_TakeProfit)                                         takeprofite=true;                
        if(takeprofite==true)   {Close_Orders_JPY();}
         if(Total > 0 && indi_jpy <= indi_jpy_StopLoss && indi_jpy >= indi_jpy_StopLoss_1)       stoploss=true;    
          if(stoploss==true)     {Close_Orders_JPY();}
           if(Total > 0 && indi_jpy<=indi_jpy_TakeProfit_b)                                      takeprofite=true; 
            if(takeprofite==true) {Close_Orders_JPY();}
             if(Total > 0 && indi_jpy>=indi_jpy_StopLoss_b && indi_jpy <= indi_jpy_StopLoss_b_1) stoploss=true;  
              if(stoploss==true)   {Close_Orders_JPY();}
             }
//------------------------------------------------------------------------------------------------------------------------------------------+
if(Korzina_JPY_Martin == true)
{
if(Total == 0)
{
if(indi_jpy <= indi_jpy_martin_70_M && indi_jpy >=indi_jpy_martin_70_M1)   plusx = true;
if(indi_jpy >= indi_jpy_martin_70_P && indi_jpy <= indi_jpy_martin_70_P1)  minusx = true;
if(!plusx && !minusx) return;
Nusr = 0;
}
else
{
 Nusr = Total/pairCount_JPY;
 if (Nusr > 3) return;
}
 oLots = Lots * MathPow(Multipler,Nusr);
 if(plusx  == true && Uslovie_Buy_JPY())      {Open_Buy_JPY();}
 if(minusx  == true && Uslovie_Sell_JPY())    {Open_Sell_JPY();}
 bool closprofiteM = false,closprofiteP = false,close_loss=false;
 
 if(Total > 0 && indi_jpy >= MartinTakeProfiteM && indi_jpy <= MartinTakeProfiteM1)  closprofiteM = true;
 if(closprofiteM == true)  {Close_Orders_JPY();}
 if(Total > 0 && indi_jpy <= MartinTakeProfiteP && indi_jpy >= MartinTakeProfiteP1)  closprofiteP = true;
 if(closprofiteP == true)  {Close_Orders_JPY();}
  close_loss=NormalizeDouble(AccountBalance()/100*Percent_Risk + OrderProfit() < 0,2); 
  if(close_loss)  { Close_Orders_JPY();}
}//if(Korzina_JPY_Martin == true)
 //---
}//void OnTick()
//-------------------Условие для долики ордеров----------------------+
bool Uslovie_Sell_JPY()
{
 bool res = false;
   if(Nusr == 0)  res = true;
   if(Nusr == 1 && indi_jpy >= indi_jpy_martin_80_P && indi_jpy <= indi_jpy_martin_80_P1)  res = true;
   if(Nusr == 2 && indi_jpy >= indi_jpy_martin_90_P && indi_jpy <= indi_jpy_martin_90_P1)  res = true;
return(res);
}
//-------------------Условие для долики ордеров----------------------+
bool Uslovie_Buy_JPY()
{
 bool res = false;
   if(Nusr == 0)  res = true;
   if(Nusr == 1 && indi_jpy <= indi_jpy_martin_80_M && indi_jpy >= indi_jpy_martin_80_M1)  res = true;
   if(Nusr == 2 && indi_jpy <= indi_jpy_martin_90_M && indi_jpy >= indi_jpy_martin_90_M1)  res = true;
return(res);
}
//-------------------Функция закрытия ордеров JPY--------------------+
void Close_Orders_JPY()
{
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderMagicNumber() == Magic_jpy)
{
if(OrderType() == OP_BUY || OrderType() == OP_SELL)
{
if(OrderType() == OP_BUY)  if(OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,clrYellow))Print("Ордер закрыт успешно ! "+OrderSymbol());Alert("Ошибка закрытия № "+IntegerToString(GetLastError())+"  ордера по символу "+OrderSymbol());
if(OrderType() == OP_SELL) if(OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,clrYellow))Print("Ордер закрыт успешно ! "+OrderSymbol());Alert("Ошибка закрытия № "+IntegerToString(GetLastError())+"  ордера по символу "+OrderSymbol());
    }
   }
  }
 }
}
//+------------------Функция открытия ордеров--------------------+
void Open_Buy_JPY()
{  
   int c;
   for(c=size_jpy-1; c >=0; c--)
   {
   OrderSendReliable(jpy[c],OP_BUY,oLots,Ask,Slippage,0,0,"",Magic_jpy,0,clrGreen);
   }
  }
//-------------------Функция открытия ордеров-------------------+
void Open_Sell_JPY()
{  
   int c;
   for(c=size_jpy-1; c >=0; c--)
   {
   OrderSendReliable(jpy[c],OP_SELL,oLots,Bid,Slippage,0,0,"",Magic_jpy,0,clrRed);
   }
  }
//+------------------------------------------------------------------+
int CountTrades()
{
   int count = 0;
   for(int i=OrdersTotal()-1; i >= 0; i--)
   {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
      if(OrderMagicNumber() == Magic_jpy)     count++;
 }
 return(count);
}
//----------------Функция оброботки ошибок---------------------------+
int OrderSendReliable(string asymbol, int cmd, double volume, double aprice,
                 int slippage, double stoploss, double takeprofit,
                 string acomment, int magic, datetime expiration = 0, 
                 color arrow_color = CLR_NONE) 
{
   int err = GetLastError(); 
   err = 0; 
   bool exit_loop = false;
   bool limit_to_market = false; 

   err = GetLastError(); 
   err = 0; 
   ticket = -1;

   if ((cmd == OP_BUY) || (cmd == OP_SELL)) 
   {
      int cnt = 0;
      while (!exit_loop) 
      {
         if (IsTradeAllowed()) 
         {
            ticket = OrderSend(asymbol, cmd, volume, aprice, slippage, 
                           stoploss, takeprofit, acomment, magic, 
                           expiration, arrow_color);
            err = GetLastError();
         } 
         else 
         {
            cnt++;
         } 
         switch (err) 
         {
            case ERR_NO_ERROR:
               exit_loop = true;
               break;
               
            case ERR_SERVER_BUSY:
            case ERR_NO_CONNECTION:
            case ERR_INVALID_PRICE:
            case ERR_OFF_QUOTES:
            case ERR_BROKER_BUSY:
            case ERR_TRADE_CONTEXT_BUSY: 
               cnt++;
               break;
               
            case ERR_PRICE_CHANGED:
            case ERR_REQUOTE:
               RefreshRates();
               continue; 
               
            default:
               exit_loop = true;
               break; 
               
         }  // end switch 

         if (cnt > retries) 
             exit_loop = true; 
             
         if (!exit_loop) 
         {
            Sleep(1000); 
            RefreshRates(); 
         }
         
         if (exit_loop) 
         {
            if (err != ERR_NO_ERROR) 
            {
               Alert("Ошибка : " + IntegerToString(err)); 
            }
         }
      }
      
      if (err == ERR_NO_ERROR) 
      {
         if(OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES)) 
         return(ticket);
      } 
      Alert("Ошибка открытия ордера после " + IntegerToString(cnt) + " попыток."+" по символу "+OrderSymbol());
      Alert("Ошибка : " + IntegerToString(err)); 
      return(-1); 
   }
   return(-1);
}
//+------------------------------------------------------------------+
 
Причина обращения: