Cualquier pregunta de los recién llegados sobre MQL4 y MQL5, ayuda y discusión sobre algoritmos y códigos - página 1371

 
MakarFX:

Hasta el fondo del EA.

Lamentablemente no se multiplica!!(((

 
Сергей Дыбленко:

Lamentablemente no se multiplica!!(((

Esta función calcula el lote en relación con el margen libre y el riesgo especificado.

¿De qué multiplicación estás hablando?

 
MakarFX:

Esta función calcula el lote en relación con el margen libre y el riesgo especificado.

¿De qué multiplicación estás hablando?

¡El aumento de los lotes después de cada beneficio!

 
Сергей Дыбленко:

¡sobre el aumento de los lotes después de cada ganancia!

Esta función aumentará el lote después de un beneficio, pero si el beneficio permite un aumento por el incremento mínimo del lote

 
Сергей Дыбленко:

¡sobre el aumento de los lotes después de cada ganancia!

aquí hay un ejemplo hasta 10 000 su saldo será lote 0.1 de 10 000 a 20 000 con lote 0.5

de 20 000 a 40 000 con lote 1.0 más de 40 000 con lote 2.0

//+------------------------------------------------------------------+
//|                                               Moving Average.mq4 |
//|                   Copyright 2005-2014, MetaQuotes Software Corp. |
//|                                              http://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright   "2005-2014, MetaQuotes Software Corp."
#property link        "http://www.mql4.com"
#property description "Moving Average sample expert advisor"

#define  MAGICMA  20131111
//--- Inputs
input double InpLots       =0.1;
input int    MovingPeriod  =12;
input int    MovingShift   =6;
//+------------------------------------------------------------------+
//| Calculate open positions                                         |
//+------------------------------------------------------------------+
int CalculateCurrentOrders(string symbol)
  {
   int buys=0,sells=0;
//---
   for(int i=0; i<OrdersTotal(); i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)
         break;
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
        {
         if(OrderType()==OP_BUY)
            buys++;
         if(OrderType()==OP_SELL)
            sells++;
        }
     }
//--- return orders volume
   if(buys>0)
      return(buys);
   else
      return(-sells);
  }
//+------------------------------------------------------------------+
//| Calculate optimal lot size                                       |
//+------------------------------------------------------------------+
double LotsOptimized()
  {
   double Lots=InpLots;
   double ab=AccountBalance();
   if(ab>=10000 && ab<20000)
      Lots=0.5;
   if(ab>=20000 && ab<40000)
      Lots=1.0;
   if(ab>=40000)
      Lots=2.0;
   return(Lots);
  }
//+------------------------------------------------------------------+
//| Check for open order conditions                                  |
//+------------------------------------------------------------------+
void CheckForOpen()
  {
   double ma;
   int    res;
//--- go trading only for first tiks of new bar
   if(Volume[0]>1)
      return;
//--- get Moving Average
   ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0);
//--- sell conditions
   if(Open[1]>ma && Close[1]<ma)
     {
      res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,0,0,"",MAGICMA,0,Red);
      return;
     }
//--- buy conditions
   if(Open[1]<ma && Close[1]>ma)
     {
      res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,0,0,"",MAGICMA,0,Blue);
      return;
     }
//---
  }
//+------------------------------------------------------------------+
//| Check for close order conditions                                 |
//+------------------------------------------------------------------+
void CheckForClose()
  {
   double ma;
//--- go trading only for first tiks of new bar
   if(Volume[0]>1)
      return;
//--- get Moving Average
   ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0);
//---
   for(int i=0; i<OrdersTotal(); i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)
         break;
      if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol())
         continue;
      //--- check order type
      if(OrderType()==OP_BUY)
        {
         if(Open[1]>ma && Close[1]<ma)
           {
            if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,White))
               Print("OrderClose error ",GetLastError());
           }
         break;
        }
      if(OrderType()==OP_SELL)
        {
         if(Open[1]<ma && Close[1]>ma)
           {
            if(!OrderClose(OrderTicket(),OrderLots(),Ask,3,White))
               Print("OrderClose error ",GetLastError());
           }
         break;
        }
     }
//---
  }
//+------------------------------------------------------------------+
//| OnTick function                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- check for history and trading
   if(Bars<100 || IsTradeAllowed()==false)
      return;
//--- calculate open orders by current symbol
   if(CalculateCurrentOrders(Symbol())==0)
      CheckForOpen();
   else
      CheckForClose();
//---
  }
//+------------------------------------------------------------------+
 
SanAlex:

aquí hay un ejemplo hasta 10 000 su saldo será lote 0.1 de 10 000 a 20 000 con lote 0.5

de 20 000 a 40 000 con 1.0 lote más de 40 000 con 2.0 lote

se trata de un incremento de lote fijo.

para mí, si el beneficio es mayor o igual a

 MarketInfo(Symbol(), MODE_MARGINREQUIRED)*MarketInfo(Symbol(), MODE_LOTSTEP)

aumentará el lote,

pero si no hay otras órdenes abiertas que utilicen margen.

 
MakarFX:

es un aumento fijo del lote.

En mi caso, si el beneficio es mayor o igual a

entonces habrá un aumento en el lote,

pero si no hay otras órdenes abiertas que utilicen margen.

Estaba engañando - si la posición es deficitaria aumentaría el lote

//+------------------------------------------------------------------+
//| Calculate optimal lot size                                       |
//+------------------------------------------------------------------+
double OptimizedBuy(void)
  {
   double PROFIT_BUY=0.00;
   for(int i=OrdersTotal()-1; i>=0; i--) // returns the number of open positions
     {
      if(OrderSelect(i,SELECT_BY_POS) && OrderSymbol()==Symbol())
        {
         if(OrderSymbol()==Symbol() && OrderType()==OP_BUY)
           {
            PROFIT_BUY=PROFIT_BUY+NormalizeDouble(OrderProfit(),2);
           }
        }
     }
   double Lots=InpLots;
   double ab=PROFIT_BUY;
   if(ab<-1 && ab>=-InpLots_01)
      Lots=InpLots1;
   if(ab<-InpLots_01 && ab>=-InpLots_02)
      Lots=InpLots2;
   if(ab<-InpLots_02 && ab>=-InpLots_03)
      Lots=InpLots3;
   if(ab<-InpLots_03)
      Lots=InpLots4;
//--- return trading volume
   return(Lots);
  }
//+------------------------------------------------------------------+
//| Calculate optimal lot size                                       |
//+------------------------------------------------------------------+
double OptimizedSell(void)
  {
   double PROFIT_SELL=0.00;
   for(int i=OrdersTotal()-1; i>=0; i--) // returns the number of open positions
     {
      if(OrderSelect(i,SELECT_BY_POS) && OrderSymbol()==Symbol())
        {
         if(OrderSymbol()==Symbol() && OrderType()==OP_SELL)
           {
            PROFIT_SELL=PROFIT_SELL+NormalizeDouble(OrderProfit(),2);
           }
        }
     }
   double Lots=InpLots;
   double ab=PROFIT_SELL;
   if(ab<-1 && ab>=-InpLots_01)
      Lots=InpLots1;
   if(ab<-InpLots_01 && ab>=-InpLots_02)
      Lots=InpLots2;
   if(ab<-InpLots_02 && ab>=-InpLots_03)
      Lots=InpLots3;
   if(ab<-InpLots_03)
      Lots=InpLots4;
//--- return trading volume
   return(Lots);
  }
//+------------------------------------------------------------------+
 
¡Gracias a todos por su ayuda PERO mis cerebros que no están no fueron suficientes para hacer lo que necesitaba!
 
Сергей Дыбленко:
Gracias a todos por su ayuda PERO mi cerebro no es suficiente para hacer lo que necesito.

Explica punto por punto lo que se necesita.

Cuántas órdenes en el trabajo, cuántos pares operan simultáneamente, cuáles son los riesgos por operación (si los hay)

Y algo más de ti)

 
SanAlex:

Aquí estaba engañando - si las posiciones son deficitarias el lote aumentaría

Sasha lo retocó un poco para aumentar el lote por las probabilidades

input double factor=1.05;        // коофициент умножения
//+------------------------------------------------------------------+
//| Calculate optimal lot size                                       |
//+------------------------------------------------------------------+
double OptimizedSell(void)
  {
   double Lots       =0.00;
   double PROFIT_BUY =0.00;
   double LOT_BUY    =0.00;
   double PROFIT_SELL=0.00;
   double LOT_SELL   =0.00;
   for(int i=OrdersTotal()-1; i>=0; i--) // returns the number of open positions
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true)
        {
         if(OrderSymbol()==Symbol())
           {
            if(OrderType()==OP_BUY)
              {
               PROFIT_BUY=PROFIT_BUY+NormalizeDouble(OrderProfit(),2);
               LOT_BUY   =LOT_BUY+NormalizeDouble(OrderLots(),2);
              }
            if(OrderType()==OP_SELL)
              {
               PROFIT_SELL=PROFIT_SELL+NormalizeDouble(OrderProfit(),2);
               LOT_SELL   =LOT_SELL+NormalizeDouble(OrderLots(),2);
              }
           }
        }
     }
   if(PROFIT_BUY<0)
      Lots=LOT_BUY*factor;
      else Lots=LOT_BUY;
   if(PROFIT_SELL<0)
      Lots=LOT_SELL*factor;
      else Lots=LOT_SELL;
//--- return trading volume
   return(Lots);
  }
//+------------------------------------------------------------------+ 
Razón de la queja: