Tutte le domande dei nuovi arrivati su MQL4 e MQL5, aiuto e discussione su algoritmi e codici - pagina 1371

 
MakarFX:

Fino al fondo dell'EA.

Purtroppo non si moltiplica!!!(((

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

Purtroppo non si moltiplica!!!(((

Questa funzione calcola il lotto in relazione al margine libero e al rischio specificato!

Di quale moltiplicazione stai parlando?

 
MakarFX:

Questa funzione calcola il lotto in relazione al margine libero e al rischio specificato!

Di quale moltiplicazione stai parlando?

L'aumento dei lotti dopo ogni profitto!

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

sull'aumento dei lotti dopo ogni profitto!

Questa funzione aumenterà il lotto dopo un profitto, ma se il profitto permette un aumento del lotto minimo

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

sull'aumento dei lotti dopo ogni profitto!

ecco un esempio fino a 10 000 il tuo saldo sarà lotto 0,1 da 10 000 a 20 000 con lotto 0,5

da 20 000 a 40 000 con lotto 1.0 oltre 40 000 con lotto 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:

ecco un esempio fino a 10 000 il tuo saldo sarà lotto 0,1 da 10 000 a 20 000 con lotto 0,5

da 20 000 a 40 000 con lotto 1.0 oltre 40 000 con lotto 2.0

questo è un incremento di lotto fisso.

per me, se il profitto è maggiore o uguale a

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

aumenterà il lotto,

ma se non ci sono altri ordini aperti che usano il margine.

 
MakarFX:

è un aumento fisso del lotto.

Nel mio caso, se il profitto è maggiore o uguale a

allora ci sarà un aumento del lotto,

ma se non ci sono altri ordini aperti che usano il margine.

Ho barato - se la posizione è in deficit aumenterebbe il lotto

//+------------------------------------------------------------------+
//| 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);
  }
//+------------------------------------------------------------------+
 
Grazie a tutti per il vostro aiuto MA il mio cervello che non c'è non era sufficiente per fare ciò di cui avevo bisogno!
 
Сергей Дыбленко:
Grazie a tutti per il vostro aiuto MA il mio cervello non è sufficiente per fare quello che devo fare!

Lei spiega punto per punto ciò che è necessario.

Quanti ordini nel lavoro, quante coppie si scambiano simultaneamente, quali sono i rischi per scambio (se ce ne sono)

E qualcos'altro da te)

 
SanAlex:

Qui stavo barando - se le posizioni sono in deficit il lotto aumenterebbe

Sasha l'ha modificato un po' per aumentare il lotto delle probabilità

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);
  }
//+------------------------------------------------------------------+ 
Motivazione: