Скачать MetaTrader 5

Помогите!!! Изменить совеник, чтобы верно открывал ордера!

Авторизуйтесь или зарегистрируйтесь, чтобы добавить комментарий
Yura Vakulenko
314
Yura Vakulenko  

Здравствуйте! Очень нужна помощь знатоков в мкл 4!!! Очень!  Уже не знаю, куда и обратится.. а у самого не выходит верно написать код советника.

Есть советник,, который я написал по одному из моих индикаторов.  индикатор рисует вот такие стрелочки.. которые не перерисовываются..


Я написал по нему советник, но он открывает только по 1 ордеру на всю серию сигналов (берутся только первые сигналы во всей серии, ну и закрывает это ордер при поступлении против. сигнала..  ) кАК СЕЙЧАС ТОРГУЕТ СМОТРИТЕ НА РИСУНКЕ НИЖЕ.


А нужно, чтобы он торговал так, как показано на 3-м рисунке НИЖЕ.. т.е. при появлении стрелки открывал ордер, и закрывал все открытые ордера при появлении против стрелки.


И при этом рассчитывал лот, для каждого послед. ордера в серии (можно использовать для этого коэф. или я позже напишу более подробнее схему рассчета лота. ) В общем, помогите!! Я уже давно с этим совом долбаюсь. Индикатор я не могу скинуть, он платный и привязан только к моему счету! Сигналы на покупку\продажу в советнике написаны верно!

вот мой код советника.. (то, что закомментировано - это просто я там еще разные функции добавлял для проверки.. это использовать не нужно. Заком. код можно вообще удалить. )

СОВЕТНИК ДОЛЖЕН ТОРГОВАТЬ ТОЬКО ПО ОТКРЫТИЮ БАРОВ!!

//+------------------------------------------------------------------+
//|                                                 Reversal_exp.mq4 |
//|                                                 |
//|                                            |
//+------------------------------------------------------------------+
#include <stdlib.mqh>
#include <stderror.mqh>
#property copyright ""
#property link      ""
#property version   "1.00"
#property strict

extern double Lots                           = 0.1;
extern int    Slippage                       = 5;
extern int    Magic                          = 110011;
input bool    Without_Loss                   = false;
extern int    StepStopLoss                   = 5;
extern int    StepStopLossx                  = 25;
input bool    MartinTrade                    = false;
input bool    reverse                        = false;
extern double Multiplier                     = 1.228;
extern int    MaxOrders                      = 7;
extern string _                              = "Настройки индикатора";
extern string timeframe                      = "0";
input int     Main_Period                    = 264;
input int     Main_Price                     = 5;
input double  Down_floor                     = -280.0;
input double  Up_floor                       = 150.0;
input double  Length                         = 5.0;
input double  Phase                          = 100.0;
extern bool   loging                         = false;
extern bool   use_data_from_closed_candle    = true;
extern string __                             = "Настройки индикатора";
extern int     ATR_Period                    = 10;
extern double  Multipluer                    =1.7;
extern int     Indicator_use                 =1; // 1- Reversal; 2-VHT
extern int     alertsOn                      =false;

int Total_SELL,
    Total_Buy, total_orders,
    ticket,ticket_sell,ticket_buy,retries,
    sell_signal, buy_signal, M_sell_signal, M_buy_signal, M1_sell_signal, M1_buy_signal,vht_buy_signal,vht_sell_signal,
    _OR_err;
    
double ask,bid,price;

double  REVERSAL_Signal1,REVERSAL1_1_0,REVERSAL1_1_1,REVERSAL1_1_2,REVERSAL1_2_0,REVERSAL1_2_1,REVERSAL1_2_2,
        REVERSAL_Signal,
        REVERSAL_1,
        REVERSAL_2,
        REVERSAL_1_0,
        REVERSAL_1_1,
        REVERSAL_1_2,
        REVERSAL_3_0,
        REVERSAL_3_1,
        REVERSAL_3_2,
        REVERSAL_6_0,
        REVERSAL_6_1,
        REVERSAL_6_2;
        
string  osymbol,
        symbol,
        asymbolx;
        
datetime prevtime;
datetime previousSignal = 0;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   if(_Digits == 5 || _Digits == 3)
   {
      Slippage       *= 10;
      StepStopLoss   *= 10;
      StepStopLossx  *= 10;
   }
   
   prevtime = Time[0];
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   Comment("");
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
//работа по открытию бара
 if(use_data_from_closed_candle)
 {
   if (Time[0] == prevtime) return;
   prevtime = Time[0];
 }


REVERSAL_Signal = iCustom(NULL,0,"REVERSAL",timeframe,Main_Period,Main_Price,Down_floor,Up_floor,Length,Phase,0,0);
REVERSAL_1 =      iCustom(NULL,0,"REVERSAL",timeframe,Main_Period,Main_Price,Down_floor,Up_floor,Length,Phase,0,1);
REVERSAL_2 =      iCustom(NULL,0,"REVERSAL",timeframe,Main_Period,Main_Price,Down_floor,Up_floor,Length,Phase,0,2);
REVERSAL_1_0 =      iCustom(NULL,0,"REVERSAL",timeframe,Main_Period,Main_Price,Down_floor,Up_floor,Length,Phase,1,0);
REVERSAL_1_1 =      iCustom(NULL,0,"REVERSAL",timeframe,Main_Period,Main_Price,Down_floor,Up_floor,Length,Phase,1,1);
REVERSAL_1_2 =      iCustom(NULL,0,"REVERSAL",timeframe,Main_Period,Main_Price,Down_floor,Up_floor,Length,Phase,1,2);
/*REVERSAL_Signal1 = iCustom(NULL,0,"VHT","-",ATR_Period,Multipluer,0,0);
REVERSAL1_1_0 =      iCustom(NULL,0,"VHT","-",ATR_Period,Multipluer,"",Blue,Red,Blue,Red,Green,2,2,1,"",alertsOn,1,0);
REVERSAL1_1_1 =      iCustom(NULL,0,"VHT","-",ATR_Period,Multipluer,"",Blue,Red,Blue,Red,Green,2,2,1,"",alertsOn,1,1);
REVERSAL1_1_2 =      iCustom(NULL,0,"VHT","-",ATR_Period,Multipluer,"",Blue,Red,Blue,Red,Green,2,2,1,"",alertsOn,1,2);
REVERSAL1_2_0 =      iCustom(NULL,0,"VHT","-",ATR_Period,Multipluer,"",Blue,Red,Blue,Red,Green,2,2,1,"",alertsOn,2,0);
REVERSAL1_2_1 =      iCustom(NULL,0,"VHT","-",ATR_Period,Multipluer,"",Blue,Red,Blue,Red,Green,2,2,1,"",alertsOn,2,1);
REVERSAL1_2_2 =      iCustom(NULL,0,"VHT","-",ATR_Period,Multipluer,"",Blue,Red,Blue,Red,Green,2,2,1,"",alertsOn,2,2); */
//REVERSAL_3_0 =      iCustom(NULL,0,"REVERSAL",timeframe,Main_Period,Main_Price,Down_floor,Up_floor,Length,Phase,3,0);
//REVERSAL_3_1 =      iCustom(NULL,0,"REVERSAL",timeframe,Main_Period,Main_Price,Down_floor,Up_floor,Length,Phase,3,1);
//REVERSAL_3_2 =      iCustom(NULL,0,"REVERSAL",timeframe,Main_Period,Main_Price,Down_floor,Up_floor,Length,Phase,3,2);
//REVERSAL_6_0 =      iCustom(NULL,0,"REVERSAL",timeframe,Main_Period,Main_Price,Down_floor,Up_floor,Length,Phase,6,0);
//REVERSAL_6_1 =      iCustom(NULL,0,"REVERSAL",timeframe,Main_Period,Main_Price,Down_floor,Up_floor,Length,Phase,6,1);
//REVERSAL_6_2 =      iCustom(NULL,0,"REVERSAL",timeframe,Main_Period,Main_Price,Down_floor,Up_floor,Length,Phase,6,2);


ask = NormalizeDouble (MarketInfo(Symbol(),MODE_ASK), Digits);
bid = NormalizeDouble (MarketInfo(Symbol(),MODE_BID), Digits);
_OR_err = GetLastError();

Total_SELL = CountTrades(OP_SELL);
Total_Buy = CountTrades(OP_BUY);
total_orders = OrdersTotal();

      
if ( REVERSAL_Signal < Up_floor &&  REVERSAL_1 < Up_floor &&  REVERSAL_2 >= Up_floor /*&& REVERSAL_1_2 > Up_floor*/) {sell_signal =1; buy_signal=0;} 
if ( REVERSAL_Signal > Down_floor && REVERSAL_1 > Down_floor &&  REVERSAL_2 <= Down_floor /*&& REVERSAL_3_2 < Down_floor*/) {buy_signal=1; sell_signal =0; }

//if (REVERSAL1_1_0 ==EMPTY_VALUE && REVERSAL1_1_1 ==EMPTY_VALUE && REVERSAL1_2_1 != EMPTY_VALUE && REVERSAL1_1_2 == REVERSAL1_2_2) {vht_buy_signal=1; vht_sell_signal =0;}
//if (REVERSAL1_1_0 ==EMPTY_VALUE && REVERSAL1_2_1 ==EMPTY_VALUE && REVERSAL1_1_1 != EMPTY_VALUE && REVERSAL1_1_2 == REVERSAL1_2_2) {vht_sell_signal=1; vht_buy_signal =0;}
//if (REVERSAL_1_0 == EMPTY_VALUE && REVERSAL_1_1 == EMPTY_VALUE && REVERSAL_1_2 > Up_floor && REVERSAL_Signal < Up_floor ) {M_sell_signal =1; M_buy_signal=0;} 
//if (REVERSAL_3_0 == EMPTY_VALUE && REVERSAL_3_1 == EMPTY_VALUE && REVERSAL_3_2 < Down_floor && REVERSAL_Signal > Down_floor ) {M_buy_signal=1; M_sell_signal =0; } 

//if (REVERSAL_6_2 ==1 && REVERSAL_6_1 ==0 && REVERSAL_6_0 ==0 ) {M1_sell_signal =1; M1_buy_signal=0;} 
//if (REVERSAL_6_2 ==-1 && REVERSAL_6_1 ==0 && REVERSAL_6_0 ==0 ) {M1_buy_signal=1; M1_sell_signal =0; } 
//if(prevtime && sell_signal == 1 ) Close_Orders(OP_BUY,loging);
//if(prevtime && buy_signal == 1)  Close_Orders(OP_SELL,loging);

          /* if (!MartinTrade && Indicator_use == 2) //No Martin Trade start
           {
           if(prevtime && vht_buy_signal == 1 && Total_Buy==0 && !reverse )  //buy order
            {
                  if (Total_SELL>0) CLOSEORDER(OP_SELL);//Close_Orders(OP_SELL,loging);//CLOSEORDER(OP_SELL);
                  ticket_buy = OrderSendReliable(Symbol(),OP_BUY,Lots,ask,Slippage,0,0,"",Magic,0,clrGreen,loging); //OrderSend(Symbol(),OP_BUY,Lots,NormalizeDouble(Ask,Digits),Slippage,0,0,"",Magic,0,clrBlue);       
             }
            
            if(prevtime && vht_buy_signal == 1 && Total_SELL==0 && reverse )  //buy Reverse order
            {        
                  if (Total_Buy>0) CLOSEORDER(OP_BUY);
                  ticket_buy = OrderSendReliable(Symbol(),OP_SELL,Lots,bid,Slippage,0,0,"",Magic,0,clrRed,loging);//OrderSend(Symbol(),OP_SELL,Lots,NormalizeDouble(Bid,Digits),Slippage,0,0,"",Magic,0,clrRed);//OrderSendReliable(Symbol(),OP_SELL,Lots,bid,Slippage,0,0,"",Magic,0,clrRed,loging);
                                
            }
            
           if(prevtime && vht_sell_signal == 1 && Total_SELL==0 && !reverse ) // sell order
            {
                  if (Total_Buy>0) CLOSEORDER(OP_BUY);//Close_Orders(OP_BUY,loging);
                  ticket_sell = OrderSendReliable(Symbol(),OP_SELL,Lots,bid,Slippage,0,0,"",Magic,0,clrRed,loging);//OrderSend(Symbol(),OP_SELL,Lots,NormalizeDouble(Ask,Digits),Slippage,0,0,"",Magic,0,clrRed);//OrderSendReliable(Symbol(),OP_SELL,Lots,bid,Slippage,0,0,"",Magic,0,clrRed,loging);
                          
            }
            if(prevtime && vht_sell_signal == 1 && Total_Buy==0 && reverse ) // sell Reverse order
            {
                  if (Total_SELL>0)CLOSEORDER(OP_SELL);
                  ticket_sell = OrderSendReliable(Symbol(),OP_BUY,Lots,ask,Slippage,0,0,"",Magic,0,clrGreen,loging);//OrderSend(Symbol(),OP_BUY,Lots,NormalizeDouble(Ask,Digits),Slippage,0,0,"",Magic,0,clrBlue);//OrderSendReliable(Symbol(),OP_BUY,Lots,ask,Slippage,0,0,"",Magic,0,clrGreen,loging);
             
             }
          }*/// end !MartinTrade
           
           if (!MartinTrade /*&& Indicator_use == 1*/) //No Martin Trade start
           {
           if(prevtime && buy_signal == 1 && Total_Buy==0 && !reverse )  //buy order
            {
                  if (Total_SELL>0) CLOSEORDER(OP_SELL);//Close_Orders(OP_SELL,loging);//CLOSEORDER(OP_SELL);
                  ticket_buy = OrderSendReliable(Symbol(),OP_BUY,Lots,ask,Slippage,0,0,"",Magic,0,clrGreen,loging); //OrderSend(Symbol(),OP_BUY,Lots,NormalizeDouble(Ask,Digits),Slippage,0,0,"",Magic,0,clrBlue);       
                  
             }
            
            if(prevtime && buy_signal == 1 && Total_SELL==0 && reverse )  //buy Reverse order
            {        
                  if (Total_Buy>0) CLOSEORDER(OP_BUY);
                  ticket_buy = OrderSendReliable(Symbol(),OP_SELL,Lots,bid,Slippage,0,0,"",Magic,0,clrRed,loging);//OrderSend(Symbol(),OP_SELL,Lots,NormalizeDouble(Bid,Digits),Slippage,0,0,"",Magic,0,clrRed);//OrderSendReliable(Symbol(),OP_SELL,Lots,bid,Slippage,0,0,"",Magic,0,clrRed,loging);
                  
                                
            }
            
           if(prevtime && sell_signal == 1 && Total_SELL==0 && !reverse ) // sell order
            {
                  if (Total_Buy>0) CLOSEORDER(OP_BUY);//Close_Orders(OP_BUY,loging);
                  ticket_sell = OrderSendReliable(Symbol(),OP_SELL,Lots,bid,Slippage,0,0,"",Magic,0,clrRed,loging);//OrderSend(Symbol(),OP_SELL,Lots,NormalizeDouble(Ask,Digits),Slippage,0,0,"",Magic,0,clrRed);//OrderSendReliable(Symbol(),OP_SELL,Lots,bid,Slippage,0,0,"",Magic,0,clrRed,loging);
                  
                          
            }
            if(prevtime && sell_signal == 1 && Total_Buy==0 && reverse ) // sell Reverse order
            {
                  if (Total_SELL>0)CLOSEORDER(OP_SELL);
                  ticket_sell = OrderSendReliable(Symbol(),OP_BUY,Lots,ask,Slippage,0,0,"",Magic,0,clrGreen,loging);//OrderSend(Symbol(),OP_BUY,Lots,NormalizeDouble(Ask,Digits),Slippage,0,0,"",Magic,0,clrBlue);//OrderSendReliable(Symbol(),OP_BUY,Lots,ask,Slippage,0,0,"",Magic,0,clrGreen,loging);
                  
             
             }
          }// end !MartinTrade
          
          else // Martin trade start
          {
            if (MartinTrade )
            {
            if(prevtime && buy_signal == 1 &&  Total_Buy>=0 &&  Total_Buy < MaxOrders && !reverse )  //buy order
            {
                  if (Total_SELL>0) CLOSEORDER(OP_SELL);//Close_Orders(OP_SELL,loging);//CLOSEORDER(OP_SELL);
                  ticket_buy = OrderSendReliable(Symbol(),OP_BUY,Lots,ask,Slippage,0,0,"",Magic,0,clrGreen,loging); //OrderSend(Symbol(),OP_BUY,Lots,NormalizeDouble(Ask,Digits),Slippage,0,0,"",Magic,0,clrBlue);       
                  
             }
            
            if(prevtime && buy_signal == 1 &&  Total_SELL>=0 &&  Total_SELL < MaxOrders && reverse )  //buy Reverse order
            {        
                  if (Total_Buy>0) CLOSEORDER(OP_BUY);
                  ticket_buy = OrderSendReliable(Symbol(),OP_SELL,Lots,bid,Slippage,0,0,"",Magic,0,clrRed,loging);//OrderSend(Symbol(),OP_SELL,Lots,NormalizeDouble(Bid,Digits),Slippage,0,0,"",Magic,0,clrRed);//OrderSendReliable(Symbol(),OP_SELL,Lots,bid,Slippage,0,0,"",Magic,0,clrRed,loging);
                  
                                
            }
            
           if(prevtime && sell_signal == 1 &&  Total_SELL>=0 && Total_SELL < MaxOrders && !reverse ) // sell order
            {
                  if (Total_Buy>0) CLOSEORDER(OP_BUY);//Close_Orders(OP_BUY,loging);
                  ticket_sell = OrderSendReliable(Symbol(),OP_SELL,Lots,bid,Slippage,0,0,"",Magic,0,clrRed,loging);//OrderSend(Symbol(),OP_SELL,Lots,NormalizeDouble(Ask,Digits),Slippage,0,0,"",Magic,0,clrRed);//OrderSendReliable(Symbol(),OP_SELL,Lots,bid,Slippage,0,0,"",Magic,0,clrRed,loging);
                  
                          
            }
            if(prevtime && sell_signal == 1  &&  Total_Buy>=0 && Total_Buy < MaxOrders && reverse ) // sell Reverse order
            {
                  if (Total_SELL>0)CLOSEORDER(OP_SELL);
                  ticket_sell = OrderSendReliable(Symbol(),OP_BUY,Lots,ask,Slippage,0,0,"",Magic,0,clrGreen,loging);//OrderSend(Symbol(),OP_BUY,Lots,NormalizeDouble(Ask,Digits),Slippage,0,0,"",Magic,0,clrBlue);//OrderSendReliable(Symbol(),OP_BUY,Lots,ask,Slippage,0,0,"",Magic,0,clrGreen,loging);
                  
             
             }
            }
          }
           
           
           
   
  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
int CountTrades( int otype)
{
   int count = 0;
   for(int i=OrdersTotal()-1; i >= 0; i--)
   {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
      {
      if(OrderType() == OP_BUY || OrderType() == OP_SELL)
      {
      if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == otype)     
      count++;
    }
   }
  }
 
return(count);
}

//---------------------------------------
void Close_Orders(int otype, bool loging_b) 
{


   for (int pos_0 = OrdersTotal() - 1; pos_0 >= 0; pos_0--) 
   {
      if(OrderSelect(pos_0, SELECT_BY_POS, MODE_TRADES))
      {
       if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == otype) 
         {
         if(OrderType() == OP_BUY || OrderType() == OP_SELL)
         {
            if (OrderType() == OP_BUY) if(OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, clrBlue))
            if (loging_b)
            {Print("Ошибка закрытия ордера "+IntegerToString(_OR_err));}
            if (OrderType() == OP_SELL) if(OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, clrRed))
            if (loging_b) 
             {Print("Ошибка закрытия ордера "+IntegerToString(_OR_err));}
            }
           }
           Sleep(1000);
        }
     }
   }
//--------------------------------------------------------------------
void CLOSEORDER(int ord)
{
   for (int i=0; i<OrdersTotal(); i++)
   {                                               
      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
      {
         if (OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
         {
            if (OrderType()==OP_BUY && ord==OP_BUY)
               OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),Slippage,CLR_NONE);
            if (OrderType()==OP_SELL && ord==OP_SELL)
               OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),Slippage,CLR_NONE);
         }
      }   
   }
}

//================================================================================++
  int OrderSendReliable(string osymbolx, int cmd, double volume, double aprice,
                 int slippage, double stoploss, double takeprofit,
                 string acomment, int magic, datetime expiration = 0, 
                 color arrow_color = CLR_NONE, bool logining_s = false) 
{
   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()) 
         {
       
      // Comment(asymbol,"\n",cmd,"\n",volume,"\n",aprice,"\n",slippage,"\n",stoploss,"\n",takeprofit,"\n",acomment,"\n",magic);
       
            ticket = OrderSend(osymbol, 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 && logining_s) 
            {
               Print("Ошибка : " + IntegerToString(err)); 
            }
         }
      }
      
      if (err == ERR_NO_ERROR && logining_s) 
      {
         if(OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES)) 
         return(ticket);
      } 
      if (logining_s)
      {
      Print("Ошибка открытия ордера после " + IntegerToString(cnt) + " попыток."+" по символу "+OrderSymbol());
      Print("Ошибка : " + IntegerToString(err));
      } 
      return(-1); 
   }
   return(-1);
}
//+------------------------------------------------------------------+
Andrey F. Zelinsky
32489
Andrey F. Zelinsky  

у вас в коде:

if(prevtime && buy_signal == 1 && Total_Buy==0 && !reverse )  //buy order

-- открытие идёт, если в данном направлении НЕТ ордеров.

уберите эту проверку и будет открытие, когда будет сигнал 

аналогично, по селл 

Yura Vakulenko
314
Yura Vakulenko  

вот убрал. теперь код выглядит так.. Привел пример только секции, отвечающей за торговлю с мартиным..

else // Martin trade start
          {
            if (MartinTrade )
            {
            if(prevtime && buy_signal == 1 && Total_Buy < MaxOrders && !reverse )  //buy order
            {
                  if (Total_SELL>0) CLOSEORDER(OP_SELL);//Close_Orders(OP_SELL,loging);//CLOSEORDER(OP_SELL);
                  ticket_buy = OrderSendReliable(Symbol(),OP_BUY,Lots,ask,Slippage,0,0,"",Magic,0,clrGreen,loging); //OrderSend(Symbol(),OP_BUY,Lots,NormalizeDouble(Ask,Digits),Slippage,0,0,"",Magic,0,clrBlue);       
                  
             }
            
            if(prevtime && buy_signal == 1 &&  Total_SELL < MaxOrders && reverse )  //buy Reverse order
            {        
                  if (Total_Buy>0) CLOSEORDER(OP_BUY);
                  ticket_buy = OrderSendReliable(Symbol(),OP_SELL,Lots,bid,Slippage,0,0,"",Magic,0,clrRed,loging);//OrderSend(Symbol(),OP_SELL,Lots,NormalizeDouble(Bid,Digits),Slippage,0,0,"",Magic,0,clrRed);//OrderSendReliable(Symbol(),OP_SELL,Lots,bid,Slippage,0,0,"",Magic,0,clrRed,loging);
                  
                                
            }
            
           if(prevtime && sell_signal == 1  && Total_SELL < MaxOrders && !reverse ) // sell order
            {
                  if (Total_Buy>0) CLOSEORDER(OP_BUY);//Close_Orders(OP_BUY,loging);
                  ticket_sell = OrderSendReliable(Symbol(),OP_SELL,Lots,bid,Slippage,0,0,"",Magic,0,clrRed,loging);//OrderSend(Symbol(),OP_SELL,Lots,NormalizeDouble(Ask,Digits),Slippage,0,0,"",Magic,0,clrRed);//OrderSendReliable(Symbol(),OP_SELL,Lots,bid,Slippage,0,0,"",Magic,0,clrRed,loging);
                  
                          
            }
            if(prevtime && sell_signal == 1 && Total_Buy < MaxOrders && reverse ) // sell Reverse order
            {
                  if (Total_SELL>0)CLOSEORDER(OP_SELL);
                  ticket_sell = OrderSendReliable(Symbol(),OP_BUY,Lots,ask,Slippage,0,0,"",Magic,0,clrGreen,loging);//OrderSend(Symbol(),OP_BUY,Lots,NormalizeDouble(Ask,Digits),Slippage,0,0,"",Magic,0,clrBlue);//OrderSendReliable(Symbol(),OP_BUY,Lots,ask,Slippage,0,0,"",Magic,0,clrGreen,loging);
                  
             
             }
            }
          }

Сейчас советник торгует вот таким макаром.. 

а нужно чтобы торговал вот так.. 
Yura Vakulenko
314
Yura Vakulenko  

а если написать вот так, то будет картина как ниже на рисунке и полный слив!)


if (!MartinTrade /*&& Indicator_use == 1*/) //No Martin Trade start
           {
           if(prevtime && buy_signal == 1 && !reverse )  //buy order
            {
                  if (Total_SELL>0) CLOSEORDER(OP_SELL);//Close_Orders(OP_SELL,loging);//CLOSEORDER(OP_SELL);
                  ticket_buy = OrderSendReliable(Symbol(),OP_BUY,Lots,ask,Slippage,0,0,"",Magic,0,clrGreen,loging); //OrderSend(Symbol(),OP_BUY,Lots,NormalizeDouble(Ask,Digits),Slippage,0,0,"",Magic,0,clrBlue);       
                  
             }
            
            if(prevtime && buy_signal == 1 && reverse )  //buy Reverse order
            {        
                  if (Total_Buy>0) CLOSEORDER(OP_BUY);
                  ticket_buy = OrderSendReliable(Symbol(),OP_SELL,Lots,bid,Slippage,0,0,"",Magic,0,clrRed,loging);//OrderSend(Symbol(),OP_SELL,Lots,NormalizeDouble(Bid,Digits),Slippage,0,0,"",Magic,0,clrRed);//OrderSendReliable(Symbol(),OP_SELL,Lots,bid,Slippage,0,0,"",Magic,0,clrRed,loging);
                  
                                
            }
            
           if(prevtime && sell_signal == 1  && !reverse ) // sell order
            {
                  if (Total_Buy>0) CLOSEORDER(OP_BUY);//Close_Orders(OP_BUY,loging);
                  ticket_sell = OrderSendReliable(Symbol(),OP_SELL,Lots,bid,Slippage,0,0,"",Magic,0,clrRed,loging);//OrderSend(Symbol(),OP_SELL,Lots,NormalizeDouble(Ask,Digits),Slippage,0,0,"",Magic,0,clrRed);//OrderSendReliable(Symbol(),OP_SELL,Lots,bid,Slippage,0,0,"",Magic,0,clrRed,loging);
                  
                          
            }
            if(prevtime && sell_signal == 1 && reverse ) // sell Reverse order
            {
                  if (Total_SELL>0)CLOSEORDER(OP_SELL);
                  ticket_sell = OrderSendReliable(Symbol(),OP_BUY,Lots,ask,Slippage,0,0,"",Magic,0,clrGreen,loging);//OrderSend(Symbol(),OP_BUY,Lots,NormalizeDouble(Ask,Digits),Slippage,0,0,"",Magic,0,clrBlue);//OrderSendReliable(Symbol(),OP_BUY,Lots,ask,Slippage,0,0,"",Magic,0,clrGreen,loging);
                  
             
             }
          }// end !MartinTrade
Andrey F. Zelinsky
32489
Andrey F. Zelinsky  

разбирайтесь с блоком сигнала -- может вы не так считываете стрелки.

кода индикатора нет.

такая запись:

if ( REVERSAL_Signal < Up_floor &&  REVERSAL_1 < Up_floor &&  REVERSAL_2 >= Up_floor /*&& REVERSAL_1_2 > Up_floor*/) {sell_signal =1; buy_signal=0;} 
if ( REVERSAL_Signal > Down_floor && REVERSAL_1 > Down_floor &&  REVERSAL_2 <= Down_floor /*&& REVERSAL_3_2 < Down_floor*/) {buy_signal=1; sell_signal =0; }

-- больше похожа на получение сигнала -- когда индикатор выше/ниже уровня Up_floor/Down_floor

-- т.е. в сигнале о стрелках речи не идёт. 

Yura Vakulenko
314
Yura Vakulenko  
да, там стрелки рисуются когда индикатор выходит из зон перепроданности\перекупленности. Отдельного буфера со стрелками в индикаторе нету. их рисует спец функция, как граф. объект. Давайте я вам в личику код индикатора скину. В общем, задача не сложная.. но не пойму в чем причина! поможете? спасибо!
Andrey F. Zelinsky
32489
Andrey F. Zelinsky  
сбросьте
Yura Vakulenko
314
Yura Vakulenko  

Друзья, кто может, помогите с кодом! Та совсем плевое дело!

нужно чтобы четко пос трелкам торговало! как на скринах.. это стрелочник.. нужно открывать серию ордеров в одном направлении (когда стрелка появляется..) и закрывать всю серию при против сигнале.. и при против сигнале открывать все четко по стрелочкам...  ну на скринах же четко все отметил как нужно) появилась крассная стрелка - открываем селл.. если снова появилась красная стрелка - снова селл открываем.. и  закрываем все селлы когда появится синяя стредка.. и в это же момент открываем бай.. и если снова синяя появилась - снова бай открывам..

и так до появления красной стрелки.. когда красная появилась - закрываем все бай и открываем снова селл.. лот фиксированный..)

ВОТ КАК НА РИСУНКАХ. https://c.mql5.com/3/58/EURUSDproM15_2_1.png

https://c.mql5.com/3/58/EURUSDproM150_1.png

А СЕЙЧАС ТОРГУЕТ ВОТ ТАК! https://c.mql5.com/3/58/EURUSDproM15_2_0.png

ВОТ КОД советника. Вам нужно обратить внимание только на условия открытия сделок для секции (ОНА ВЫДЕЛЕНА ЗЕЛЕНЫМ ЦВЕТОМ В ПОЛНОМ КОДЕ, что вы можете видеть ниже.) Отвечу на любые вопросы по существу. Спасибо! Подскажите...

if (MartinTrade )

Остальное все верно. Условия появления стрелок указаны верно. Индикатор скинуть не смогу. Он не нужен в данном случае.  На комментарии в коде советника не обращайте внимания.

//+------------------------------------------------------------------+
//|                                                 Reversal_exp.mq4 |
//|                                                 |
//|                                            |
//+------------------------------------------------------------------+
#include <stdlib.mqh>
#include <stderror.mqh>
#property copyright ""
#property link      ""
#property version   "1.00"
#property strict

extern double Lots                           = 0.1;
extern int    Slippage                       = 5;
extern int    Magic                          = 110011;
input bool    Without_Loss                   = false;
extern int    StepStopLoss                   = 5;
extern int    StepStopLossx                  = 25;
input bool    MartinTrade                    = false;
input bool    reverse                        = false;
extern double Multiplier                     = 1.228;
extern int    MaxOrders                      = 7;
extern string _                              = "Настройки индикатора";
extern string timeframe                      = "0";
input int     Main_Period                    = 264;
input int     Main_Price                     = 5;
input double  Down_floor                     = -280.0;
input double  Up_floor                       = 150.0;
input double  Length                         = 5.0;
input double  Phase                          = 100.0;
extern bool   loging                         = false;
extern bool   use_data_from_closed_candle    = true;
extern string __                             = "Настройки индикатора";
extern int     ATR_Period                    = 10;
extern double  Multipluer                    =1.7;
extern int     Indicator_use                 =1; // 1- Reversal; 2-VHT
extern int     alertsOn                      =false;

int Total_SELL,
    Total_Buy, total_orders,
    ticket,ticket_sell,ticket_buy,retries,
    sell_signal, buy_signal, M_sell_signal, M_buy_signal, M1_sell_signal, M1_buy_signal,vht_buy_signal,vht_sell_signal,
    _OR_err;
    
double ask,bid,price;

double  REVERSAL_Signal1,REVERSAL1_1_0,REVERSAL1_1_1,REVERSAL1_1_2,REVERSAL1_2_0,REVERSAL1_2_1,REVERSAL1_2_2,
        REVERSAL_Signal,
        REVERSAL_1,
        REVERSAL_2,
        REVERSAL_1_0,
        REVERSAL_1_1,
        REVERSAL_1_2,
        REVERSAL_3_0,
        REVERSAL_3_1,
        REVERSAL_3_2,
        REVERSAL_6_0,
        REVERSAL_6_1,
        REVERSAL_6_2;
        
string  osymbol,
        symbol,
        asymbolx;
        
datetime prevtime;
datetime previousSignal = 0;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   if(_Digits == 5 || _Digits == 3)
   {
      Slippage       *= 10;
      StepStopLoss   *= 10;
      StepStopLossx  *= 10;
   }
   
   prevtime = Time[0];
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   Comment("");
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
//работа по открытию бара
 if(use_data_from_closed_candle)
 {
   if (Time[0] == prevtime) return;
   prevtime = Time[0];
 }


//REVERSAL_Signal = iCustom(NULL,0,"REVERSAL",timeframe,Main_Period,Main_Price,Down_floor,Up_floor,Length,Phase,0,0);
REVERSAL_1 =      iCustom(NULL,0,"REVERSAL_2",timeframe,Main_Period,Main_Price,Down_floor,Up_floor,Length,Phase,7,1);
REVERSAL_2 =      iCustom(NULL,0,"REVERSAL_2",timeframe,Main_Period,Main_Price,Down_floor,Up_floor,Length,Phase,7,2);
//REVERSAL_1_0 =      iCustom(NULL,0,"REVERSAL",timeframe,Main_Period,Main_Price,Down_floor,Up_floor,Length,Phase,1,0);
//REVERSAL_1_1 =      iCustom(NULL,0,"REVERSAL",timeframe,Main_Period,Main_Price,Down_floor,Up_floor,Length,Phase,1,1);
//REVERSAL_1_2 =      iCustom(NULL,0,"REVERSAL",timeframe,Main_Period,Main_Price,Down_floor,Up_floor,Length,Phase,1,2);
/*REVERSAL_Signal1 = iCustom(NULL,0,"VHT","-",ATR_Period,Multipluer,0,0);
REVERSAL1_1_0 =      iCustom(NULL,0,"VHT","-",ATR_Period,Multipluer,"",Blue,Red,Blue,Red,Green,2,2,1,"",alertsOn,1,0);
REVERSAL1_1_1 =      iCustom(NULL,0,"VHT","-",ATR_Period,Multipluer,"",Blue,Red,Blue,Red,Green,2,2,1,"",alertsOn,1,1);
REVERSAL1_1_2 =      iCustom(NULL,0,"VHT","-",ATR_Period,Multipluer,"",Blue,Red,Blue,Red,Green,2,2,1,"",alertsOn,1,2);
REVERSAL1_2_0 =      iCustom(NULL,0,"VHT","-",ATR_Period,Multipluer,"",Blue,Red,Blue,Red,Green,2,2,1,"",alertsOn,2,0);
REVERSAL1_2_1 =      iCustom(NULL,0,"VHT","-",ATR_Period,Multipluer,"",Blue,Red,Blue,Red,Green,2,2,1,"",alertsOn,2,1);
REVERSAL1_2_2 =      iCustom(NULL,0,"VHT","-",ATR_Period,Multipluer,"",Blue,Red,Blue,Red,Green,2,2,1,"",alertsOn,2,2); */
//REVERSAL_3_0 =      iCustom(NULL,0,"REVERSAL",timeframe,Main_Period,Main_Price,Down_floor,Up_floor,Length,Phase,3,0);
//REVERSAL_3_1 =      iCustom(NULL,0,"REVERSAL",timeframe,Main_Period,Main_Price,Down_floor,Up_floor,Length,Phase,3,1);
//REVERSAL_3_2 =      iCustom(NULL,0,"REVERSAL",timeframe,Main_Period,Main_Price,Down_floor,Up_floor,Length,Phase,3,2);
//REVERSAL_6_0 =      iCustom(NULL,0,"REVERSAL",timeframe,Main_Period,Main_Price,Down_floor,Up_floor,Length,Phase,6,0);
//REVERSAL_6_1 =      iCustom(NULL,0,"REVERSAL",timeframe,Main_Period,Main_Price,Down_floor,Up_floor,Length,Phase,6,1);
//REVERSAL_6_2 =      iCustom(NULL,0,"REVERSAL",timeframe,Main_Period,Main_Price,Down_floor,Up_floor,Length,Phase,6,2);


ask = NormalizeDouble (MarketInfo(Symbol(),MODE_ASK), Digits);
bid = NormalizeDouble (MarketInfo(Symbol(),MODE_BID), Digits);
_OR_err = GetLastError();

Total_SELL = CountTrades(OP_SELL);
Total_Buy = CountTrades(OP_BUY);
total_orders = OrdersTotal();

      
if ( REVERSAL_1 == 1 && REVERSAL_2 == EMPTY_VALUE) {sell_signal =1; buy_signal=0;} 
if ( REVERSAL_1 == -1 && REVERSAL_2 == EMPTY_VALUE) {buy_signal=1; sell_signal =0; }

//if (REVERSAL1_1_0 ==EMPTY_VALUE && REVERSAL1_1_1 ==EMPTY_VALUE && REVERSAL1_2_1 != EMPTY_VALUE && REVERSAL1_1_2 == REVERSAL1_2_2) {vht_buy_signal=1; vht_sell_signal =0;}
//if (REVERSAL1_1_0 ==EMPTY_VALUE && REVERSAL1_2_1 ==EMPTY_VALUE && REVERSAL1_1_1 != EMPTY_VALUE && REVERSAL1_1_2 == REVERSAL1_2_2) {vht_sell_signal=1; vht_buy_signal =0;}
//if (REVERSAL_1_0 == EMPTY_VALUE && REVERSAL_1_1 == EMPTY_VALUE && REVERSAL_1_2 > Up_floor && REVERSAL_Signal < Up_floor ) {M_sell_signal =1; M_buy_signal=0;} 
//if (REVERSAL_3_0 == EMPTY_VALUE && REVERSAL_3_1 == EMPTY_VALUE && REVERSAL_3_2 < Down_floor && REVERSAL_Signal > Down_floor ) {M_buy_signal=1; M_sell_signal =0; } 

//if (REVERSAL_6_2 ==1 && REVERSAL_6_1 ==0 && REVERSAL_6_0 ==0 ) {M1_sell_signal =1; M1_buy_signal=0;} 
//if (REVERSAL_6_2 ==-1 && REVERSAL_6_1 ==0 && REVERSAL_6_0 ==0 ) {M1_buy_signal=1; M1_sell_signal =0; } 
//if(prevtime && sell_signal == 1 ) Close_Orders(OP_BUY,loging);
//if(prevtime && buy_signal == 1)  Close_Orders(OP_SELL,loging);

          /* if (!MartinTrade && Indicator_use == 2) //No Martin Trade start
           {
           if(prevtime && vht_buy_signal == 1 && Total_Buy==0 && !reverse )  //buy order
            {
                  if (Total_SELL>0) CLOSEORDER(OP_SELL);//Close_Orders(OP_SELL,loging);//CLOSEORDER(OP_SELL);
                  ticket_buy = OrderSendReliable(Symbol(),OP_BUY,Lots,ask,Slippage,0,0,"",Magic,0,clrGreen,loging); //OrderSend(Symbol(),OP_BUY,Lots,NormalizeDouble(Ask,Digits),Slippage,0,0,"",Magic,0,clrBlue);       
             }
            
            if(prevtime && vht_buy_signal == 1 && Total_SELL==0 && reverse )  //buy Reverse order
            {        
                  if (Total_Buy>0) CLOSEORDER(OP_BUY);
                  ticket_buy = OrderSendReliable(Symbol(),OP_SELL,Lots,bid,Slippage,0,0,"",Magic,0,clrRed,loging);//OrderSend(Symbol(),OP_SELL,Lots,NormalizeDouble(Bid,Digits),Slippage,0,0,"",Magic,0,clrRed);//OrderSendReliable(Symbol(),OP_SELL,Lots,bid,Slippage,0,0,"",Magic,0,clrRed,loging);
                                
            }
            
           if(prevtime && vht_sell_signal == 1 && Total_SELL==0 && !reverse ) // sell order
            {
                  if (Total_Buy>0) CLOSEORDER(OP_BUY);//Close_Orders(OP_BUY,loging);
                  ticket_sell = OrderSendReliable(Symbol(),OP_SELL,Lots,bid,Slippage,0,0,"",Magic,0,clrRed,loging);//OrderSend(Symbol(),OP_SELL,Lots,NormalizeDouble(Ask,Digits),Slippage,0,0,"",Magic,0,clrRed);//OrderSendReliable(Symbol(),OP_SELL,Lots,bid,Slippage,0,0,"",Magic,0,clrRed,loging);
                          
            }
            if(prevtime && vht_sell_signal == 1 && Total_Buy==0 && reverse ) // sell Reverse order
            {
                  if (Total_SELL>0)CLOSEORDER(OP_SELL);
                  ticket_sell = OrderSendReliable(Symbol(),OP_BUY,Lots,ask,Slippage,0,0,"",Magic,0,clrGreen,loging);//OrderSend(Symbol(),OP_BUY,Lots,NormalizeDouble(Ask,Digits),Slippage,0,0,"",Magic,0,clrBlue);//OrderSendReliable(Symbol(),OP_BUY,Lots,ask,Slippage,0,0,"",Magic,0,clrGreen,loging);
             
             }
          }*/// end !MartinTrade
           
           if (!MartinTrade /*&& Indicator_use == 1*/) //No Martin Trade start
           {
           if(prevtime && buy_signal == 1 && Total_Buy==0 && !reverse )  //buy order
            {
                  if (Total_SELL>0) CLOSEORDER(OP_SELL);//Close_Orders(OP_SELL,loging);//CLOSEORDER(OP_SELL);
                  ticket_buy = OrderSendReliable(Symbol(),OP_BUY,Lots,ask,Slippage,0,0,"",Magic,0,clrGreen,loging); //OrderSend(Symbol(),OP_BUY,Lots,NormalizeDouble(Ask,Digits),Slippage,0,0,"",Magic,0,clrBlue);       
                  
             }
            
            if(prevtime && buy_signal == 1 && Total_SELL==0 && reverse )  //buy Reverse order
            {        
                  if (Total_Buy>0) CLOSEORDER(OP_BUY);
                  ticket_buy = OrderSendReliable(Symbol(),OP_SELL,Lots,bid,Slippage,0,0,"",Magic,0,clrRed,loging);//OrderSend(Symbol(),OP_SELL,Lots,NormalizeDouble(Bid,Digits),Slippage,0,0,"",Magic,0,clrRed);//OrderSendReliable(Symbol(),OP_SELL,Lots,bid,Slippage,0,0,"",Magic,0,clrRed,loging);
                  
                                
            }
            
           if(prevtime && sell_signal == 1 && Total_SELL==0 && !reverse ) // sell order
            {
                  if (Total_Buy>0) CLOSEORDER(OP_BUY);//Close_Orders(OP_BUY,loging);
                  ticket_sell = OrderSendReliable(Symbol(),OP_SELL,Lots,bid,Slippage,0,0,"",Magic,0,clrRed,loging);//OrderSend(Symbol(),OP_SELL,Lots,NormalizeDouble(Ask,Digits),Slippage,0,0,"",Magic,0,clrRed);//OrderSendReliable(Symbol(),OP_SELL,Lots,bid,Slippage,0,0,"",Magic,0,clrRed,loging);
                  
                          
            }
            if(prevtime && sell_signal == 1 && Total_Buy==0 && reverse ) // sell Reverse order
            {
                  if (Total_SELL>0)CLOSEORDER(OP_SELL);
                  ticket_sell = OrderSendReliable(Symbol(),OP_BUY,Lots,ask,Slippage,0,0,"",Magic,0,clrGreen,loging);//OrderSend(Symbol(),OP_BUY,Lots,NormalizeDouble(Ask,Digits),Slippage,0,0,"",Magic,0,clrBlue);//OrderSendReliable(Symbol(),OP_BUY,Lots,ask,Slippage,0,0,"",Magic,0,clrGreen,loging);
                  
             
             }
          }// end !MartinTrade
          
          else // Martin trade start
          {
            if (MartinTrade )
            {
            
            
            //for(int counter=0;counter<MaxOrders;counter++)
            //{  
            
            if(prevtime && buy_signal == 1 && Total_Buy < MaxOrders && !reverse )  //buy order
            {
                  if (Total_SELL>0) CLOSEORDER(OP_SELL);//Close_Orders(OP_SELL,loging);//CLOSEORDER(OP_SELL);
                  ticket_buy = OrderSendReliable(Symbol(),OP_BUY,Lots,ask,Slippage,0,0,"",Magic,0,clrGreen,loging); //OrderSend(Symbol(),OP_BUY,Lots,NormalizeDouble(Ask,Digits),Slippage,0,0,"",Magic,0,clrBlue);       
                  
             }
            
            if(prevtime && buy_signal == 1 &&  Total_SELL < MaxOrders && reverse )  //buy Reverse order
            {        
                  if (Total_Buy>0) CLOSEORDER(OP_BUY);
                  ticket_buy = OrderSendReliable(Symbol(),OP_SELL,Lots,bid,Slippage,0,0,"",Magic,0,clrRed,loging);//OrderSend(Symbol(),OP_SELL,Lots,NormalizeDouble(Bid,Digits),Slippage,0,0,"",Magic,0,clrRed);//OrderSendReliable(Symbol(),OP_SELL,Lots,bid,Slippage,0,0,"",Magic,0,clrRed,loging);
                  
                                
            }
            
           if(prevtime && sell_signal == 1  && Total_SELL < MaxOrders && !reverse ) // sell order
            {
                  if (Total_Buy>0) CLOSEORDER(OP_BUY);//Close_Orders(OP_BUY,loging);
                  ticket_sell = OrderSendReliable(Symbol(),OP_SELL,Lots,bid,Slippage,0,0,"",Magic,0,clrRed,loging);//OrderSend(Symbol(),OP_SELL,Lots,NormalizeDouble(Ask,Digits),Slippage,0,0,"",Magic,0,clrRed);//OrderSendReliable(Symbol(),OP_SELL,Lots,bid,Slippage,0,0,"",Magic,0,clrRed,loging);
                  
                          
            }
            if(prevtime && sell_signal == 1 && Total_Buy < MaxOrders && reverse ) // sell Reverse order
            {
                  if (Total_SELL>0)CLOSEORDER(OP_SELL);
                  ticket_sell = OrderSendReliable(Symbol(),OP_BUY,Lots,ask,Slippage,0,0,"",Magic,0,clrGreen,loging);//OrderSend(Symbol(),OP_BUY,Lots,NormalizeDouble(Ask,Digits),Slippage,0,0,"",Magic,0,clrBlue);//OrderSendReliable(Symbol(),OP_BUY,Lots,ask,Slippage,0,0,"",Magic,0,clrGreen,loging);
                  
             
             }
             
            //} //end FOR
            }
          }
           
           
           
   
  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
int CountTrades( int otype)
{
   int count = 0;
   for(int i=OrdersTotal()-1; i >= 0; i--)
   {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
      {
      if(OrderType() == OP_BUY || OrderType() == OP_SELL)
      {
      if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == otype)     
      count++;
    }
   }
  }
 
return(count);
}

//---------------------------------------
void Close_Orders(int otype, bool loging_b) 
{


   for (int pos_0 = OrdersTotal() - 1; pos_0 >= 0; pos_0--) 
   {
      if(OrderSelect(pos_0, SELECT_BY_POS, MODE_TRADES))
      {
       if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == otype) 
         {
         if(OrderType() == OP_BUY || OrderType() == OP_SELL)
         {
            if (OrderType() == OP_BUY) if(OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, clrBlue))
            if (loging_b)
            {Print("Ошибка закрытия ордера "+IntegerToString(_OR_err));}
            if (OrderType() == OP_SELL) if(OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, clrRed))
            if (loging_b) 
             {Print("Ошибка закрытия ордера "+IntegerToString(_OR_err));}
            }
           }
           Sleep(1000);
        }
     }
   }
//--------------------------------------------------------------------
void CLOSEORDER(int ord)
{
   for (int i=0; i<OrdersTotal(); i++)
   {                                               
      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
      {
         if (OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
         {
            if (OrderType()==OP_BUY && ord==OP_BUY)
               OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),Slippage,CLR_NONE);
            if (OrderType()==OP_SELL && ord==OP_SELL)
               OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),Slippage,CLR_NONE);
         }
      }   
   }
}

//================================================================================++
  int OrderSendReliable(string osymbolx, int cmd, double volume, double aprice,
                 int slippage, double stoploss, double takeprofit,
                 string acomment, int magic, datetime expiration = 0, 
                 color arrow_color = CLR_NONE, bool logining_s = false) 
{
   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()) 
         {
       
      // Comment(asymbol,"\n",cmd,"\n",volume,"\n",aprice,"\n",slippage,"\n",stoploss,"\n",takeprofit,"\n",acomment,"\n",magic);
       
            ticket = OrderSend(osymbol, 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 && logining_s) 
            {
               Print("Ошибка : " + IntegerToString(err)); 
            }
         }
      }
      
      if (err == ERR_NO_ERROR && logining_s) 
      {
         if(OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES)) 
         return(ticket);
      } 
      if (logining_s)
      {
      Print("Ошибка открытия ордера после " + IntegerToString(cnt) + " попыток."+" по символу "+OrderSymbol());
      Print("Ошибка : " + IntegerToString(err));
      } 
      return(-1); 
   }
   return(-1);
}
//+------------------------------------------------------------------+
Andrey F. Zelinsky
32489
Andrey F. Zelinsky  

добавьте:

sell_signal =0; buy_signal=0;      
if ( REVERSAL_1 == 1 && REVERSAL_2 == EMPTY_VALUE) {sell_signal =1; buy_signal=0;} 
if ( REVERSAL_1 == -1 && REVERSAL_2 == EMPTY_VALUE) {buy_signal=1; sell_signal =0; }

-- а то у вас эти переменные объявлены глобально (лучше объявить их локально) -- и по первому сигналу они установились, например:

sell_signal =1; buy_signal=0;

-- а дальше -- сигнала нет, а их значения не меняются -- вплоть до противоположного сигнала

Yura Vakulenko
314
Yura Vakulenko  
Огромное спасибо, Андрей!! Все работает как нужно!! теперь буду делать мартин для ордеров...
Vladimir Karputov
Модератор
58926
Vladimir Karputov  

Форум по трейдингу, автоматическим торговым системам и тестированию торговых стратегий

Вопросы от начинающих

YuraVakulenko, 2015.02.22 15:37

а как к моему советнику функцию мартина прикрутить?? желательно мартин для прибыльных сделак, а не для убыточных!! можете посоветовать неплохие функции?

12
Авторизуйтесь или зарегистрируйтесь, чтобы добавить комментарий