Errors, bugs, questions - page 585

 
Can I use trading signal modules separately from Wizard EAs? For testing purposes, I wrote


#include <Expert\Signal\SignalMA.mqh>


CSignalMA  SignalMA;
int        TickCount;
string     Str;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   TickCount=0;
 
   SignalMA.Symbol(Symbol());
   SignalMA.Period(PERIOD_H1);
   SignalMA.Weight(0.5);
 
   SignalMA.PeriodMA(20);
   SignalMA.Shift(0);
   SignalMA.Method(MODE_SMA);
   SignalMA.Applied(PRICE_CLOSE);

 
   return(0);
 
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
 
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
 
   TickCount++;
   Str = "LongCondition  = " + IntegerToString(SignalMA.LongCondition())+"; "+IntegerToString(TickCount)+ "\n";
   Str = Str + "ShortCondition = " + IntegerToString(SignalMA.ShortCondition())+"; "+IntegerToString(TickCount);
   Comment(Str);
 
  }
//+------------------------------------------------------------------+

But what is shown in bold is not in CSignalMA class, but it compiles well, when I try to place it on the symbol it gives out


2011.11.29 15:36:27 1234 (EURUSD,M1) CExpertBase::Period: changing of timeframe is forbidden
2011.11.29 15:36:27 1234 (EURUSD,M1) CExpertBase::Symbol: changing of symbol is forbidden

How do I change symbol and timeframe for standard trading signals?
Использование прямого и обратного преобразований Фишера для анализа рынков в MetaTrader 5
Использование прямого и обратного преобразований Фишера для анализа рынков в MetaTrader 5
  • 2011.08.16
  • investeo
  • www.mql5.com
Функция распределения рыночных данных не является гауссовой, скорее она похожа на распределение синусоподобной волны. Поскольку большинство индикаторов базируются на предположении о нормальном распределении цен, их нужно "скорректировать". Решением является использование преобразования Фишера, которое преобразует данные таким образом, чтобы они имели распределение, близкое к нормальному. В статье рассмотрена теория прямого и обратного преобразования Фишера и ее применение в трейдинге, разработан модуль торговых сигналов.
 
Konstantin83:
Can I use trading signal modules separately from Wizard EAs? For testing purposes, I wrote


#include <Expert\Signal\SignalMA.mqh>


CSignalMA  SignalMA;
int        TickCount;
string     Str;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   TickCount=0;
 
   SignalMA.Symbol(Symbol());
   SignalMA.Period(PERIOD_H1);
   SignalMA.Weight(0.5);
 
   SignalMA.PeriodMA(20);
   SignalMA.Shift(0);
   SignalMA.Method(MODE_SMA);
   SignalMA.Applied(PRICE_CLOSE);

 
   return(0);
 
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
 
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
 
   TickCount++;
   Str = "LongCondition  = " + IntegerToString(SignalMA.LongCondition())+"; "+IntegerToString(TickCount)+ "\n";
   Str = Str + "ShortCondition = " + IntegerToString(SignalMA.ShortCondition())+"; "+IntegerToString(TickCount);
   Comment(Str);
 
  }
//+------------------------------------------------------------------+

But what is shown in bold is not in CSignalMA class, but it compiles well, when I try to place it on the symbol it gives out


2011.11.29 15:36:27 1234 (EURUSD,M1) CExpertBase::Period: changing of timeframe is forbidden
2011.11.29 15:36:27 1234 (EURUSD,M1) CExpertBase::Symbol: changing of symbol is forbidden

How can I change the symbol and timeframe for the standard trading signals?
Basically, you can. But initializing the trading signals module is a whole "ritual". I'm afraid I cannot explain the whole initialization procedure "on my fingers".
 

The following code:

RectLabel* GetLabel()
{
   static bool initialized = false;
   static RectLabel label("rectlabel sample", 0, 0);
   
   if (!initialized)
   {
      Pos leftTop = {100, 100};
      Rect rect(leftTop, 100, 50);
      
      label.Move(rect);
      label.SetBGColor(clrYellowGreen);
      label.SetTooltip(" -- Yuuuu! -- ");
      
      initialized = true;
   }

   return GetPointer(label);
}

Calls the constructor for label each time the function is called.

Документация по MQL5: Основы языка / Функции / Вызов функции
Документация по MQL5: Основы языка / Функции / Вызов функции
  • www.mql5.com
Основы языка / Функции / Вызов функции - Документация по MQL5
 

With the following code: in the first case the indicator is set, in the second case it is not (switched with slashes).

#include <Charts\Chart.mqh>
CChart cc;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
   int f_h=iFractals(_Symbol,_Period);
   
   if (f_h==INVALID_HANDLE) {Print("Ошибка создания индикатора.");return(-1);}
   
   ChartIndicatorAdd(0,0,f_h);   // устанавливает индикатор
   
   //cc.IndicatorAdd(0,f_h);     // НЕ устанавливает индикатор
   
   if(GetLastError()>0) {Print("Ошибка  (",GetLastError(),") ");} ResetLastError();
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick()
 { }
 

The second option in this library outputs 0. All other functions seem to work.

#include <Trade\SymbolInfo.mqh>
CSymbolInfo si;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
   Print (SymbolInfoDouble("EURUSD",SYMBOL_BID)); // все правильно
   
   si.Name("EURUSD");
   Print (si.Bid());            // выводит 0
   
   if(GetLastError()>0) {Print("Ошибка  (",GetLastError(),") ");} ResetLastError();
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick()
 { 
 }
 
Karlson:

For the next code: in the first case indicator is set, in the second case it is not (switched with slashes).

As far as I understand, at the moment all three parameters are mandatory.

Therefore, you must specify the window number (variants: 0 - main window, ChartIndicatorsTotal() - new window, 0 toChartIndicatorsTotal()-1 - an existing window).

That's what does not give out errors is not good.

Karlson:

For this library for the second option outputs 0. All other functions seem to work.

Most likely before getting the price you should use refreshes (at least RefreshRates).

The right variant should look like this

  si.Name("EURUSD");
  si.Refresh();
  si.RefreshRates();
  Print(si.Bid());
 

Thank you. It did work with Bid, after specifying refresh.

But the indicator output, using the library, requires 2 parameters, a subwindow and a handle. Otherwise it says the number of parameters is wrong. I can't figure it out, because the library uses the same ChartIndicatorAdd, so it works directly, but calling through the library does not.

Документация по MQL5: Операции с графиками / ChartIndicatorAdd
Документация по MQL5: Операции с графиками / ChartIndicatorAdd
  • www.mql5.com
Операции с графиками / ChartIndicatorAdd - Документация по MQL5
 
Karlson:

Thank you. It did work with Bid, after specifying refresh.

But the indicator output, using the library, requires 2 parameters, a subwindow and a handle. Otherwise it says the number of parameters is wrong. I can't figure it out, because the library uses the same ChartIndicatorAdd, so it works directly, but calling through the library does not.

Using the library requires 2 parameters. Chart and subwindow.
 
uncleVic:
Using the library requires 2 parameters. Chart and subwindow.

Without a Handle? And how will the system know what turntable to use? ..So far I've trusted what's written :) The substrate and the handle.

 
Karlson:

Without a handle? How will the system know which indicator to use? I have trusted the texts so far :) Subwindow and handle.

About the library (from class help)

IndicatorAdd

Adds an indicator with the specified handle to the specified chart window.

bool  IndicatorAdd(
   int   sub_win         // номер подокна
   int   handle          // хэндл индикатора
   );

Regarding the ChartIndicatorAdd direct work.

ChartIndicatorAdd

Adds an indicator with the specified handle to the specified chart window.

bool  ChartIndicatorAdd(
   long  chart_id,                 // идентификатор графика
   int   sub_window                // номер подокна
   int   indicator_handle          // хэндл индикатора
   );

As for the CChart class.

In order to avoid unnecessary questions, we try to follow three basic rules:

1. We look at the source code, if something is not clear refer to the documentation (the source code will always tell the "truth", but the documentation can also lie);

2. If OOP implementation is important to us, we start with a description of a particular class and go as far as "direct implementers". If "real work" is important, OOP should be studied last (downward/upward examination of code);

3. if after reading the documentation and sources something is not clear, we go to the forum.

Directly on the implementation of the IndicatorAdd method in a class

If you look at source code it becomes clear that method gets subwindow and handle (as noted in help), and the third parameter is taken from data stored in the class itself (I mean the graph ID).

class CChart : public CObject
  {
protected:
   long  m_chart_id; // chart identifier
public:
   //methods for working with indicators
   bool  IndicatorAdd(int subwin,int handle);
  }

bool CChart::IndicatorAdd(int subwin,int handle)
  {
//checking (проверка корректности идентификатора графика)
   if(m_chart_id<=0) return(false);
//Непосредственно в обработку выдаются три параметра
   return(ChartIndicatorAdd(m_chart_id,subwin,handle));
  }