Librerie: Esperto - pagina 13

 
fxsaber #:

In caso di problemi, si prega di fornire i file mq5 pronti per la riproduzione.

#define  MT4ORDERS_LIBRARY
#include "../../utils/MT4Orders.mqh" 
// #define REPORT_BROWSER // Creazione di un report all'avvio del browser - richiede l'autorizzazione della DLL.
#define  TESTER_CUSTOM // Esecuzione dell'Expert Advisor nel Tester utente
#include "../../utils/fxsaber/Tester/Tester.mqh" // https://www.mql5.com/it/code/24848

#define  Bid SymbolInfoDouble(_Symbol, SYMBOL_BID)
#define  Ask SymbolInfoDouble(_Symbol, SYMBOL_ASK)

#define  KEY_B 66
#define  KEY_S 83
#define  KEY_C 67

input int In1 = 1;
input group "label1"
input double In2 = 2.0;
// 
void OnChartEvent( const int id, const long &lparam, const double &dparam, const string &sparam ) {
  if (id == CHARTEVENT_KEYDOWN) {
    switch ((int)lparam) {
    case KEY_B: // acquistare
      OrderSend(_Symbol, OP_BUY, 1, Ask, 100, 0, 0);
      break;
    case KEY_S: // vendere
      OrderSend(_Symbol, OP_SELL, 1, Bid, 100, 0, 0);
      break;
    case KEY_C: // chiudere
      for (int i = OrdersTotal() - 1; i >= 0; i--)
        if (OrderSelect(i, SELECT_BY_POS) && (OrderType() <= OP_SELL))
          OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 100);
    }
  }
}


void OnTick() {
  //Stampa(_Symbol, " ", SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_SIZE));
}
void OnTimer() { /* Commento(REPORT::OrdersToString(_Symbol, 0, 5)); */ }
int OnInit() {
  Print(_Symbol, " ", SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_SIZE));
  Print(_Symbol, " In2 = ", In2);
  return(INIT_SUCCEEDED);
}
//
void OnDeinit( const int ) {}
//
void OnTradeTransaction(const MqlTradeTransaction& trans, const MqlTradeRequest& request, const MqlTradeResult& result) {

}
//+------------------------------------------------------------------+

Il codice di esempio utilizza il codice della libreria Tester. Dopo l'avvio, la variabile In2 è 0, non 2. Ciò significa che tutti i parametri di ingresso non possono essere recuperati dopo il gruppo.
 
hini #:

Questa situazione non sembra essere considerata. Quando il parametro è un gruppo, non esiste un valore specifico e il valore ottenuto sarà nullo, quindi non si otterrà alcun parametro dopo il gruppo.

Il codice seguente mostra che tutto viene gestito correttamente.

input int In1 = 1;
input group "label1"
input double In2 = 2.0;

#include <fxsaber\Expert.mqh> // https://www.mql5.com/it/code/19003

int GetAmountExperts()
{
  int Res = 0;
  
  for (long Chart = ChartFirst(); Chart != -1; Chart = ChartNext(Chart))
    Res += (ChartGetString(Chart, CHART_EXPERT_NAME) != "");
    
  return(Res);
}

void OnInit()
{
  if (GetAmountExperts() < 2)
  {
    MqlParam Params[];
    string Names[];
            
    const int Size = EXPERT::Parameters(0, Params, Names) - 1;
    
    ArrayPrint(Params);
    ArrayPrint(Names);
    
    for (uint i = Size; (bool)i--;)
      EXPERT::AddInputName(Params[i + 1], Names[i]);
            
    Params[Size].string_value = "7";
    EXPERT::Run(ChartOpen(_Symbol, _Period), Params);
  }
}


Risultato.

    [type] [integer_value] [double_value]      [string_value]
[0]     14               0           0.00 "Scripts\Test6.ex5"
[1]     14               1           1.00 "1"                
[2]     14               0           0.00 null               
[3]     14               2           2.00 "2.0"              
"In1" null  "In2"


Expert.mqh Expert Advisor lanciato tramite Expert.mqh.

 
input bool InRun = true;
input group "label1"
input double In2 = 2.0;

#include <fxsaber\Expert.mqh> // https://www.mql5.com/it/code/19003


int GetAmountExperts()
{
  int Res = 0;
  
  for (long Chart = ChartFirst(); Chart != -1; Chart = ChartNext(Chart))
    Res += (ChartGetString(Chart, CHART_EXPERT_NAME) != "");
    
  return(Res);
}

void OnInit()
{
  if (InRun)
  {
    MqlParam Params[];
    string Names[];
            
    const int Size = EXPERT::Parameters(0, Params, Names) - 1;
    
    ArrayPrint(Params);
    ArrayPrint(Names);
    int nameSize = ArraySize(Names);
    for (int i = nameSize-1; i >= 0; i--) {
      if (Names[i] == "InRun")
        Params[i+1].string_value = "false";
      EXPERT::AddInputName(Params[i + 1], Names[i]);
    }  
            
    ArrayPrint(Params);
    ArrayPrint(Names);
    //Params[Size].string_value = "7";
    EXPERT::Run(ChartOpen(_Symbol, _Period), Params);
    return;
  }
  Print("In2 = ", In2);
}

La funzione GetAmountExperts viene eseguita per un motivo sconosciuto per un tempo molto lungo senza alcun risultato. Ho modificato un po' il codice - per favore eseguitelo di nuovo. Non si deve assegnare il valore 7 al parametro In2 (si vedrà che c'è 0, non 2).


 
hini #:

Ho modificato un po' il codice: eseguitelo di nuovo.

Questa è una segnalazione di bug esemplare: ho eseguito il codice conciso, che ha mostrato immediatamente il bug.

Ho apportato la correzione, grazie.

 
fxsaber #:

Questa è una segnalazione di bug esemplare: ha eseguito un codice conciso che ha mostrato immediatamente un bug.

Ho apportato la correzione, grazie.

Capisco, in caso di problemi farò segnalazioni nello stesso formato.
 

Se lo script viene caricato, sembra che i parametri di input non possano essere modificati.

 //Test1.ex5
#property script_show_inputs
input string str = "test1" ;
//void OnInit() {
void OnStart () {
   Print (str);
}
 // Avvia l'Expert Advisor con i parametri di input specificati.
#property script_show_inputs

#include "Expert.mqh"

input bool CurrentChart = false ; // Eseguire l'EA sul grafico corrente(true)/nuovo(false)

string GetMyName( void ) {
   return ( StringSubstr ( MQLInfoString ( MQL_PROGRAM_PATH ), StringLen ( TerminalInfoString ( TERMINAL_DATA_PATH ) + "\\MQL5\\" )));
}

bool RunExpert( const long Chart ) {
   MqlParam Params[ 2 ];
  Params[ 0 ].string_value = "Experts\\Advisors\\Test1.ex5" ;
   // Il primo parametro di input dell'Expert Advisor
  Params[ 1 ].type = TYPE_STRING ;
  Params[ 1 ].string_value = "Hello World!" ;
   return (EXPERT::Run(Chart, Params));
}

#define  NAME __FILE__

void OnStart () {
   union UNION {
     double Double;
     long Long;
  } Chart;
   if (CurrentChart) {
    Chart.Long = ChartID ();
     GlobalVariableSet (NAME, Chart.Double);
     MqlParam Params[ 1 ];
     // Percorso verso se stessi (script)
    Params[ 0 ].string_value = GetMyName();
     // Sul nuovo grafico, ci lanciamo
    EXPERT::Run( ChartOpen ( _Symbol , _Period ), Params);
  } else if ( GlobalVariableCheck (NAME)) {
    Chart.Double = GlobalVariableGet (NAME);
     GlobalVariableDel (NAME);
    RunExpert(Chart.Long);
     ChartClose ();
  } else // Il modo più semplice per eseguire l'Expert Advisor (con parametri non predefiniti) non è sul grafico corrente
    RunExpert( ChartOpen ( _Symbol , _Period ));
}
//+------------------------------------------------------------------+
 
hini #:

Se lo script viene caricato, sembra che i parametri di input non possano essere modificati.

L'architettura della MT5 è tale che non è possibile impostare i valori dei parametri di input per gli script e non è possibile leggerli.

La libreria ha un nome eloquente.

 
fxsaber #:

L'architettura della MT5 è tale che non è possibile impostare i valori dei parametri di ingresso per gli script e non è possibile leggerli.

La libreria ha un nome eloquente.

ok