CandlePattern class ?

 

Hi, all,

I have gon thorugh a article https://www.mql5.com/en/code/291 Candlepatterns, it says using of this clas in Wizard genaration, we have to create another module clas for using this.

My question is can i use this class, for my EA writing with out the help of wizard ?

by giving a code like #include <candlepatterns.mqh> from the includ file,

i am using the method of samual https://www.mql5.com/en/articles/100 for creating an EA

 

Thanks in advance

Suresh 

MQL5 Wizard - Candlestick Patterns Class
MQL5 Wizard - Candlestick Patterns Class
  • votes: 11
  • 2011.02.16
  • MetaQuotes Software Corp.
  • www.mql5.com
The class can be used for creation of trade signal classes with reversal candlestick patterns.
 
surubabs:

Hi, all,

I have gon thorugh a article https://www.mql5.com/en/code/291 Candlepatterns, it says using of this clas in Wizard genaration, we have to create another module clas for using this.

My question is can i use this class, for my EA writing with out the help of wizard ?

by giving a code like #include <candlepatterns.mqh> from the includ file,

i am using the method of samual https://www.mql5.com/en/articles/100 for creating an EA

 

Thanks in advance

Suresh 

Yes you can, but you have to include other classes neccesary to compile, not only candlepatterns.mdh.
 
angevoyageur:
Yes you can, but you have to include other classes neccesary to compile, not only candlepatterns.mdh.

I again started to work with candle patterns, i am planing to create a new class,with Bollinger Bands,

which works like, a bullish candle pattern formed outside the lower band for long entry, viceversa for short entry,

i will create a class on bands, and i call candlepattern class like  #include <candlepatterns.mqh>,

then in the long condition only i call again the patterns. does it work sir?

please help.

Thanks in advance 

Create Your Own Trading Robot in 6 Steps!
Create Your Own Trading Robot in 6 Steps!
  • 2012.03.22
  • MetaQuotes Software Corp.
  • www.mql5.com
If you don't know how trade classes are constructed, and are scared of the words "Object Oriented Programming", then this article is for you. In fact, you do not need to know the details to write your own module of trading signals. Just follow some simple rules. All the rest will be done by the MQL5 Wizard, and you will get a ready-to-use trading robot!
 
surubabs:

I again started to work with candle patterns, i am planing to create a new class,with Bollinger Bands,

which works like, a bullish candle pattern formed outside the lower band for long entry, viceversa for short entry,

i will create a class on bands, and i call candlepattern class like  #include <candlepatterns.mqh>,

then in the long condition only i call again the patterns. does it work sir?

please help.

Thanks in advance 

Why not ? Try it.
 
angevoyageur:
Why not ? Try it.

Hei Sir, i tryed it today but have some problems, but i couldint figreout wats the issue.

is it the problem with my class or in my derived ea from this.

Please check my class wether its correct or not,if some missing please guide me.

//+------------------------------------------------------------------+
//|                                                Rock_Patterns.mqh |
//|                        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"
#include "CandlePatterns.mqh" 
// wizard description start
//+------------------------------------------------------------------+
//| Description of the class                                         |
//| Title=Rock_Patterns                                              |
//| Type=SignalAdvanced                                              |
//| Name=Rock_Patterns                                               |
//| Class=RockPatterns                                               |
//| Page=                                                            |
//| Parameter=param1,int,9                                           |
//| Parameter=BBPeriod,int,20,Periof of Bollinger Bands              |
//| Parameter=BBDeviation,double,2.000,Deviation of Bollinger Bands  |
//| Parameter=BBshift,int,0,Time shift                               |
//| Parameter=BBApplied,ENUM_APPLIED_PRICE,PRICE_CLOSE               |
//| Parameter=paramN,int,13                                          |
//| Parameter=MAPeriod,int,12                                        |
//+------------------------------------------------------------------+
// wizard description end
//+------------------------------------------------------------------+

class Rock_Patterns : public CCandlePattern
  {
private: CiBands           m_Bands;
         //--- Configurable module parameters
         int               m_ma_period;
         int               m_ma_shift;
         ENUM_MA_METHOD    m_Method;
         double            m_deviation;
         ENUM_APPLIED_PRICE m_applied;
         string m_Name;
         //--- adjusted parameters
         

public:
                     Rock_Patterns();
                    ~Rock_Patterns();
        //--- methods of setting adjustable parameters
     void              MaPeriod(int value)               { m_ma_period=value;        }
     void              MaShift(int value)                { m_ma_shift=value;         }
     void              Deviation(double value)           {m_deviation=value;         }
     void              Applied(ENUM_APPLIED_PRICE value) { m_applied=value;          }              
     //--- Checking correctness of input data
     bool              ValidationSettings(void); 
     //--- Creating indicators and timeseries for the module of signals
     bool              InitIndicators(CIndicators *indicators);
     //--- Creating BB indicators
     bool              InitBands(CIndicators *indicators);
     //--- methods of access to indicator data
     double            Base(const int index) const  {return(m_Bands.Base(index)); }
     double            Upper(const int index) const {return(m_Bands.Upper(index));}
     double            Lower(const int index) const {return(m_Bands.Lower(index));}
     //--- checking of trade signals
    virtual bool      CheckOpenLong(double &price,double &sl,double &tp,datetime &expiration);
    virtual bool      CheckCloseLong(double &price);
    virtual bool      CheckOpenShort(double &price,double &sl,double &tp,datetime &expiration);
    virtual bool      CheckCloseShort(double &price);

                 
  };
//+------------------------------------------------------------------+
//| Constructor                                                      |
//+------------------------------------------------------------------+
Rock_Patterns::Rock_Patterns():m_ma_period(20),
                           m_ma_shift(0),
                           m_deviation(2.000),
                           m_applied(PRICE_CLOSE)
  {
  //--- initialization of protected data
   m_used_series=USE_SERIES_OPEN+USE_SERIES_HIGH+USE_SERIES_LOW+USE_SERIES_CLOSE;
  }
//+------------------------------------------------------------------+
//|  Destructor                                                      |
//+------------------------------------------------------------------+
Rock_Patterns::~Rock_Patterns()
  {
  }
//+------------------------------------------------------------------------------+
//| Validation settings protected data. and returns true if everything is OK     |
//+------------------------------------------------------------------------------+
bool Rock_Patterns:: ValidationSettings()
  {
//--- call of ValidationSettings of parent CCandlePattern class
   if(!CCandlePattern::ValidationSettings()) return(false);

//--- initial data checks Bands
   if(m_ma_period<=0)
     {
      printf(__FUNCTION__+": Bands period must be greater than 0");
      return(false);
     }   
//--- All checks are completed, everything is ok
   return true;
  }
//+------------------------------------------------------------------+
//| Creates indicators                                               |
//| Input:  a pointer to a collection of indicators                  |
//| Output: true if successful, otherwise false                      |
//+------------------------------------------------------------------+
bool Rock_Patterns::InitIndicators(CIndicators* indicators)
  {
//--- check pointer
   if(indicators==NULL)
      return(false);
//--- call of InitIndicators of parent CCandlePattern class
   if(!CCandlePattern::InitIndicators(indicators)) return(false);   
//--- create and initialize BB indicator
   if(!InitBands(indicators))
      return(false);
//--- ok
   return(true);
  }
//+------------------------------------------------------------------+
//| Initialize BB indicators.                                        |
//+------------------------------------------------------------------+
bool Rock_Patterns::InitBands(CIndicators *indicators)
  {
//--- check pointer
   if(indicators==NULL)
      return(false);
//--- add object to collection
   if(!indicators.Add(GetPointer(m_Bands)))
     {
      printf(__FUNCTION__+": error adding object");
      return(false);
     }
//--- initialize object
   if(!m_Bands.Create(m_symbol.Name(),m_period,m_ma_period,m_ma_shift,m_deviation,m_applied))
     {
      printf(__FUNCTION__+": error initializing object");
      return(false);
     }
//--- ok
   return(true);
  }
//+------------------------------------------------------------------+
//| Checking condition of long position opening                      |
//+------------------------------------------------------------------+
bool Rock_Patterns::CheckOpenLong(double &price,double &sl,double &tp,datetime &expiration)
  {
   int result=0;
   int idx   =StartIndex();
   double close=Close(idx);
   double Base=Base(idx);
   double Upper=Upper(idx);
   double Lower=Lower(idx);
//--- check conditions to open long position
//--- it's better to use this code in addition to indicator's checking
//--- for example, let's check formation of "3 white soldiers" pattern:
   if (CheckPatternAllBullish()&& (Close(1)<Lower(1)))result=80; 
//--- check conditions of short position closing 
   if(Close(1)>Upper(1)) 
      result=40; 
//--- return the result 
   return(result); 
  } 
//-------------------------------------------------------------------+
//| Checking condition of short position opening                     |
//+------------------------------------------------------------------+
bool Rock_Patterns::CheckOpenShort(double &price,double &sl,double &tp,datetime &expiration)
  {
   int result=0;
   int idx   =StartIndex();
   double close=Close(idx);
   double Base=Base(idx);
   double Upper=Upper(idx);
   double Lower=Lower(idx);
//--- check conditions to open short position
//--- it's better to use this code in addition to indicator's checking
//--- for example, let's check formation of "3 black crows" pattern:
    if(CheckPatternAllBearish() && Close(1)<Upper(1))result=80; 
//--- check conditions of long position closing 
   if(Close(1)<Lower(1)) 
      result=40; 
//--- return the result 
   return(result); 
  } 

//+------------------------------------------------------------------+ 

i am uploding my derived ea from this class.

//+------------------------------------------------------------------+
//|                                                 RockPatterns.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"
//+------------------------------------------------------------------+
//| Include                                                          |
//+------------------------------------------------------------------+
#include <Expert\Expert.mqh>
//--- available signals
#include <Expert\MySignals\Rock_Patterns.mqh>
//--- available trailing
#include <Expert\Trailing\TrailingFixedPips.mqh>
//--- available money management
#include <Expert\Money\MoneyFixedLot.mqh>
//+------------------------------------------------------------------+
//| Inputs                                                           |
//+------------------------------------------------------------------+
//--- inputs for expert
input string             Expert_Title                  ="RockPatterns"; // Document name
ulong                    Expert_MagicNumber            =2712;           // 
bool                     Expert_EveryTick              =false;          // 
//--- inputs for main signal
input int                Signal_ThresholdOpen          =10;             // Signal threshold value to open [0...100]
input int                Signal_ThresholdClose         =10;             // Signal threshold value to close [0...100]
input double             Signal_PriceLevel             =0.0;            // Price level to execute a deal
input double             Signal_StopLevel              =50.0;           // Stop Loss level (in points)
input double             Signal_TakeLevel              =50.0;           // Take Profit level (in points)
input int                Signal_Expiration             =4;              // Expiration of pending orders (in bars)
input int                Signal__param1                =9;              // Rock_Patterns(9,20,2.000,0,...) 
input int                Signal__BBPeriod              =20;             // Rock_Patterns(9,20,2.000,0,...) Periof of Bollinger Bands
input double             Signal__BBDeviation           =2.000;          // Rock_Patterns(9,20,2.000,0,...) Deviation of Bollinger Bands
input int                Signal__BBshift               =0;              // Rock_Patterns(9,20,2.000,0,...) Time shift
input ENUM_APPLIED_PRICE Signal__BBApplied             =PRICE_CLOSE;    // Rock_Patterns(9,20,2.000,0,...) 
input int                Signal__paramN                =13;             // Rock_Patterns(9,20,2.000,0,...) 
input int                Signal__MAPeriod              =12;             // Rock_Patterns(9,20,2.000,0,...) 
input double             Signal__Weight                =1.0;            // Rock_Patterns(9,20,2.000,0,...) Weight [0...1.0]
//--- inputs for trailing
input int                Trailing_FixedPips_StopLevel  =30;             // Stop Loss trailing level (in points)
input int                Trailing_FixedPips_ProfitLevel=50;             // Take Profit trailing level (in points)
//--- inputs for money
input double             Money_FixLot_Percent          =10.0;           // Percent
input double             Money_FixLot_Lots             =1.0;            // Fixed volume
//+------------------------------------------------------------------+
//| Global expert object                                             |
//+------------------------------------------------------------------+
CExpert ExtExpert;
//+------------------------------------------------------------------+
//| Initialization function of the expert                            |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- Initializing expert
   if(!ExtExpert.Init(Symbol(),Period(),Expert_EveryTick,Expert_MagicNumber))
     {
      //--- failed
      printf(__FUNCTION__+": error initializing expert");
      ExtExpert.Deinit();
      return(-1);
     }
//--- Creating signal
   CExpertSignal *signal=new CExpertSignal;
   if(signal==NULL)
     {
      //--- failed
      printf(__FUNCTION__+": error creating signal");
      ExtExpert.Deinit();
      return(-2);
     }
//---
   ExtExpert.InitSignal(signal);
   signal.ThresholdOpen(Signal_ThresholdOpen);
   signal.ThresholdClose(Signal_ThresholdClose);
   signal.PriceLevel(Signal_PriceLevel);
   signal.StopLevel(Signal_StopLevel);
   signal.TakeLevel(Signal_TakeLevel);
   signal.Expiration(Signal_Expiration);
//--- Creating filter RockPatterns
   RockPatterns *filter0=new RockPatterns;
   if(filter0==NULL)
     {
      //--- failed
      printf(__FUNCTION__+": error creating filter0");
      ExtExpert.Deinit();
      return(-3);
     }
   signal.AddFilter(filter0);
//--- Set filter parameters
   filter0.param1(Signal__param1);
   filter0.BBPeriod(Signal__BBPeriod);
   filter0.BBDeviation(Signal__BBDeviation);
   filter0.BBshift(Signal__BBshift);
   filter0.BBApplied(Signal__BBApplied);
   filter0.paramN(Signal__paramN);
   filter0.MAPeriod(Signal__MAPeriod);
   filter0.Weight(Signal__Weight);
//--- Creation of trailing object
   CTrailingFixedPips *trailing=new CTrailingFixedPips;
   if(trailing==NULL)
     {
      //--- failed
      printf(__FUNCTION__+": error creating trailing");
      ExtExpert.Deinit();
      return(-4);
     }
//--- Add trailing to expert (will be deleted automatically))
   if(!ExtExpert.InitTrailing(trailing))
     {
      //--- failed
      printf(__FUNCTION__+": error initializing trailing");
      ExtExpert.Deinit();
      return(-5);
     }
//--- Set trailing parameters
   trailing.StopLevel(Trailing_FixedPips_StopLevel);
   trailing.ProfitLevel(Trailing_FixedPips_ProfitLevel);
//--- Creation of money object
   CMoneyFixedLot *money=new CMoneyFixedLot;
   if(money==NULL)
     {
      //--- failed
      printf(__FUNCTION__+": error creating money");
      ExtExpert.Deinit();
      return(-6);
     }
//--- Add money to expert (will be deleted automatically))
   if(!ExtExpert.InitMoney(money))
     {
      //--- failed
      printf(__FUNCTION__+": error initializing money");
      ExtExpert.Deinit();
      return(-7);
     }
//--- Set money parameters
   money.Percent(Money_FixLot_Percent);
   money.Lots(Money_FixLot_Lots);
//--- Check all trading objects parameters
   if(!ExtExpert.ValidationSettings())
     {
      //--- failed
      ExtExpert.Deinit();
      return(-8);
     }
//--- Tuning of all necessary indicators
   if(!ExtExpert.InitIndicators())
     {
      //--- failed
      printf(__FUNCTION__+": error initializing indicators");
      ExtExpert.Deinit();
      return(-9);
     }
//--- ok
   return(0);
  }
//+------------------------------------------------------------------+
//| Deinitialization function of the expert                          |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   ExtExpert.Deinit();
  }
//+------------------------------------------------------------------+
//| "Tick" event handler function                                    |
//+------------------------------------------------------------------+
void OnTick()
  {
   ExtExpert.OnTick();
  }
//+------------------------------------------------------------------+
//| "Trade" event handler function                                   |
//+------------------------------------------------------------------+
void OnTrade()
  {
   ExtExpert.OnTrade();
  }
//+------------------------------------------------------------------+
//| "Timer" event handler function                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
   ExtExpert.OnTimer();
  }
//+------------------------------------------------------------------+
but iam geting an error

Please see the error 

Please help some one. 

 
surubabs:

Hei Sir, i tryed it today but have some problems, but i couldint figreout wats the issue.

is it the problem with my class or in my derived ea from this.

Please check my class wether its correct or not,if some missing please guide me.

i am uploding my derived ea from this class.

but iam geting an error

 

Please help some one. 

Your class is named :
  Rock_Patterns

and you try to declare :

  RockPatterns *filter0=new RockPatterns;