MetaEditor build 1490

 

La nouvelle fonction "FileSave" ne permet d'enregistrer un fichier que sous forme binaire ?

//+------------------------------------------------------------------+
//|                                                 Scripts_Test.mq5 |
//|                                      Copyright 2012, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
//--- входные параметры
input int      rates_to_save=1000; // количество
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   string  filename=_Symbol+"_ticks.csv";
   MqlRates rates[];        
//---
   int copied=CopyRates(Symbol(),Period(),0,rates_to_save,rates);
   if(copied!=-1)
     {
      PrintFormat(" CopyRates(%s) copied %d rates",Symbol(),copied);
      //---  запишем тики в файл
      if(!FileSave(filename,rates,FILE_COMMON))
         PrintFormat("FileSave() failed, error=%d",GetLastError());
     }
   else
      PrintFormat("Failed CopyRates(%s), Error=",_Symbol,GetLastError());
  }
//+------------------------------------------------------------------+

Ce que je voulais faire : enregistrer le fichier au format "csv" pour l'ouvrir dans Excel.

Dossiers :
 
Vladimir Karputov:

La nouvelle fonction "FileSave" enregistre uniquement le fichier sous forme binaire ?

Oui.
 

Suggestion pour la classe CGraphic.mqh.

Afin de pouvoir supprimer un objet graphique, les méthodes de GraphPlot doivent être modifiées :

//+------------------------------------------------------------------+
//| Create graphic of one curve and return resource name             |
//+------------------------------------------------------------------+
string GraphPlot(const double &y[],ENUM_CURVE_TYPE type=CURVE_POINTS)
  {
   string   name="Graphic"+(string)(GetTickCount()+MathRand());
   ulong    width = ChartGetInteger(0,CHART_WIDTH_IN_PIXELS);
   ulong    height= ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS);
   CGraphic graphic;
//--- create graphic and add curves
   graphic.Create(0,name,0,65,45,(int)(0.6*width),(int)(0.65*height));
   graphic.CurveAdd(y,type);
//--- plot curves
   graphic.CurvePlotAll();
   graphic.Update();
//--- return resource name
   //return graphic.ResourceName();
   return graphic.ChartObjectName();
  }

Par exemple, il y a actuellement un objet nommé "Graphic27489614" sur le graphique, la méthode graphic.ResourceName() renvoie "::Graphic2748961427502758" et la méthode graphic.ChartObjectName() renvoie "Graphic27489614". Et si vous apportez une modification, vous pouvez appeler ObjectDelete avec le nom de l'objet et supprimer l'objet graphique.

 
Vladimir Karputov:

Suggestion pour la classe CGraphic.mqh.

Afin de pouvoir supprimer un objet graphique, les méthodes de GraphPlot doivent être modifiées :

Par exemple, il y a actuellement un objet nommé "Graphic27489614" sur le graphique, la méthode graphic.ResourceName() renvoie "::Graphic2748961427502758" et la méthode graphic.ChartObjectName() renvoie "Graphic27489614". Et si vous apportez une modification, vous pouvez appeler ObjectDelete avec le nom de l'objet et supprimer l'objet graphique.

Mais cette possibilité existe déjà. En appelant la méthodeCGraphic::ChartObjectName(), nous obtenons le nom de l'objet à supprimer.

P.S. Ou même la méthodeCGraphic::Destroy().

 
Vladimir Karputov:

Proposition pour la classe CGraphic.mqh.

Cela a été fait pour ResourceSave.
 
Anatoli Kazharski:

Cette fonctionnalité est déjà disponible. En appelant simplement la méthodeCGraphic::ChartObjectName(), nous obtenons le nom de l'objet à supprimer.

P.S. Ou même la méthodeCGraphic::Destroy().

Non. Les deux méthodes ne fonctionnent pas (CGraphic::ChartObjectName() renvoie "NULL"), CGraphic::Destroy() ne sert pas du tout à détruire le graphique.
 
Vladimir Karputov:
Non. Les deux méthodes ne fonctionnent pas (CGraphic::ChartObjectName() renvoie "NULL"), CGraphic::Destroy() ne sert pas du tout à supprimer le graphique.

Les deux fonctionnent pour moi. Testez ce script et montrez-moi votre version. Je me demande pourquoi ça n'a pas marché pour vous.

Vous pouvez tester deux méthodes dans le script.

//+------------------------------------------------------------------+
//|                                                         Test.mq5 |
//|                        Copyright 2016, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
//---
#include <Math/Stat/Binomial.mqh>
#include <Graphics/Graphic.mqh>
//--- Размер массива
#define ARRAY_SIZE 50
//---
double array_values[ARRAY_SIZE];
double array_results[ARRAY_SIZE];
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart(void)
  {
   string name   ="Graphic";
   ulong  width  =::ChartGetInteger(0,CHART_WIDTH_IN_PIXELS);
   ulong  height =::ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS);
//---
   CGraphic graphic;
//--- create graphic
   graphic.Create(0,name,0,65,45,(int)(0.6*width),(int)(0.65*height));
//---
   InitArray();
   CCurve *curve1=graphic.CurveAdd(array_values,CURVE_POINTS);
//---
   graphic.CurvePlotAll();
   graphic.Update();
//---
   for(int i=0; i<10; i++)
     {
      InitArray();
      curve1.Update(array_values);
      //---
      graphic.CurvePlotAll();
      graphic.Update();
      //---
      Sleep(500);
     }
//---
   graphic.Destroy();
//---
   ::Print(__FUNCTION__," > graphic.ChartObjectName(): ",graphic.ChartObjectName());
   if(!::ObjectDelete(0,graphic.ChartObjectName()))
      Print(__FUNCTION__," > Объект уже удалён!");
  }
//+------------------------------------------------------------------+
//| Генерация значений                                               |
//+------------------------------------------------------------------+
void InitArray(void)
  {
   for(int j=0; j<ARRAY_SIZE; j++)
      array_values[j]=j;
   Shuffle(array_values);
  }
//+------------------------------------------------------------------+
//| Тасование значений массива                                       |
//+------------------------------------------------------------------+
void Shuffle(double &array[])
  {
   for(uint i=0; i<ARRAY_SIZE; i++)
      RandomSwap(array_values,i);
  }
//+------------------------------------------------------------------+
//| Случайно поменять элементы местами                               |
//+------------------------------------------------------------------+
void RandomSwap(double &array[],uint i)
  {
//--- Случайный индекс для замены
   uint j=::rand()%ARRAY_SIZE;
//--- Меняем местами
   double temp =array[i];
   array[i]    =array[j];
   array[j]    =temp;
  }
//+------------------------------------------------------------------+
 

J'ai initialement torturé cet exemple (tiré deMetaTrader 5 build 1485 : modes test et graphique supplémentaires dans la bibliothèque standard)

//+------------------------------------------------------------------+
//|                                                       Test_1.mq5 |
//|                        Copyright 2016, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
#include <Math/Stat/Binomial.mqh>
#include <Graphics/Graphic.mqh>
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnStart(void)
  {
   double    vars[101];
   double    results[101];
   const int N=2000;
//---  
   MathSequence(0,N,20,vars);
   MathProbabilityDensityBinomial(vars,N,M_PI/10,true,results);
   GraphPlot(results);
//---
  }
 
#include <Math\Stat\Math.mqh> // https://www.mql5.com/ru/forum/162251#comment_3885372
#include <Math\Stat\Normal.mqh>
#include <Graphics\Graphic.mqh>

void OnStart()
  {
//---
   double random_values[];
   double pdf[];
   double cdf[];
   double x[];
   if(MathRandomNormal(0,1,1000000,random_values))
     {
      if(MathProbabilityDensityEmpirical(random_values,200,x,pdf))
        {
         GraphPlot(x,pdf,CURVE_LINES);
         //---
         DebugBreak();
        }

      if(MathCumulativeDistributionEmpirical(random_values,200,x,cdf))
        {
         GraphPlot(x,cdf,CURVE_LINES);
         //---
         DebugBreak();
        }
     }
  }
 
Vladimir Karputov:

J'ai initialement torturé cet exemple (tiré deMetaTrader 5 build 1485 : modes de test et de graphique supplémentaires dans la bibliothèque standard)

//+------------------------------------------------------------------+
//|                                                       Test_1.mq5 |
//|                        Copyright 2016, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
#include <Math/Stat/Binomial.mqh>
#include <Graphics/Graphic.mqh>
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnStart(void)
  {
   double    vars[101];
   double    results[101];
   const int N=2000;
//---  
   MathSequence(0,N,20,vars);
   MathProbabilityDensityBinomial(vars,N,M_PI/10,true,results);
   GraphPlot(results);
//---
  }

Pour l'instant, c'est ce que je fais dans le cadre d'un déménagement général :

      ObjectsDeleteAll(0,"Graphic",0,OBJ_BITMAP_LABEL);
      ChartRedraw();
 

Comment puis-je savoir si le SL/TP est déclenché dans OnTradeTransaction() ?

Voilà ce que j'ai fait, ça n'a pas aidé :

void  OnTradeTransaction (const MqlTradeTransaction &trans,   // структура торговой транзакции
                          const MqlTradeRequest     &request, // структура запроса
                          const MqlTradeResult      &result)  // структура ответа
{
  if(trans.type == TRADE_TRANSACTION_HISTORY_ADD)
  {
    datetime date = TimeCurrent ();
    MqlDateTime dateT;
    TimeToStruct (date, dateT);
    dateT.hour += 1;
    date = StructToTime (dateT);
    
    if(HistorySelect (TimeCurrent (), date))
    {
      int dealsTotal = HistoryDealsTotal ();
      ulong ticketD = HistoryDealGetTicket (dealsTotal - 1);
      if(HistoryDealGetString (ticketD, DEAL_SYMBOL) == Symbol ())
      {
        ENUM_DEAL_ENTRY entry = (ENUM_DEAL_ENTRY)HistoryDealGetInteger (ticketD, DEAL_ENTRY);
        if(entry == DEAL_ENTRY_OUT)
        {
          int ordersTotal = HistoryOrdersTotal ();
          ulong ticketO = HistoryOrderGetTicket (ordersTotal - 1);
          if(HistoryOrderGetString (ticketO, ORDER_SYMBOL) == Symbol ())
          {
            double orderPrice = HistoryOrderGetDouble (ticketO, ORDER_PRICE_OPEN);
            double orderSL    = HistoryOrderGetDouble (ticketO, ORDER_SL);
            double orderTP    = HistoryOrderGetDouble (ticketO, ORDER_TP);
            
            if(orderPrice == orderSL)
              Print ("Сработал SL");
            
            if(orderPrice == orderTP)
              Print ("Сработал TP");
          }  
        }
      }  
    }
  }
}

Et de toute façon, il n'y a pas plus simple !

2016.12.04 14:33:01.854 2016.11.17 03:14:40 take profit triggered #4 sell 0.10 EURUSD 1.07103 sl : 1.07153 tp : 1.07053 [#5 buy 0.10 EURUSD at 1.07053]
Ici, l'événement est montré dans les logs du terminal, pourquoi est-il si facile d'obtenir cet événement (déclenchement de SL/TP) dans l'EA ? Ou est-ce possible ?
Raison: