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

 
Non può accedere al sito web
 

Ciao sviluppatori,

Visualizza qualsiasi tester di strategia con data personalizzata o qualsiasi opzione di data

Vedi immagine:

tester di strategia

Voglio ottenere i valori di inizio e fine data nel mio programma nella funzione OnInit ().

Come posso ottenerlo?

 
Artyom Trishkin:

Formare l'intero ciclo in una funzione, e restituire il numero di barra se trovato, o WRONG_VALUE se non trovato.


Buon pomeriggio. Penso di aver finito di lavorare con il problematico iCustom di ieri. Ho fatto tutto sotto forma di funzione e ho usato"Comment" e "Print" per il controllo.

L'idea di questo Expert Advisor di prova è di catturare i segnali sotto forma di frecce su/giù dell'indicatore iCrossAD e trasformarli in un comando BUY o SELL da utilizzare in un programma futuro.

Ho un po' di esperienza, quindi per favore non giudicate severamente, ma critiche ben motivate e consigli su come farlo meglio sarebbero apprezzati.

Infatti, per il bene di questo e ha scritto un post. File EA e indicatore allegati, il codice qui sotto.

//+------------------------------------------------------------------+
//|                                                  Test_iCusom.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>
//---
enum Indicator_Direction
   {
   Direction_BUY,
   Direction_SELL,
   Direction_FLAT
   };
//---
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;

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

double         Buf_Arrow_Sell[],                  //Массив буфера для приема значений последних стрелок ВНИЗ из индикатора iCrossAD
               Last_Arrow_Sell_volume,            //Переменная для записи значения цены последней стрелки ВНИЗ индикатора iCrossAD
               Last_Arrow_Sell_index;             //Переменная для записи значения индекса свечи последней стрелки ВНИЗ индикатора iCrossAD
datetime       Last_Arrow_Buy_time;               //Переменная для записи времени стрелки
               
double         Buf_Arrow_Buy[], Last_Arrow_Buy_volume, Last_Arrow_Buy_index;
datetime       Last_Arrow_Sell_time;
   
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   ArraySetAsSeries(Buf_Arrow_Buy, true);
   ArraySetAsSeries(Buf_Arrow_Sell, true);
//---
   CrossAD = iCustom(asymbol.Name(), _Period, "iCrossAD",InpPeriodFind,InpUnheckedBars,InpPeriodIND);
   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()
  {
  
   string direction = "no information";
   switch(iCustom_iCrossAD(InpPeriodFind))
      {
      case Direction_BUY: direction = "BUY";
         break;
      case Direction_SELL: direction = "SELL";
         break;
      case Direction_FLAT: direction = "FLAT";
         break;
      case WRONG_VALUE: direction = "no information";
         break;   
      }
   Comment("-------------------------", 
            "\n Last_Arrow_Buy_volume     = ",Last_Arrow_Buy_volume,
            "\n Last_Arrow_Buy_index        = ",Last_Arrow_Buy_index,
            "\n Last_Arrow_Buy_time         = ",Last_Arrow_Buy_time,
            "\n ---------------------- ",
            "\n Last_Arrow_Sell_volume     = ",Last_Arrow_Sell_volume,
            "\n Last_Arrow_Sell_index        = ",Last_Arrow_Sell_index,
            "\n Last_Arrow_Sell_time         = ",Last_Arrow_Sell_time,
            "\n ---------------------- ",
            "\n Indicator_Direction             = ",direction
            ); 
  }
//+------------------------------------------------------------------+
int iCustom_iCrossAD(uint PeriodFind) 
  { 
   Indicator_Direction direct = Direction_FLAT;
   
   if (CopyBuffer(CrossAD, 1, 0, PeriodFind, Buf_Arrow_Buy) != PeriodFind)
      {  
         Print("НЕ удалось правильно скопировать данные из 1-го буфера индикатора iCrossAD, error code %d",GetLastError());
         return(WRONG_VALUE);
      }
         for(int n=0; n<(int)PeriodFind; n++)
            {
               if(n==0)
                  Print("Last_Arrow_Buy_index n==",n," Last_Arrow_Buy_time = ",iTime(_Symbol,0,n));
               if(Buf_Arrow_Buy[n]==EMPTY_VALUE)
                  Print("Last_Arrow_Buy_index n==",n," Last_Arrow_Buy_time = ",iTime(_Symbol,0,n));
               if(Buf_Arrow_Buy[n]!=EMPTY_VALUE)
               {
                  Last_Arrow_Buy_volume = iOpen(_Symbol,_Period,n);
                  Last_Arrow_Buy_time   = iTime(_Symbol,0,n);
                  Last_Arrow_Buy_index  = n;
                  Print("Last_Arrow_Buy_volume = ",Last_Arrow_Buy_volume,", Last_Arrow_Buy_index = ",Last_Arrow_Buy_index,", Last_Arrow_Buy_time = ",Last_Arrow_Buy_time);
                  break;
               }   
            }
         
   if (CopyBuffer(CrossAD, 2, 0, PeriodFind, Buf_Arrow_Sell) != PeriodFind)
      {  
         Print("НЕ удалось правильно скопировать данные из 2-го буфера индикатора iCrossAD, error code %d",GetLastError());
         return(WRONG_VALUE);
      }
         for(int n=0; n<(int)PeriodFind; n++)
            {
               if(n==0)
                  Print("Last_Arrow_Sell_index n==",n," Last_Arrow_Sell_time = ",iTime(_Symbol,0,n));
               if(Buf_Arrow_Sell[n]==EMPTY_VALUE)
                  Print("Last_Arrow_Sell_index n==",n," Last_Arrow_Sell_time = ",iTime(_Symbol,0,n));
               if(Buf_Arrow_Sell[n]!=EMPTY_VALUE)
               {
                  Last_Arrow_Sell_volume = iOpen(_Symbol,_Period,n);
                  Last_Arrow_Sell_time   = iTime(_Symbol,0,n);
                  Last_Arrow_Sell_index  = n;
                  Print("Last_Arrow_Sell_volume = ",Last_Arrow_Sell_volume,", Last_Arrow_Sell_index = ",Last_Arrow_Sell_index,", Last_Arrow_Sell_time = ",Last_Arrow_Sell_time);
                  break;
               }
            }
   if(Last_Arrow_Buy_index < Last_Arrow_Sell_index)direct = Direction_BUY;
      else if(Last_Arrow_Buy_index > Last_Arrow_Sell_index)direct = Direction_SELL;
         else direct = Direction_FLAT;         
   return(direct); 
      //return(WRONG_VALUE); 
  }
//+------------------------------------------------------------------+
File:
iCrossAD.mq5  49 kb
 
Salve, il mio Expert Advisor ha una funzione per cancellare gli ordini in sospeso quando un altro ordine si innesca. Come posso prescrivere nei parametri esterni di poter disabilitare questa funzione? Molte grazie in anticipo.
File:
ths42o20.txt  1 kb
 

Ciao!

Ho convertito l'indicatore da MT4 a MT5. Voglio usare l'indicatore come filtro aggiuntivo.

Sto studiando solo MT5. Ma non riesco a trovare l'errore. Le mie riflessioni МТ4 e МТ5 sono diverse.

Ho una richiesta agli esperti - per favore aiutatemi a trovare un errore nel file *.mql5.

Sto allegando il codice sorgente.

Vi sono molto, molto grato per il vostro aiuto.

File:
ReVoIn.mq4  4 kb
ReVoIn.mq5  11 kb
 
Priffekt:
Ciao, ho una funzione nel mio EA per cancellare gli ordini pendenti quando un altro ordine si innesca. Come posso prescrivere nei parametri esterni di poter disabilitare questa funzione? Molte grazie in anticipo.
DeleteOppositeOrders();
void DeleteOppositeOrders() {
  bool fd, fep1, fep2;

  fep1=ExistPosition(1);
  fep2=ExistPosition(2);

  for (int i=OrdersTotal()-1; i>=0; i--) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()==Symbol()) {
        fd=False;
        if (OrderType()==OP_BUYSTOP && OrderMagicNumber()== Magik) {
          if (fep2) fd=OrderDelete(OrderTicket());
        }
        if (OrderType()==OP_SELLSTOP && OrderMagicNumber()== Magik) {
          if (fep1) fd=OrderDelete(OrderTicket());
        }
        if (fd && UseSound) PlaySound(NameFileSound);
      }
    }
  }
}
bool ExistPosition(int mn) {
  bool Exist=False;
  for (int i=0; i<OrdersTotal(); i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()==Symbol() && OrderMagicNumber()== Magik) {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          Exist=True; break;
        }
      }
    }
  }
  return(Exist);
}

Questo è il tuo codice, è meglio attaccare in questo modo.

 

Certo, non sono molto adatto al ruolo di consigliere, ma il compito sembra non essere difficile.

Notate che non entrerò nel vostro codice in sé, c'è un sacco di polemica, anche per me (dummies), a partire dal fatto che la vostra funzione è di tipo void. Questo tipo viene utilizzato sia per indicare che la funzione non restituisce un valore, o come parametro di una funzione indica l'assenza di parametri. E avete return(Exist) alla fine del vostro codice;

Dichiarate una variabile di ingresso, scrivetela come parametro per la vostra funzione e uscite dalla funzione se impostate 'questa variabile su False.

 
input bool On_Off = true;
DeleteOppositeOrders(On_Off);
void DeleteOppositeOrders(bool on_off) {

  if(on_off==false)return;

  bool fd, fep1, fep2;

  fep1=ExistPosition(1);
  fep2=ExistPosition(2);

  for (int i=OrdersTotal()-1; i>=0; i--) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()==Symbol()) {
        fd=False;
        if (OrderType()==OP_BUYSTOP && OrderMagicNumber()== Magik) {
          if (fep2) fd=OrderDelete(OrderTicket());
        }
        if (OrderType()==OP_SELLSTOP && OrderMagicNumber()== Magik) {
          if (fep1) fd=OrderDelete(OrderTicket());
        }
        if (fd && UseSound) PlaySound(NameFileSound);
      }
    }
  }
}
bool ExistPosition(int mn) {
  bool Exist=False;
  for (int i=0; i<OrdersTotal(); i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()==Symbol() && OrderMagicNumber()== Magik) {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          Exist=True; break;
        }
      }
    }
  }
  return(Exist);
}
 
Priffekt:
Ciao, ho nel mio EA la funzione per cancellare gli ordini pendenti quando un altro ordine si innesca. Come posso prescrivere nei parametri esterni che questa funzione possa essere disabilitata. Molte grazie in anticipo.

Trova tutti i False e True nel testo del tuo codice. Sostituiteli con falso e vero. Questa lingua è sensibile alle maiuscole e alle minuscole.

 
Sergey Voytsekhovsky:

Trova tutti i False e True nel testo del tuo codice. Sostituiteli con falso e vero. Questa lingua è sensibile alle maiuscole e alle minuscole.

Buon pomeriggio, ho cambiato tutti i valori, ma sono interessato alla possibilità di disabilitare la funzione stessa nelle impostazioni di Expert Advisor.
DeleteOppositeOrders(); void DeleteOppositeOrders() { bool fd, fep1, fep2; fep1=ExistPosition(1); fep2=ExistPosition(2); for (int i=OrdersTotal()-1; i>=0; i--) { se (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { se (OrderSymbol()==Symbol()) { fd=falso; if (OrderType()==OP_BUYSTOP && OrderMagicNumber()== Magik) { if (fep2) fd=OrderDelete(OrderTicket()); } if (OrderType()==OP_SELLSTOP && OrderMagicNumber()== Magik) { if (fep1) fd=OrderDelete(OrderTicket()); } if (fd && UseSound) PlaySound(NameFileSound); } } } bool ExistPosition(int mn) { bool Exist=false; for (int i=0; i<OrdersTotal(); i++) { se (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol()==Symbol() && OrderMagicNumber()== Magik) { if (OrderType()==OP_BUY || OrderType()==OP_SELL) { Exist=true; break; } } } return(Exist); }
Motivazione: