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

 
erotin:

Può dirmi cosa c'è di sbagliato nel razionamento del lotto?

Tutto è sbagliato. Leggete l'articolo "Quali controlli deve superare un EA...". Lì c'è una funzione già pronta.

 

Fatto, fatto un modello vuoto, preparato tutto il necessario per la funzione iCustom().

Ho messo l'indicatore iCrossAD che mi interessa nella funzione.

La funzione funziona, trova correttamente gli indici delle frecce Up e Down più esterne, ma i valori di prezzo a cui queste frecce sono state impostate sono sbagliati.

Il codice è breve, quindi lo metterò proprio qui, allegherò i file di questo consulente e dell'indicatore per sicurezza.

//+------------------------------------------------------------------+
//|                                             TestDoEasyPart08.mq5 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                             https://mql5.com/ru/users/artmedia70 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://mql5.com/ru/users/artmedia70"
#property version   "1.00"
#property description ""
#property strict
//--- includes
#include <DoEasy\Engine.mqh>
#include <Trade\Trade.mqh>
#include <Trade\PositionInfo.mqh>
#include <Trade\SymbolInfo.mqh>
//---
input string               Inp_param_indi_iCrossAD = "Input parameters indicator iCrossAD";//----- "Внешние параметры индикатора iCrossAD" -----

input uint                 InpPeriodFind           = 400;                 // Bars for calculate
input uint                 InpUnheckedBars         = 2;                   // Unchecked bars
input uint                 InpPeriodIND            = 21;                  // CCI period

//--- global variables

CEngine        engine;
CTrade         trade;
CPositionInfo  apos;
CSymbolInfo    asymbol;

uint            period_find = InpPeriodFind;       //Number bars for calculate

int            CrossAD;                           //Хэндл индикатора iCrossAD

double         Buf_Arrow_Sell[],                  //Массив буфера для приема значений последних стрелок ВНИЗ из индикатора iCrossAD
               Last_Arrow_Sell_volume,            //Переменная для записи значения цены последней стрелки ВНИЗ индикатора iCrossAD
               Last_Arrow_Sell_index;             //Переменная для записи значения индекса свечи последней стрелки ВНИЗ индикатора iCrossAD
               
double         Buf_Arrow_Buy[], Last_Arrow_Buy_volume, Last_Arrow_Buy_index;
   
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   ArraySetAsSeries(Buf_Arrow_Buy, true);
   ArraySetAsSeries(Buf_Arrow_Sell, true);
//---
   CrossAD = iCustom(asymbol.Name(), _Period, "iCrossAD");
   if (CrossAD == INVALID_HANDLE)
   {
      Print("Не удалось создать описатель индикатора iCrossAD!");
      return(INIT_FAILED);
   }
      else Print("Хендл iCrossAD = ",CrossAD);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- delete objects
   ObjectsDeleteAll(0,"",-1);
   Comment("");
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   int n=0;
   
   if (CopyBuffer(CrossAD, 1, 0, period_find, Buf_Arrow_Buy) != period_find)
      {  
         Print("НЕ удалось правильно скопировать данные из 1-го буфера индикатора iCrossAD, error code %d",GetLastError());
         return;
      }
         for(n=0; n<period_find; n++)
            {
               if(Buf_Arrow_Buy[n]!=EMPTY_VALUE)break;
            }
         Last_Arrow_Buy_volume = Buf_Arrow_Buy[n];
         Last_Arrow_Buy_index  = n;
         Print("Last_Arrow_Buy_volume = ",Last_Arrow_Buy_volume,", Last_Arrow_Buy_index = ",Last_Arrow_Buy_index);
         
   if (CopyBuffer(CrossAD, 2, 0, period_find, Buf_Arrow_Sell) != period_find)
      {  
         Print("НЕ удалось правильно скопировать данные из 2-го буфера индикатора iCrossAD, error code %d",GetLastError());
         return;
      }
         for(n=0; n<period_find; n++)
            {
               if(Buf_Arrow_Sell[n]!=EMPTY_VALUE)break;
            }
         Last_Arrow_Sell_volume = Buf_Arrow_Sell[n];
         Last_Arrow_Sell_index  = n;
         Print("Last_Arrow_Sell_volume = ",Last_Arrow_Sell_volume,", Last_Arrow_Sell_index = ",Last_Arrow_Sell_index);
      
Comment("-------------------------", 
         "\n Last_Arrow_Buy_volume     = ",Last_Arrow_Buy_volume,
         "\n Last_Arrow_Buy_index        = ",Last_Arrow_Buy_index,
         "\n ---------------------- ",
         "\n Last_Arrow_Sell_volume     = ",Last_Arrow_Sell_volume,
         "\n Last_Arrow_Sell_index        = ",Last_Arrow_Sell_index
         ); 
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
   if(!MQLInfoInteger(MQL_TESTER))
      engine.OnTimer();
  }
File:
iCrossAD.mq5  49 kb
 

Ecco come appaiono le voci di registro nella scheda "Experts

2019.05.20 15:11:15.025 Test_iCustom (EURUSD,H1) Last_Arrow_Buy_volume = -11211905.17483469, Last_Arrow_Buy_index = 5.0

2019.05.20 15:11:15.025 Test_iCustom (EURUSD,H1) Last_Arrow_Sell_volume = -11203799.85975282, Last_Arrow_Sell_index = 50.0

2019.05.20 15:11:16.798 Test_iCustom (EURUSD,H1) Last_Arrow_Buy_volume = -11211905.17483469, Last_Arrow_Buy_index = 5.0

2019.05.20 15:11:16.798 Test_iCustom (EURUSD,H1) Last_Arrow_Sell_volume = -11203799.85975282, Last_Arrow_Sell_index = 50.0


 
Sergey Voytsekhovsky:

Ecco come appaiono le voci di registro nella scheda "Experts

2019.05.20 15:11:15.025 Test_iCustom (EURUSD,H1) Last_Arrow_Buy_volume = -11211905.17483469, Last_Arrow_Buy_index = 5.0

Invece del prezzo al quale sono state create le frecce = -11211905.17483469



 

Sergey Voytsekhovsky:

...

Invece dei prezzi a cui sono state create le frecce = -11211905.17483469

Premi Ctrl+D, muovi il mouse lungo le linee dell'indicatore e vedi nella finestra dei dati quali valori hanno i suoi buffer.

 
Artyom Trishkin:

Premi Ctrl+D, trascina il mouse lungo le linee dell'indicatore e guarda nella finestra dei dati per vedere quali valori hanno i suoi buffer.

Se ho capito bene, stavo cercando un gatto nella stanza che non c'è? L'array non è stato riempito con i prezzi, ma con i valori dell'indicatore in quel momento? Grazie, ci ripenserò.

Un'ultima domanda - il compilatore mi dà 2 avvertimenti


sign mismatch Test_iCustom.mq5 79 20

sign mismatch Test_iCustom.mq5 92 20


Non riesco a capire la loro ragione, per favore ditemi. Cosa significa "sign mismatch" (traduttore Yandex)?


 
Sergey Voytsekhovsky:

Se ho capito bene, stavo cercando un gatto nella stanza che non c'è? L'array non è stato riempito con i prezzi, ma con i valori dell'indicatore in quel momento? Grazie, ci ripenserò.

Un'ultima domanda - il compilatore mi dà 2 avvertimenti


sign mismatch Test_iCustom.mq5 79 20

sign mismatch Test_iCustom.mq5 92 20


Non riesco a capire la loro ragione, per favore ditemi. Che cosa significa "sign mismatch" (traduttore Yandex)?


Potresti perdere un segno numerico. Mostra queste linee di codice.

 
Artyom Trishkin:

Potresti perdere un segno numerico. Mostra queste linee di codice.

for(n=0; n<period_find; n++)
Il secondo è esattamente lo stesso (cicli per trovare valori non nulli negli array Arrows).
 
Sergey Voytsekhovsky:
Il secondo è esattamente lo stesso (cicli per trovare valori non nulli negli array "Arrows").

Quali sono i tipi di variabili n e period_find ? La cosa più importante che non hanno mostrato...

Provate:

for(n=0; n<(int)period_find; n++)

Perché dichiarate una variabile di loop a livello del gestore OnTick()?

Puoi farlo in questo modo:

for(int n=0; n<(int)period_find; n++)

Potete rimuovere la dichiarazione n da OnTick() - non ne abbiamo bisogno.

 
Artyom Trishkin:

Quali sono i tipi di variabili n e period_find? La cosa più importante e non mostrata...

uint            period_find = InpPeriodFind;       //Number bars for calculate
int             n=0;