Usage of Signal-Classes

 
Hello everyone,


I tried to setup an Expert-Advisor in mql5 trading with several Indicator-Signals using the Signal-Classes from StdLib.

I've searched a lot for examples, but can only find complete Trading-Systems with objects of "CExpert" (propably just made with a wizard).

But I cannot find any simple discriptions of the proper usage of those Signal-Classes.

For Example I want to use "CSignalMACD" from "Expert/Signal/SignalMACD.mqh":

I just want to create an Object like

CSignalMACD* sm = new CSignalMACD();

and use the calculated signals, be something like:

    if     (sm.LongCondition()) buy();
    else if(sm.ShortCondition()) sell();

I know that most time I have to call some kind of calculate-method. For indicator-classes like "CiBands" it is the method "Refresh()"

Could please anybody tell me what methods I actually have to call to receive the signals?


For the Bollinger-Indicator it is easy:


#include <Indicators/Trend.mqh>
CiBands bo;

...

  bo.Create(_Symbol, PERIOD_CURRENT, 500, 0, 1.5, PRICE_CLOSE);

...

  bo.Refresh();

  upp = bo.Upper(0);

  base = bo.Base(0);

  low = bo.Lower(0);

...

This all works without Problems. I found out, that the methods "Create(...)" and "Refresh()" are essencial.

But how can I use the Signal-Classes like "CSignalRSI" in this way? Which methods do I need?
 
If it is a language provided function or object, usually the best place to find out how to use them is on their doc page.  If it is a custom built one, then you should see if the person who built it made a doc page.
 

There are 20 Classes in the folder. Each one with this headline:

//|                   Copyright 2009-2013, MetaQuotes Software Corp. |

//|                                              http://www.mql5.com |

I have searched for a long time.

All I can find are some simple descriptions on how to use a wizard to create an EA

https://www.mql5.com/en/code/262

or super-simple documentation like this one

http://barmenteros.com/mql5_reference/signal_macd.htm

I tried a lot meanwhile by analyzing code, base-classes and just testing diffrent ideas.

Seems like you have to create Objects for Open, High, Low, Close and maybe spread, volume and time.

There are the methods SetPriceSeries(...) and SetOtherSeries(...) to pass those values.

also you propably have to call InitIndicators(...) with a new Pointer to an "Indicators"-Object ...

I receive some Values from LongCondition() and ShortCondition() that way, but are the correct?

Did no one ever use those classes? Is there any documentation-site, where the proper use is discribed?

Automated Trading and Strategy Testing
Automated Trading and Strategy Testing
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
 

I work with those classes now, because that way I get some signals.

But could anybody please tell me, if this initialisation is correct?

Maybe I forgot something and use wrong signals ...

 
Did you find out how to use signal classes?
 
They mostly have boolean methods with names like CheckLongOrder which give back true if a trade is to be initiated or false if not.
Apparently you can make them yourself by inheriting a class from CExpertSignal, giving them all the function they need and wrapping the conditions of your signal into such boolean functions. Then you put your signal class into the ExpertSignal folder.

There is also an article series "techniques of the mql wizard you should know"
 

Thank you. Of course base CExpertSignal class has bool methods LongCondition() and ShortCondition(). But question is how to create object of special signal class - CSignalMACD or CSignalRSI, set init data such as Symbol, period and other params of indicator and get result. I tried to learn standart examples of experts that use CExpert and CExpertSignal classes. They just init list of signal OnInit, and after use CExpert.OnTick() method. Inside it all magic happens. I'd like to use CSignalRSI with out CExpert, but could not find out how to do it. My script code doesn't work correctly. It always return 0 as signal result. I guess I should make more inits or do it in different way.


void OnStart()
  {
   CSignalMACD       m_signal_macd;
   CSymbolInfo       m_info;
   CiOpen            m_open;
   CiHigh            m_high;
   CiLow             m_low;
   CiClose           m_close;
   CIndicators       m_indicators;

   m_signal_macd.Pattern_0(0);
   m_signal_macd.Pattern_1(0);
   m_signal_macd.Pattern_2(0);
   m_signal_macd.Pattern_3(100);
   m_signal_macd.Pattern_4(0);
   m_signal_macd.Pattern_5(0);
   m_info.Name(Symbol());                                  // Initializing the object that represents the trading symbol of the strategy
   m_signal_macd.Init(GetPointer(m_info), Period(), 10);   // Initializing the signal module by the trading symbol and timeframe
   m_signal_macd.InitIndicators(GetPointer(m_indicators)); // creating required indicators in the signal module based on the empty list of indicators m_indicators
   //m_signal_macd.EveryTick(true);                          // Testing mode
   m_signal_macd.Magic(42);                     // Magic number
   m_signal_macd.PatternsUsage(8);                         // Pattern mask
   m_open.Create(Symbol(), Period());                      // Initializing the timeseries of Open prices
   m_high.Create(Symbol(), Period());                      // Initializing the timeseries of High prices
   m_low.Create(Symbol(), Period());                       // Initializing the timeseries of Low prices
   m_close.Create(Symbol(), Period());                     // Initializing the timeseries of Close prices
   m_signal_macd.SetPriceSeries(GetPointer(m_open),        // Initializing the signal module by timeseries objects
                              GetPointer(m_high),
                              GetPointer(m_low),
                              GetPointer(m_close));
                              
   m_indicators.Refresh();
   m_signal_macd.SetDirection();
   int power_sell = m_signal_macd.ShortCondition();
   int power_buy = m_signal_macd.LongCondition();
   printf("PowerSell: " + (string)power_sell + " PowerBuy: " + (string)power_buy);
                                    
  }