Je rédigerai un conseiller gratuitement - page 85

 
Evgenij Litvintsev:

Bonjour ! Peut-être que quelqu'un serait intéressé par l'automatisation de ma stratégie. Il fonctionne maintenant, mais en mode semi-automatique, j'aimerais l'automatiser.


Puis-je voir les résultats des transactions ?

 

Bonsoir, pourriez-vous m'indiquer comment obtenir un ordre de ticket, un lot et un bénéfice à partir d'une seule fonction :

double OldTicketSell()// Trouver l'ordre de vente le plus éloigné

{
double MaxDist=0,oldprofit,lot ;
int ticket=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) ;
ticket=OrderTicket() ;
oldprofit = OrderProfit() ;
lot = OrderLots() ;
}
}
}
retour(ticket) ;

}

La fonction est claire, mais il n'est pas évident d'en extraire les données trouvées, ni de les copier sous lot et profit.


 
Николай:

Bonsoir, pourriez-vous m'indiquer comment obtenir les ordres, le lot et le bénéfice d'un ticket à partir d'une seule fonction.

La fonction est compréhensible, mais il n'est pas clair comment en extraire les données trouvées, ou dois-je les copier sous lot et profit.

Nous pourrions le faire comme suit

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:

Vous pouvez faire comme ceci

Tout cela est bien, mais je suis un idiot, j'essaie d'écrire un EA dans la mesure de mes connaissances (je viens d'apprendre un peu), je comprends que la variable est une structure, mais comment obtenir des données de cette structure n'est pas clair. Par exemple, si nous avons trouvé l'ordre le plus éloigné, le bénéfice doit être divisé par les lots et nous obtenons le nombre de points entre le prix actuel et le lot. Ensuite, nous obtenons le bénéfice d'un ordre opposé (je sais comment l'obtenir), nous le divisons par le nombre de points de l'ordre opposé calculé précédemment, nous obtenons le nombre de lots et nous utilisons ce nombre de lots pour fermer totalement ou partiellement l'ordre lointain trouvé.
 
Konstantin Nikitin:

Nous pourrions le faire comme suit

Je voudrais également demander s'il est possible de trouver l'ordre le plus éloigné du prix en comparant les prix d'ouverture des ordres du cycle, je pense que ce serait encore plus facile ?

 
Николай:

Je voudrais également demander s'il est possible de trouver l'ordre le plus éloigné du prix en comparant les prix d'ouverture des ordres du cycle, je pense que ce serait encore plus facile ?

Bien sûr qu'elle l'est. Et le fait que ce soit plus facile ou non dépend de ce dont vous avez besoin.
Voici un exemple pour répondre à votre question ci-dessus.

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:

Bien sûr que vous pouvez. Que ce soit plus facile ou non, cela dépend de ce dont vous avez besoin.
Et un exemple pour répondre à votre question ci-dessus.

En regardant tout cela, je réalise à quel point je suis un pronostiqueur. Ainsi, lerésultat de lafonctionvoid OldSell(void)est écrit dans la structureInfoOrder, et vous pouvez ensuite utiliser les valeurs des 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:

Bien sûr que vous pouvez. Le fait que ce soit plus facile ou non dépend de ce dont vous avez besoin.
Et un exemple pour répondre à votre question ci-dessus.

J'ai oublié de changer les variables d'impression
 
Николай:
En regardant tout ça, je réalise à quel point je suis un imbécile. Ainsi, lerésultat de lafonctionvoid OldSell(void)est écrit dans la structureInfoOrder et nous pouvons ensuite utiliser infoOrder.ticket,infoOrder.profit,infoOrder.lot.J'ai un peu généralisé la fonction, était-ce bien ou non ?
//-Структура для нахождения самого дальнего ордера на продажу
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; 
}

Quelque chose comme ça.
 




J'ai trouvé cette structure dans l'EA, pouvez-vous me dire ce qu'elle définit ?

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;
}


Raison: