Una pregunta para los expertos en MQL - página 2

 
primavera
 
Chicos, muchas gracias a todos, veré lo que me queda. Primavera ....
 

Pido disculpas por la pregunta posiblemente incorrecta.

Actualmente estoy tratando con el código descompilado de EA. No puedo "meterme" en un trozo de código.

//-----------------------------------------------------------      
int TotalSell() {  int count=0;
   for (int i=0; i<OrdersTotal(); i++) {
      if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) break;
      if (OrderSymbol()!=Symbol()) continue;
      if (OrderType()==OP_SELL) count++;}return (count);}
//------------------------------------------------------------      
int TotalSellStop() { int count=0;
   for (int i=0; i<OrdersTotal(); i++){
      if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) break;
      if (OrderSymbol()!=Symbol()) continue;
      if (OrderType()==OP_SELLSTOP) count++;} return (count);}
//-------------------------------------------------------------------

Por favor, decodifique (en ruso) línea por línea esta oscura construcción (superior o inferior) para mí?

En general, el "concepto" de este Asesor Experto, lo entendí. Inicialmente, se establecen dos órdenes pendientes - Buy Stop y Sell Stop. Cuando cualquiera de las órdenes pendientes se dispara, la segunda se elimina. ¡Pero, al mismo tiempo, se establece un trailing stop en la posición abierta y se fija el trailing stop-loss opuesto en lugar del precio del stop-loss!

 
//-----------------------------------------------------------      
int TotalSell() {  int count=0;                                    //Функция возвращающая количество устаноавленныых SELL ордеров 
   for (int i=0; i<OrdersTotal(); i++) {                           //задается цикл от ноля до общего количества всех ордеров 
      if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) break;        //Выбирается ордер по позиции из списка, если не выбран - выход
      if (OrderSymbol()!=Symbol()) continue;                       //Сравнивается по символу, если соответствует - продолжить 
      if (OrderType()==OP_SELL) count++;}return (count);}          //Сравнивается по типу SELL, если соответствует то увеличивает счетчик ордеров на 1
//------------------------------------------------------------      
int TotalSellStop() { int count=0;                                 //Тоже что и предидущая функция но для SELLSTOP ордеров
   for (int i=0; i<OrdersTotal(); i++){
      if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) break;
      if (OrderSymbol()!=Symbol()) continue;
      if (OrderType()==OP_SELLSTOP) count++;} return (count);}
//-------------------------------------------------------------------

Eso es todo.

 
¡Gracias, xeon!
 

Buenas noches a todos. Ha surgido una necesidad.

Para utilizar un script que invierta las posiciones abiertas.

Para mi sorpresa, descubrí que el script no funciona por alguna razón. Traté de entenderlo, pero .... No funciona.

Y allí, al parecer, - demasiado ingenioso autor consiguió el diseño ..., insertado comentarios acompañantes imbéciles.

/ Развернуть все ордера.mq4
// Скрипт
#property copyright "mandorr@gmail.com"
#include <WinUser32.mqh>
void start()
{
   int i=0, count=0;
   //закладываем массивы значений
   int cmd[];
   int ticket[];
   double lots[];
   string symbol[];
   string type[];
//------------------------------------------------------------   
   for (i=0; i<OrdersTotal(); i++)           {
      if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) break;
      if (OrderType()==OP_BUY || OrderType()==OP_SELL)      {
         ArrayResize(cmd,count+1); 
         ArrayResize(ticket,count+1); 
         ArrayResize(lots,count+1); 
         ArrayResize(symbol,count+1); 
         ArrayResize(type,count+1); 
         cmd[count]=OrderType();
         ticket[count]=OrderTicket();
         lots[count]=OrderLots();
         symbol[count]=OrderSymbol();
         if (OrderType()==OP_BUY) type[count]="Buy";//если открыта длинная позиция
         // заносим её в массив "Buy"
         else type[count]="Sell";// иначе в массив "Sell"
         count++;                                            }
   }
//---------------------------------------------------------------   
   string space="    ";
   string title="Кароче_В_натуре";
   string msg="Развернуть:"+"\n";
   for (i=0; i<count; i++) msg=msg+"\n"+"Order "+ticket[i]+" "+type[i]+" "+DoubleToStr(lots[i],1)+" Lots "+symbol[i]+space;
   if (MessageBox(msg,title,MB_YESNO|MB_ICONQUESTION)!=IDYES)
   {
      title="Аха";
      string ends=""; if (count>1) ends="и";
      msg="Ну и хрен с ним"+ends+" ...    "; 
      MessageBox(msg,title,MB_OK|MB_ICONEXCLAMATION);
      return;
   }
   for (i=0; i<count; i++)
   {
      if(!OrderSelect(ticket[i],SELECT_BY_TICKET)) continue;
      double ask=MarketInfo(symbol[i],MODE_ASK);
      double bid=MarketInfo(symbol[i],MODE_BID);
      int slippage=3;
      if (cmd[i]==OP_BUY )
      {
         OrderClose(ticket[i],lots[i],bid,slippage);
         OrderSend(symbol[i],OP_SELL,lots[i],bid,slippage,0,0,NULL,0,0);
      }
      if (cmd[i]==OP_SELL)
      {
         OrderClose(ticket[i],lots[i],ask,slippage);
         OrderSend(symbol[i],OP_BUY ,lots[i],ask,slippage,0,0,NULL,0,0);
      }
   }
}
// End
Por favor, ¿puede decirme por qué no funciona?
 
// Развернуть все ордера.mq4
Es raro que todo funcione solo que no sería malo hacerlo así :
 

Esa no es la cuestión. Puse el script en el gráfico (Alpari demo). Pulso el botón "SÍ" en la ventana que aparece, pero no ocurre nada. Las posiciones no se invierten. En el libro de registro en el momento de pulsar

2008.04.29 01:15:41 Script Revers__all_orders EURJPY,M15: eliminado

 

Buenas tardes. Por favor, escriba una expresión iCustom para este indicador:



Este es su código -

#property indicator_chart_window
#property indicator_buffers 2

//---- input parameters
extern int R=3;
//---- buffers
double HighBuffer[];
double LowBuffer[];
double VALUE1,VALUE2,VALUE11,VALUE22;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
//---- indicator line
   SetIndexStyle(0,DRAW_ARROW,EMPTY,1,Blue);
   SetIndexStyle(1,DRAW_ARROW,EMPTY,1,Yellow);
   SetIndexArrow(0, 0x9F);
   SetIndexArrow(1, 0x9F);

   SetIndexBuffer(0,HighBuffer);
   SetIndexBuffer(1,LowBuffer);

   SetIndexEmptyValue(0,0);
   SetIndexEmptyValue(1,0);
//---- name for DataWindow and indicator subwindow label
   short_name="HiLo";
   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);
//----
   SetIndexDrawBegin(0,10);
   SetIndexDrawBegin(1,10);
//----
   return(0);
  }
//+-----------------------------------------------------+
int deinit()
  {
//---- TODO: add your code here
ObjectsDeleteAll(0);   
//----
   return(0);
  }
//+-------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted(),i,shift,Swing;   

//---- TODO: add your code here
i=(Bars-counted_bars)-1;

for (shift=i; shift>=0;shift--)  {

VALUE1=iMA(NULL,0,R,0,MODE_SMA,PRICE_HIGH,shift+1);
VALUE2=iMA(NULL,0,R,0,MODE_SMA,PRICE_LOW,shift+1);

if (Close[shift+1]<VALUE2 ) Swing=-1;
if (Close[shift+1]>VALUE1 ) Swing=1;

if (Swing==1) { HighBuffer[shift]=VALUE2; LowBuffer[shift]=0;  }
if (Swing==-1) { LowBuffer[shift]=VALUE1; HighBuffer[shift]=0; }
//----
}
   return(0);
  }
Para poder establecer el parámetro R en las "propiedades" y el número de barra, por supuesto.
 

Sí, algo así, si se tiene en cuenta que el nombre del indicador es hilo.mq4:

extern int iR=3;
extern int SignalBar=1;
//.......
//---получение значения HighBuffer
double buy = iCustom( NULL,0, "hilo",
iR,
0, // № буффера
SignalBar ); // № бара

//---получение значения LowBuffer
double sell = iCustom( NULL,0, "hilo",
iR,
1, // № буффера
SignalBar ); // № бара