Perguntas de um "boneco" - página 253

 
lucky_teapot:

Cavalheiros, poderiam dizer-me por favor porque é que o meu testador usa apenas metade de um dos 4 núcleos no teste?


Quando se testa apenas 1/8 do CPU está completamente carregado, não é bom.

É terrivelmente lento...

Obrigado.

se se refere ao teste com visualização - isso parece estar bem

se se refere à execução única - então 1 processador é utilizado para 1 execução

Se estiver a testar uma estratégia com várias passagens - não pode passar sem 1 imagem de ecrã das suas CPUs, deve pelo menos fazer uma imagem de ecrã durante o teste

 

Pela primeira vez, tentei converter um indicador de MQL4 para MQL5 de acordo com o artigo deste fórum, mas não consigo terminar.

Não consigo ultrapassar os últimos erros.

https://www.mql5.com/ru/articles/66

Por favor, diga-me o que mais precisa

//+------------------------------------------------------------------+
//|                                                           FT.mq5 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Fisher
#property  indicator_label1  "Fisher"
#property  indicator_type1   DRAW_LINE
#property  indicator_color1  clrRed
#property  indicator_style1  STYLE_SOLID
#property  indicator_width1  1

#include <mql4_2_mql5.mqh>
//--- input parameters
input  ENUM_APPLIED_PRICE Mode =PRICE_CLOSE;
input int      StochPeriod=21;
int StochMode = 0;
int SmoothType1 = 3;
int SmoothPeriod1 = 4;
double K = 1;
int SmoothType2 = 3;
int SmoothPeriod2 = 4;
int Buffers = 0;
int DrawBegin = 0;


//--- indicator buffers
double FisherBuffer[];
double Stoch[];
double Value1[];
double F[];

//int init() 
//{
//   if (StochPeriod < 3) 
 //     StochPeriod = 3;
//   drawBegin = StochPeriod;      
  // initBuffer(Fisher, "Fisher", DRAW_LINE);
  // initBuffer(Value1);
   //initBuffer(stoch);
  // initBuffer(f);
  // IndicatorBuffers(buffers);
  // string name = "FT("+PriceMode+","+StochPeriod+","+StochMode+","
  //    +SmoothType1+","+SmoothPeriod1+","
  //    +DoubleToStr(k,2)+","+SmoothType2+","+SmoothPeriod2+")";
  //IndicatorShortName(name);
  // SetIndexLabel(0,name);
 //  return (0);
//}

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,FisherBuffer,INDICATOR_DATA);
SetIndexBuffer(1,Value1,INDICATOR_DATA);
SetIndexBuffer(2,Stoch,INDICATOR_DATA);
SetIndexBuffer(3,F,INDICATOR_DATA);
   
    
InitMql4();

   ArraySetAsSeries(FisherBuffer,true);
ArraySetAsSeries(Value1,true);
ArraySetAsSeries(Stoch,true);
ArraySetAsSeries(F,true);
   
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
  int bars=MQL4Run(rates_total,prev_calculated);
//---
  start(bars,
      CountedMQL4,
      FisherBuffer,
      Stoch,
      Value1,
      F,
      Mode,
      StochPeriod,
      StochMode,
      SmoothType1,
      SmoothPeriod1,
      K,
      SmoothType2,
      SmoothPeriod2,
      Buffers,
      DrawBegin); 
//--- return value of prev_calculated for next call

   return(rates_total);
   }
   //+--------------------+------------------+
//|              MQL4  | MQL5             |
//+--------------------+------------------+
//|IndicatorCounted()  | prev_calculated  |
//|              Bars  | rates_total      |
//|              iMA(  | iMAMql4(         |
//|       iMAOnArray(  | iMAOnArrayMql4(  |
//+--------------------+------------------+ 
      int start(int rates_total,
         int prev_calculated, 
         double &fisher[],
         double &stoch[],
         double &value1[],
         double &f[],
         int mode,
         int stochPeriod,
         int stochMode,
         int smoothType1,
         int smoothPeriod1,
         double k,
         int smoothType2,
         int smoothPeriod2,
         int buffers,
         int drawBegin)


{
   if (rates_total <= stochPeriod)  
      return (0);
   int countedBars = prev_calculated;
   if (countedBars < 0) 
      return (-1);
   if (countedBars > 0) 
      countedBars--;
   int s, limit = rates_total - countedBars - 1;
   for (s = limit; s >= 0; s--) 
   {
      double price = P(s);
      double MaxH = price;
      double MinL = price;
      for (int i = 0; i < stochPeriod; i++) 
      {
         if (stochMode == 0)
         {
         price = P(s + i);
         if (price > MaxH) 
            MaxH = price;
         if (price < MinL) 
            MinL = price;
         }
         else
         {
            MaxH = MathMax(MaxH,High[s+i]);
            MinL = MathMin(MinL,Low[s+i]);
         }
      }
      stoch[s] = 2.0 * ((P(s) - MinL) / (MaxH - MinL) - 0.5);
   }
  smooth(stoch,value1,smoothType1,smoothPeriod1,limit);
   for (s = limit; s >= 0; s--)
   {
      f[s] = MathLog((1.0 + val(Value1[s])) / (1.0 - val(Value1[s]))) / 2.0;
   }    
   smooth(f,fisher,smoothType2,smoothPeriod2,limit);
   return (0);
}

double P(int index) 
{
   return (iMAMql4(NULL,0,1,0,MODE_SMA,Mode,index));
}

//void initBuffer(double &array[], string label = "", 
 //  int type = DRAW_NONE, int arrow = 0, int style = EMPTY, 
 //  int width = EMPTY, color clr = CLR_NONE) 
//   SetIndexBuffer(buffers, array);
 //  SetIndexLabel(buffers, label);
//   SetIndexEmptyValue(buffers, EMPTY_VALUE);
//   SetIndexDrawBegin(buffers, drawBegin);
//   SetIndexShift(buffers, 0);
//   SetIndexStyle(buffers, type, style, width);
//  SetIndexArrow(buffers, arrow);
 //  buffers++;
//}

double val(double v)
{
   return (MathMax(MathMin(K * v,0.999),-0.999));
}


void smooth(int rates_total, double &inp[], double &out[], int type, int len, int limit)
{
   switch(type)
   {
      case 0:
         HTMA(rates_total-StochPeriod,len,inp,out);
         break;
      case 1:
        // HMA(len,inp,out);
         break;
      case 2:
        // LWMA(len,inp,out);
         break;
      case 3:
        // EMA(len,inp,out);
         break;
   }
}

void HTMA(int N,int HMALen,double &onput[],double &output[])
{
   double ma1,ma2,hma,mix,mixprime;
   ma1=onput[N-1];
   ma2=ma1;
   mix=3.0/(2.0 + HMALen);
   mixprime=1.0-mix;
   for(int i=N-2;i>=0;i--)
   {
      ma1=mixprime*ma1 + mix*onput[i];
      ma2=mixprime*ma2 + mix*ma1;
      output[i]=3.0*ma1-2.0*ma2;
   }
}

void HMA(int rates_total, int per, double &array[], double &out[])
{
   double tmp[];
   ArrayResize(tmp,rates_total);
   ArraySetAsSeries(tmp,true);
   for(int i = rates_total-1; i >= 0; i--)
   {
      tmp[i] =
         2*iMAOnArrayMql4(array,0,per/2,0,MODE_LWMA,i)
         -iMAOnArrayMql4(array,0,per,0,MODE_LWMA,i);
   }
   for(int i = rates_total-1; i >= 0; i--)
   {
      out[i] = iMAOnArrayMql4(tmp,0,MathSqrt(per),0,MODE_LWMA,i);
   }
}

void LWMA(int rates_total, int len, double &inp[], double &out[])
{
   for(int i = rates_total-1; i >= 0; i--)
   {
      out[i] = iMAOnArrayMql4(inp,0,len,0,MODE_LWMA,i);
   }
}

void EMA(int rates_total, int len, double &inp[], double &out[])
{
   for(int i =rates_total -1; i >= 0; i--)
   {
      out[i] = iMAOnArrayMql4(inp,0,len,0,MODE_EMA,i);
   }
}

  
//+------------------------------------------------------------------+
//| TradeTransaction function                                        |
//+------------------------------------------------------------------+
void OnTradeTransaction(const MqlTradeTransaction& trans,
                        const MqlTradeRequest& request,
                        const MqlTradeResult& result)
  {
//---
   
  }
//+------------------------------------------------------------------+


Перенос индикаторов из MQL4 в MQL5
Перенос индикаторов из MQL4 в MQL5
  • 2010.07.21
  • Vasily
  • www.mql5.com
Статья посвящена особенностям переноса в MQL5 ценовых конструкций, используемых в индикаторах, написанных на MQL4. Для упрощения переноса индикаторных расчетов из MQL4 в MQL5 предложена библиотека функций mql4_2_mql5.mqh, применение которой рассмотрено на примере переноса индикаторов MACD, Stochastic и RSI.
Arquivos anexados:
FT.mq5  8 kb
FT.mq4  5 kb
 

Este bloco, por exemplo.

int start(int rates_total,
         int prev_calculated, 
         double &fisher[],
         double &stoch[],
         double &value1[],
         double &f[],
         int mode,
         int stochPeriod,
         int stochMode,
         int smoothType1,
         int smoothPeriod1,
         double k,
         int smoothType2,
         int smoothPeriod2,
         int buffers,
         int drawBegin)


{
   if (rates_total <= stochPeriod)  
      return (0);
   int countedBars = prev_calculated;
   if (countedBars < 0) 
      return (-1);
   if (countedBars > 0) 
      countedBars--;
   int s, limit = rates_total - countedBars - 1;
   for (s = limit; s >= 0; s--) 
   {
      double price = P(s);
      double MaxH = price;
      double MinL = price;
      for (int i = 0; i < stochPeriod; i++) 
      {
         if (stochMode == 0)
         {
         price = P(s + i);
         if (price > MaxH) 
            MaxH = price;
         if (price < MinL) 
            MinL = price;
         }
         else
         {
            MaxH = MathMax(MaxH,High[s+i]);
            MinL = MathMin(MinL,Low[s+i]);
         }
      }
      stoch[s] = 2.0 * ((P(s) - MinL) / (MaxH - MinL) - 0.5);
   }
  smooth(stoch,value1,smoothType1,smoothPeriod1,limit);

///'stoch' - parameter conversion not allowed   FT.mq5  173     10

   for (s = limit; s >= 0; s--)
   {
      f[s] = MathLog((1.0 + val(Value1[s])) / (1.0 - val(Value1[s]))) / 2.0;
   }    
   smooth(f,fisher,smoothType2,smoothPeriod2,limit);

///'f' - parameter conversion not allowed       FT.mq5  178     11

   return (0);
}

Colocoas mensagens do compilador depois das linhas correspondentes.

stoch, f parecem ser pré-definidos como elementos de matriz. Se eu colocar parênteses rectos depois deles, o erro salta mais longe na linha - algo como

smoothType1' - a conversão de parâmetros não é permitida FT .mq5 173 25


É apenas uma variável. Qual é o problema?

 
Agat:

Este bloco, por exemplo...

if (stochMode == 0)
         {

         }
         else
         {

         };

Tente verificar novamente a correcção do ";". por causa deles e parênteses (em falta/espuro), o erro pode "flutuar" no código.

A actualização pode ser mais fácil de escrever em 5 de uma só vez, do que utilizar bibliotecas. Será mais curto e menos problemático.

 

Sim, existe um tipo semelhante de transformação Fisher aqui na base, mas sem qualquer configuração. Precisaria pelo menos de mudar ENUM_APPLIED_PRICE, e não funciona lá.

Pode dizer-me como mudá-lo?

https://www.mql5.com/ru/code/537?source=terminal5_mql5


Индикатор Fisher Transform
Индикатор Fisher Transform
  • votos: 8
  • 2011.10.10
  • Witold Wozniak
  • www.mql5.com
Индикатор Fisher, рассчитывая минимальные и максимальные уровни цены в предыдущей истории, определяет силу и направление тренда, прогнозируя его смену.
 

Em Fisher Transform obtém-se se adicionar algumas linhas e seleccionar manualmente uma delas

//price=(high[bar]+low[bar])/2.0;
//price=(high[bar]+low[bar]+close[bar])/3.0;

//price=(high[bar]+low[bar]+close[bar]+close[bar])/4.0;

E não há rebites suficientes para inserir via Input

 
Agat:

Em Fisher Transform obtém-se se adicionar algumas linhas e seleccionar manualmente uma delas

//price=(high[bar]+low[bar])/2.0;
//price=(high[bar]+low[bar]+close[bar])/3.0;

//price=(high[bar]+low[bar]+close[bar]+close[bar])/4.0;

E não há rebites suficientes para inserir via Input

//+------------------------------------------------------------------+
//| inputs                                                           |
//+------------------------------------------------------------------+
enum var_ratio
  {
   O_HLC,                                 // Open
   O_H_LC                                 // Hight
// продолжите список
  };

input var_ratio             OHLC_var=O_HLC;            // variant
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
if(OHLC_var==O_HLC)
{};

dessa forma
 

Obrigado! Vou tentar, é claro, mas isso não é o principal. A imagem não é a mesma que no MT-4 - esse é o problema. Não tenho configurações suficientes ou o algoritmo é diferente.

 
Ou será porque há muitas mais barras na imagem inferior?
Документация по MQL5: Стандартные константы, перечисления и структуры / Константы индикаторов / Стили рисования
Документация по MQL5: Стандартные константы, перечисления и структуры / Константы индикаторов / Стили рисования
  • www.mql5.com
Стандартные константы, перечисления и структуры / Константы индикаторов / Стили рисования - Документация по MQL5
 
Agat:
Ou será porque há muitas mais barras na imagem inferior?

Se o indicador não é uma tradução de 4, porque é que a imagem deve ser a mesma, especialmente num número diferente de barras?

Verificar as fórmulas e definições. E tente contactar o autor do indicador, em discussão do indicador, talvez ele sugira algo.

Razão: