Toute question des nouveaux arrivants sur MQL4 et MQL5, aide et discussion sur les algorithmes et les codes. - page 1371

 
MakarFX:

Au plus bas de l'EA.

Malheureusement il ne se multiplie pas !!!((((

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

Malheureusement il ne se multiplie pas !!!((((

Cette fonction calcule le lot en fonction de la marge libre et du risque spécifié !

De quelle multiplication parlez-vous ?

 
MakarFX:

Cette fonction calcule le lot en fonction de la marge libre et du risque spécifié !

De quelle multiplication parlez-vous ?

L'augmentation des lots après chaque bénéfice !

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

sur l'augmentation des lots après chaque bénéfice !

Cette fonction augmentera le lot après un profit, mais si le profit permet une augmentation de l'incrément minimum du lot.

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

sur l'augmentation des lots après chaque bénéfice !

voici un exemple jusqu'à 10 000 votre solde sera lot 0.1 de 10 000 à 20 000 avec 0.5 lot

de 20 000 à 40 000 avec le lot 1.0 plus de 40 000 avec le lot 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:

voici un exemple jusqu'à 10 000 votre solde sera lot 0.1 de 10 000 à 20 000 avec 0.5 lot

de 20 000 à 40 000 avec 1,0 lot plus de 40 000 avec 2,0 lot

il s'agit d'un incrément de lot fixe.

pour moi, si le bénéfice est supérieur ou égal à

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

cela augmentera le lot,

mais s'il n'y a pas d'autres ordres ouverts qui utilisent la marge.

 
MakarFX:

il s'agit d'une augmentation fixe dans le lot.

Dans mon cas, si le bénéfice est supérieur ou égal à

alors il y aura une augmentation du lot,

mais s'il n'y a pas d'autres ordres ouverts qui utilisent la marge.

J'ai triché - si la position est déficitaire, cela augmenterait le lot.

//+------------------------------------------------------------------+
//| 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);
  }
//+------------------------------------------------------------------+
 
Merci à tous pour votre aide MAIS mes cerveaux qui ne sont pas là n'étaient pas suffisants pour faire ce dont j'avais besoin !
 
Сергей Дыбленко:
Merci à tous pour votre aide MAIS mon cerveau n'est pas suffisant pour faire ce que je dois faire !

Vous expliquez point par point ce qui est nécessaire.

Combien d'ordres dans le travail, combien de paires vous négociez simultanément, quels sont les risques par transaction (s'il y en a) ?

Et quelque chose d'autre de vous)

 
SanAlex:

Là, j'ai triché - si les positions sont déficitaires le lot augmenterait

Sasha l'a modifié un peu pour augmenter le lot par les chances.

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