Redactaré un asesor de forma gratuita - página 85

 
Evgenij Litvintsev:

Buenas tardes, quizás alguien esté interesado en automatizar mi estrategia. Ahora funciona, pero en modo semiautomático, me gustaría automatizarlo.


¿Puedo ver los resultados de las operaciones?

 

Buenas noches, podríais aconsejarme cómo obtener una orden de entradas, un lote y un beneficio a partir de una función:

double OldTicketSell()// Encuentra la orden de venta más lejana

{
double MaxDist=0,oldprofit,lot;
int ticket=0;
double BID=MarketInfo(Symbol(),MODE_BID);
double ASK=MarketInfo(Symbol(),MODE_ASK);
for(int i=TotalPedidos()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderType()==OP_SELL && MaxDist<MathAbs(OrderOpenPrice()-ASK))
{
MaxDist=MathAbs(OrderOpenPrice()-ASK);
ticket=OrderTicket();
oldprofit = OrderProfit();
lote = OrderLots();
}
}
}
return(ticket);

}

La función es clara, no está claro cómo sacar los datos encontrados, o es necesario copiarlos bajo lote y beneficio.


 
Николай:

Buenas noches, me podrían decir cómo obtener las órdenes de entradas, el lote y el beneficio de una función.

La función es comprensible, no está claro cómo sacar los datos encontrados de ella, o debo copiarlos bajo lote y beneficio.

Podríamos hacerlo así

struct InfoOrder
{
     int ticket;
     double lot,
            profit,
            swap,
            commission,
            sl, tp;
     datetime timeOpen;
     string comment;
} infoOrder;

void OldSell(void)// Находим самый дальний ордер на продажу
{
   double MaxDist=0;
   double BID=MarketInfo(Symbol(),MODE_BID);
   double ASK=MarketInfo(Symbol(),MODE_ASK);
   for(int i=OrdersTotal()-1; i>=0; i--)
   {
   if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
      {
        if(OrderType()==OP_SELL && MaxDist<MathAbs(OrderOpenPrice()-ASK))
         {
             MaxDist=MathAbs(OrderOpenPrice()-ASK);
             infoOrder.ticket=OrderTicket();
             infoOrder.profit = OrderProfit();
             infoOrder.lot = OrderLots();
         }
      }
   }
   return; 
}
 
Konstantin Nikitin:

Puedes ir así

Todo esto está bien, pero soy un tonto, estoy tratando de escribir un EA en la medida de mis conocimientos (apenas aprendí un poco), entiendo que la variable es una estructura, pero cómo sacar los datos de esta estructura no está claro. Por ejemplo, si hemos encontrado la orden más lejana, entonces el beneficio debe ser dividido por el lote y obtenemos el número de puntos desde el precio actual hasta ese lote. Entonces obtenemos el beneficio de una orden contraria (sé cómo obtenerlo), lo dividimos por el número de puntos de la orden contraria calculado anteriormente, obtenemos el número de lotes y utilizamos este número de lotes para cerrar total o parcialmente la orden lejana encontrada.
 
Konstantin Nikitin:

Podríamos hacerlo así

También me gustaría preguntar si es posible encontrar la orden más alejada del precio comparando los precios de apertura de las órdenes en el ciclo, creo que sería aún más fácil?

 
Николай:

También me gustaría preguntar si es posible encontrar la orden más alejada del precio comparando los precios de apertura de las órdenes en el ciclo, creo que sería aún más fácil?

Por supuesto que sí. Y que sea más fácil o no depende de lo que necesites.
Este es un ejemplo de su pregunta anterior.

struct InfoOrder
{
     int ticket;
     double lot,
            profit,
            swap,
            commission,
            sl, tp;
     datetime timeOpen;
     string comment;
} infoOrder;

void OnTick()
{
     OldSell();
     Print("Ticket: ", infoOrder.ticket);
     Print("Profit: ", infoOrder.profit);
     Print("Lot: ", infoOrder.lot);
     Print("-----=====-----");
     
     return;
}

void OldSell(void)// Находим самый дальний ордер на продажу
{
   double MaxDist=0;
   double BID=MarketInfo(Symbol(),MODE_BID);
   double ASK=MarketInfo(Symbol(),MODE_ASK);
   for(int i=OrdersTotal()-1; i>=0; i--)
   {
   if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
      {
        if(OrderType()==OP_SELL && MaxDist<MathAbs(OrderOpenPrice()-ASK))
         {
             MaxDist=MathAbs(OrderOpenPrice()-ASK);
             infoOrder.ticket=OrderTicket();
             infoOrder.profit = OrderProfit();
             infoOrder.lot = OrderLots();
         }
      }
   }
   return; 
}
 
Konstantin Nikitin:

Por supuesto que sí. Que sea más fácil o no depende de lo que necesites.
Y un ejemplo a su pregunta anterior.

Viendo todo esto, me doy cuenta de que soy un tipster. Así, elresultado de lafunciónvoid OldSell(void)se escribe en la estructuraInfoOrder y luego se pueden utilizar las variables infoOrder.ticket,infoOrder.profit,infoOrder.lot.
//-Структура для нахождения самого дальнего ордера на продажу
struct InfoOrder
{
     int ticket;
     double lot,
            profit,
            swap,
            commission,
            sl, tp;
     datetime timeOpen;
     string comment;
} infoOrder;

void OnTick()
{
     OldSell();
     Print("Ticketbuy: ", infoOrder.ticket);
     Print("Profitbuy: ", infoOrder.profit);
     Print("Lotbuy: ", infoOrder.lot);
     Print("Ticketsell: ", infoOrder.ticket);
     Print("Profitsell: ", infoOrder.profit);
     Print("Lotsell: ", infoOrder.lot);
     Print("-----=====-----");
     
     return;
}

void OldSell(void)// Находим самый дальний ордер на продажу
{
   double MaxDist=0;
   double BID=MarketInfo(Symbol(),MODE_BID);
   double ASK=MarketInfo(Symbol(),MODE_ASK);
   for(int i=OrdersTotal()-1; i>=0; i--)
   {
   if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
      {
         if(OrderType()==OP_BUY && MaxDist<MathAbs(OrderOpenPrice()-BID))
          {
             MaxDist=MathAbs(OrderOpenPrice()-BID);
             infoOrder.ticketbuy=OrderTicket();
             infoOrder.profitbuy = OrderProfit();
             infoOrder.lotbuy = OrderLots();
           }  
             
        if(OrderType()==OP_SELL && MaxDist<MathAbs(OrderOpenPrice()-ASK))
          {
             MaxDist=MathAbs(OrderOpenPrice()-ASK);
             infoOrder.ticketsell=OrderTicket();
             infoOrder.profitsell = OrderProfit();
             infoOrder.lotsell = OrderLots();
          }
      }
   }
   return; 
}


 
Konstantin Nikitin:

Por supuesto que sí. Que sea más fácil o no depende de lo que necesites.
Y un ejemplo a su pregunta anterior.

Olvidé cambiar las variables de impresión
 
Николай:
Viendo todo esto, me doy cuenta de lo tonta que soy. Así, elresultado de lafunciónvoid OldSell(void) se escribe en la estructuraInfoOrder y luego podemos utilizar infoOrder.ticket,infoOrder.profit,infoOrder.lot.He generalizado un poco la función, ¿es correcto o no?
//-Структура для нахождения самого дальнего ордера на продажу
struct InfoOrder
{
     int ticket;
     double lot,
            profit,
            swap,
            commission,
            sl, tp,
            MaxDist;
     datetime timeOpen;
     string comment;
} infoOrder;

void OnTick()
{
     if( OldOrder(OP_BUY) )
     {
        Print("Ticketbuy: ", infoOrder.ticket);
        Print("Profitbuy: ", infoOrder.profit);
        Print("Lotbuy: ", infoOrder.lot);
        Print("MaxDistbuy: ", infoOrder.MaxDist);
        Print("-----=====-----");
     }
     if( OldOrder(OP_SELL) )
     {
        Print("Ticketsell: ", infoOrder.ticket);
        Print("Profitsell: ", infoOrder.profit);
        Print("Lotsell: ", infoOrder.lot);
        Print("MaxDistsell: ", infoOrder.MaxDist);
        Print("-----=====-----");
     }
     
     return;
}

bool OldOrder(const int type)// Находим самый дальний ордер на продажу
{
   bool res = false;
   double MaxDist=0;
   double BID=MarketInfo(Symbol(),MODE_BID);
   double ASK=MarketInfo(Symbol(),MODE_ASK);
   for(int i=OrdersTotal()-1; i>=0; i--)
   {
   if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
      {
         switch(type)
           {
            case OP_BUY:
               if(OrderType()!=OP_BUY) break;
               if(MaxDist<=MathAbs(OrderOpenPrice()-BID)) break;
               infoOrder.MaxDist=MathAbs(OrderOpenPrice()-BID);
               infoOrder.ticket=OrderTicket();
               infoOrder.profit = OrderProfit();
               infoOrder.lot = OrderLots();
               res = true;
               break;
             
           case OP_SELL:
               if(OrderType()!=OP_SELL) break;
               if(MaxDist>=MathAbs(OrderOpenPrice()-ASK)) break;
               infoOrder.MaxDist=MathAbs(OrderOpenPrice()-ASK);
               infoOrder.ticket=OrderTicket();
               infoOrder.profit = OrderProfit();
               infoOrder.lot = OrderLots();
               res = true;
               break;
        }
      }
   }
   return res; 
}

Algo así.
 




encontrado esta estructura en el EA, ¿puede decirme qué define

struct TMartinData
{
   int    BUY_Positions;
   double BUY_LastPrice;
   double BUY_StopPrice;
   double BUY_Lots;
   datetime BUY_LastTime;
   bool   BUY_AllWD;
   int    SELL_Positions;
   double SELL_LastPrice;
   double SELL_StopPrice;
   double SELL_Lots;
   datetime SELL_LastTime;
   bool   SELL_AllWD;
} MartinData;

void OnTick()

void FillMartinData()
{
   datetime bfirst = TimeCurrent()+1;
   datetime blast = 0;
   datetime sfirst = TimeCurrent()+1;
   datetime slast = 0;
   MartinData.BUY_Positions = 0;
   MartinData.SELL_Positions = 0;
   MartinData.BUY_Lots = 0;
   MartinData.SELL_Lots = 0;
   MartinData.BUY_LastPrice = -1;
   MartinData.SELL_LastPrice = -1;
   MartinData.BUY_StopPrice = -1;
   MartinData.SELL_StopPrice = -1;
   MartinData.BUY_LastTime = 0;
   MartinData.SELL_LastTime = 0;
   MartinData.BUY_AllWD = true;
   MartinData.SELL_AllWD = true;
   for(int i=0;i<OrdersTotal();i++)
   {
     if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
     if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNum)
     {
        if (OrderType()==OP_BUY)
        {
           MartinData.BUY_Positions++;
           if (OrderOpenTime()<bfirst)
           {
              MartinData.BUY_Lots = OrderLots();
              MartinData.BUY_StopPrice = OrderStopLoss();
              bfirst = OrderOpenTime();
           }
           if (OrderOpenTime()>blast)
           {
              MartinData.BUY_LastPrice = OrderOpenPrice();
              blast = OrderOpenTime();
           }
           if (OrderStopLoss()<OrderOpenPrice())
              MartinData.BUY_AllWD = false;
        }
        else if (OrderType()==OP_SELL)
        {
           MartinData.SELL_Positions++;
           if (OrderOpenTime()<sfirst)
           {
              MartinData.SELL_Lots = OrderLots();
              MartinData.SELL_StopPrice = OrderStopLoss();
              sfirst = OrderOpenTime();
           }
           if (OrderOpenTime()>slast)
           {
              MartinData.SELL_LastPrice = OrderOpenPrice();
              slast = OrderOpenTime();
           }
           if ((OrderStopLoss()==0) || (OrderStopLoss()>OrderOpenPrice()))
              MartinData.SELL_AllWD = false;
        }
     }
   }
   MartinData.BUY_LastTime = blast;
   MartinData.SELL_LastTime = slast;
   if (MartinData.BUY_Positions==0) MartinData.BUY_AllWD = false;
   if (MartinData.SELL_Positions==0) MartinData.SELL_AllWD = false;
}


Razón de la queja: