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

 
makssub #:

Che sia tutto all'interno della stessa coppia di valute, EurUsd per esempio. Entrambi sono aperti in Buy.

Generalmente si tratta di compiti diversi, su coppie diverse e sulla stessa. Su una coppia di valute con lo stesso lotto 2 ordini/posizioni hanno opzioni diverse: non-crossing e crossing. Al di sopra di quello al di sotto che è o perdita o profitto a seconda della distanza degli ordini. Per una direzione tra, uno in profitto l'altro in perdita, sopra sotto entrambi in profitto o in perdita.

Dovrebbe essere impostato secondo le vostre preferenze. Se il volume è lo stesso, si dovrebbe chiudere lo stesso volume. Se non è lo stesso, si dovrebbe calcolare la quantità di denaro in profitto, la quantità di perdita in denaro, calcolare il rapporto tra profitto e perdita, moltiplicare questo rapporto per il numero di lotti di una posizione perdente e chiudere questa parte.

 
Ivan Butko una nuova candela è iniziata e dopo averlo fatto girare attraverso il codice, tenere fermo e aspettare che la prossima candela inizi?

funzione

  bool NewBar()
   {
      static datetime LastTime = 0;
      if(iTime(Symbol(), PERIOD_CURRENT, 0) != LastTime)
      {
         LastTime = iTime(Symbol(), PERIOD_CURRENT, 0);
         return (true);
      }
      else
         return (false);
   }
 
Valeriy Yastremskiy #:

Si tratta di compiti diversi, su coppie diverse e sulla stessa coppia. Su uno, con lo stesso lotto 2 ordini/posizioni hanno opzioni divergenti non incrociate, e incrociate. il prezzo tra quelli non incrociati è perdita per entrambi, quelli incrociati hanno profitto solo tra gli ordini. Al di sopra di quello al di sotto che è o perdita o profitto a seconda della distanza degli ordini. Per una direzione tra, uno in profitto l'altro in perdita, sopra sotto entrambi in profitto o in perdita.

Dovrebbe essere impostato secondo le vostre preferenze. Se il volume è lo stesso, si dovrebbe chiudere lo stesso volume. Se non è lo stesso, si dovrebbe calcolare la quantità di denaro in profitto, la quantità di perdita in denaro, calcolare il rapporto tra profitto e perdita, moltiplicare questo rapporto per il numero di lotti di una posizione perdente e chiudere questa parte.

Esatto) È esattamente quello che voglio. Per calcolare e chiudere la parte perdente.
Qualche esempio?
Ho provato un po', mi sono confuso e ho fallito.

 
Valeriy Yastremskiy #:

sashasonik #:

funzione

Grazie mille!
 
makssub #:

Esatto) È esattamente quello che voglio. Calcolare e chiudere la parte perdente.
Qualche esempio?
Ho provato per un po', mi sono confuso, non ha funzionato.

Se non mi sbaglio, queste funzioni si sovrappongono in una direzione, cioè o comprare o vendere. In breve, dobbiamo modificarlo.




//=========================================================================================================================================//
//  Функция расчета текущего состояния по открытым ордерам                                                                                 //
//=========================================================================================================================================//

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double CurrentCondition(string OrdType, string inf)
{
   int    Pos   = 0;
   double result = 0, Count = 0, AveragePrice = 0, profit = 0;
   double LastPriceBuy, LastPriceSell, ProfitBuy, ProfitSell, SumProfit;
   for(int cnt = 0; cnt < OrdersTotal(); cnt++)
   {
      if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
      {
         if(OrderSymbol() == Symbol() && (OrderMagicNumber() == MagicNumber || MagicCheck()))
         {
            if(OrderType() == OP_SELL || OrderType() == OP_BUY)
            {
               if(inf == "Lpos")
               {
                  profit = OrderProfit()              ;
                  Pos    = OrderTicket()              ;

                  if(profit > 0 && profit > Lprofit)
                  {
                     Lprofit1 = Lprofit                  ;
                     Lpos1    = Lpos                     ;
                     Lprofit  = profit                   ; //макс значение
                     Lpos     = Pos                      ;
                  }

                  if(profit < 0 && profit < Cprofit)
                  {
                     Cprofit = profit                    ; //мин  значение
                     Cpos    = Pos                       ;
                  }
               }

               SumProfit += OrderProfit() + OrderSwap() + OrderCommission() ;
               if(inf == "CurrentDrawdown")
                  result = MathMax((AccountBalance() + AccountCredit() - AccountEquity()) / (AccountBalance() + AccountCredit()) * 100, 0);
               if(inf == "CurrentUrov" && AccountMargin() > 0)
                  result = AccountEquity() / AccountMargin() * 100        ;
               if(inf == "TotalOrd")
                  result++                ;

               if(OrdType == "Buy")
               {
                  if(OrderType() == OP_BUY)
                  {
                     if(inf == "TotalBuy")
                        result++                         ;
                     if(inf == "LastLotBuy")
                        result  = OrderLots()            ;
                     if(inf == "SumLotBuy")
                        result += OrderLots()            ;
                     AveragePrice += OrderOpenPrice() * OrderLots()            ;
                     Count        += OrderLots()                              ;
                     LastPriceBuy  = OrderOpenPrice()                         ;
                     ProfitBuy += OrderProfit() + OrderSwap() + OrderCommission() ;
                     if(AveragePrice > 0 && Count > 0)
                     {
                        if(inf == "CalculateAveragePriceBuy")
                           return(NormalizeDouble(AveragePrice / Count, Digits));
                     }
                     else
                        return(0);
                  }
               }

               if(OrdType == "Sell")
               {
                  if(OrderType() == OP_SELL)
                  {
                     if(inf == "TotalSell")
                        result++                        ;
                     if(inf == "LastLotSell")
                        result  = OrderLots()           ;
                     if(inf == "SumLotSell")
                        result += OrderLots()           ;
                     AveragePrice  += OrderOpenPrice() * OrderLots()           ;
                     Count         += OrderLots()                             ;
                     LastPriceSell  = OrderOpenPrice()                        ;
                     ProfitSell += OrderProfit() + OrderSwap() + OrderCommission();
                     if(AveragePrice > 0 && Count > 0)
                     {
                        if(inf == "CalculateAveragePriceSell")
                           return(NormalizeDouble(AveragePrice / Count, Digits));
                     }
                     else
                        return(0);
                  }
               }
            }
         }
      }
   }

   if(inf == "Lpos")
      return(Lpos)                                    ;  //Ордер с наибольшим профитом
   if(inf == "Cpos")
      return(Cpos)                                    ;  //Ордер с наименьшим профитом
   if(inf == "LastPriceBuy")
      return(NormalizeDouble(LastPriceBuy, Digits))  ;
   if(inf == "LastPriceSell")
      return(NormalizeDouble(LastPriceSell, Digits))  ;
   if(inf == "ProfitBuy")
      return(NormalizeDouble(ProfitBuy,      2))  ;
   if(inf == "ProfitSell")
      return(NormalizeDouble(ProfitSell,      2))  ;
   if(inf == "SumProfit")
      return(NormalizeDouble(SumProfit,      2))  ;
   return(result)                                                             ;
}

//=========================================================================================================================================//
//   Перекрытие ордеров                                                                                                                    //
//=========================================================================================================================================//

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void CheckOverlapping()
{
   Lpos = 0;
   Cpos = 0;
   Lprofit = 0;
   Cprofit = 0;

   Lpos = CurrentCondition("", "Lpos");
   Cpos = CurrentCondition("", "Cpos");

   if(totalord >= LeadingOrder)
   {
      if(Lprofit > 0 && Lprofit1 <= 0 && Cprofit < 0)
      {
         if(Lprofit + Cprofit > 0 && (Lprofit + Cprofit) * 100 / Lprofit > ProfitPersent)
         {
            Lpos1 = 0;
            CloseSelectOrder();
         }
      }
      else

         if(Lprofit > 0 && Lprofit1 > 0 && totalord > LeadingOrder && Cprofit < 0)
         {
            if(Lprofit + Lprofit1 + Cprofit > 0 && (Lprofit + Lprofit1 + Cprofit) * 100 / (Lprofit + Lprofit1) > SecondProfitPersent)
               CloseSelectOrder();
         }
   }
}

//=========================================================================================================================================//
//  Перекрытие ордеров                                                                                                                     //
//=========================================================================================================================================//

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int CloseSelectOrder()
{
   if(Info)
      Print("Функция перекрытия ордеров.");
   int error =  0;
   int error1 = 0;
   int error2 = 0;
   int Result = 0;
   int Slippage = 2 * MarketInfo(Symbol(), MODE_SPREAD);

//                       ---------------------- последний  -----------------------

   while(error1 == 0)
   {
      RefreshRates();
      int i = OrderSelect(Lpos, SELECT_BY_TICKET, MODE_TRADES);
      if(i != 1)
      {
         Print("Ошибка! Невозможно выбрать ордер с наибольшим профитом. Выполнение перекрытия отменено.");
         return (0);
      }
      if(OrderSymbol() == Symbol() && (OrderMagicNumber() == MagicNumber || MagicCheck()))
      {
         if(OrderType() == OP_BUY)
         {
            error1 = (OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(Bid, Digits), Slippage, Blue));
            if(error1 == 1)
            {
               if(Info)
                  Print("Лидирующий ордер закрыт успешно.");
               Sleep(500);
            }
            else
            {
               Print("Ошибка закрытия лидирующего ордера, повторяем операцию. ");
            }
         }

         //                        -----------------------------------------------------

         if(OrderType() == OP_SELL)
         {
            error1 = (OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(Ask, Digits), Slippage, Red));
            if(error1 == 1)
            {
               if(Info)
                  Print("Лидирующий ордер закрыт успешно");
               Sleep(500);
            }
            else
            {
               Print("Ошибка закрытия лидирующего ордера, повторяем операцию. ");
            }
         }
      }
   }

//                       ---------------------- пред последний  -----------------------

   if(Lpos1 != 0)
   {
      while(error2 == 0)
      {
         RefreshRates();
         i = OrderSelect(Lpos1, SELECT_BY_TICKET, MODE_TRADES);
         if(i != 1)
         {
            Print("Ошибка! Невозможно выбрать пред ордер с наибольшим профитом. Выполнение перекрытия отменено.");
            return (0);
         }
         if(OrderSymbol() == Symbol() && (OrderMagicNumber() == MagicNumber || MagicCheck()))
         {
            if(OrderType() == OP_BUY)
            {
               error2 = (OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(Bid, Digits), Slippage, Blue));
               if(error2 == 1)
               {
                  if(Info)
                     Print("Пред Лидирующий ордер закрыт успешно.");
                  Sleep(500);
               }
               else
               {
                  Print("Ошибка закрытия пред лидирующего ордера, повторяем операцию. ");
               }
            }
            //                        -----------------------------------------------------
            if(OrderType() == OP_SELL)
            {
               error2 = (OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(Ask, Digits), Slippage, Red));
               if(error2 == 1)
               {
                  if(Info)
                     Print("Пред Лидирующий ордер закрыт успешно");
                  Sleep(500);
               }
               else
               {
                  Print("Ошибка закрытия Пред лидирующего ордера, повторяем операцию. ");
               }
            }
         }
      }
   }

//                      ----------- выбранный (обычно с наименьшим профитом ) -----------

   while(error == 0)
   {
      RefreshRates();
      i = OrderSelect(Cpos, SELECT_BY_TICKET, MODE_TRADES);
      if(i != 1)
      {
         Print("Ошибка! Невозможно выбрать ордер с наименьшим профитом. Выполнение перекрытия отменено.");
         return (0);
      }
      if(OrderSymbol() == Symbol() && (OrderMagicNumber() == MagicNumber || MagicCheck()))
      {
         if(OrderType() == OP_BUY)
         {
            error = (OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(Bid, Digits), Slippage, Blue));
            if(error == 1)
            {
               if(Info)
                  Print("Перекрываемый ордер закрыт успешно.");
               Sleep(500);
            }
            else
            {
               Print("Ошибка закрытия перекрываемого ордера, повторяем операцию. ");
            }
         }

         //                             --------------------------------------------------

         if(OrderType() == OP_SELL)
         {
            error = (OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(Ask, Digits), Slippage, Red));
            if(error == 1)
            {
               if(Info)
                  Print("Перекрываемый ордер закрыт успешно.");
               Sleep(500);
            }
            else
            {
               Print("Ошибка закрытия перекрываемого ордера, повторяем операцию. ");
            }
         }
      }
   }

   Result = 1;
   return (Result);
}

 
makssub #:

Esatto) È esattamente quello che voglio. Calcolare e chiudere la parte perdente.
Qualche esempio?
Ho provato un po', mi sono confuso, non ha funzionato.

Cosa c'è che non va nel vail? Avete bisogno del codice. Io non ho questi problemi. e francamente non credo che un tale approccio alla gestione del denaro sia saggio.

 
Potete dirmi come caricare 2 indicatori uguali con gli stessi intenti in una finestra in MT5? Ho provato INDICATOR_SHORTNAME per cambiarlo ogni volta che lo avvio, ma non aiuta. Forse c'è un altro modo?
 
Aleksandr Kononov #:
Per favore consigliate come caricare 2 indicatori uguali con gli stessi intenti in una finestra in MT5. Ho provato INDICATOR_SHORTNAME, dovrei cambiarlo ogni volta che lo avvio. Forse c'è un altro modo?

Prendi un altro input senza valore e cambialo.

 
Valeriy Yastremskiy #:

Perché hai bisogno di un vail, cosa c'è di male? Avete bisogno di un codice. Io non ho questo tipo di problema. e francamente non credo che questo approccio sia saggio per un gestore di denaro

Buon pomeriggio. Ho letto di Vail. Non so aggiungere o sottrarre.
Non posso dire nulla sulla gestione del denaro, non ho provato.
Ho allegato l'ultima versione. Ma ho già incasinato tutto per me)
Order1(2) il profitto dell'ordine selezionato
Order1(3) il lotto dell'ordine selezionato

double FirstProfit(int a = 1)
{
   double  profit = 0, proflot = 0,
           OneProfLot = 0, result = 1, profit_1 = 0;
           
      OneProfLot = NormalizeDouble(Lots*Order1(2)/Order1(3),2);
      profit = NormalizeDouble(Lots*Order1(2)/Order1(3),2);
      proflot = Order1(3);
      while (profit >= Order1(2) && profit <= OneProfLot)
         {
            profit -= OneProfLot;
            if (profit !=0 && NormalizeDouble(profit + CalculateProfitHistory(),2) > NormalizeDouble(ProfitLot, Digits)*Lots*100) 
            profit_1 = profit;
            proflot = NormalizeDouble(proflot*profit/Order1(2),2);
 
         }
      }
   }
   if(a==1) {result = (double)profit_1;} else
   if(a==2) {result = (double)proflot;}  
   return(result);
}
 
Alexey Viktorov #:

Prendi un altro input senza valore e cambialo.

E senza intervento manuale? In mt4 ho degli indicatori che sono impostati uno sopra l'altro, e non so perché. Vorrei che fosse lo stesso in mt5, e in generale vorrei capire da cosa dipende.

Motivazione: