Download MetaTrader 5

using a functioan of a class into an expert

To add comments, please log in or register
mohsen bahrami
312
mohsen bahrami  

hi taders

i want to use function CheckCandlestickPattern() of aCandlePatterns.mqh

and i wrote

#include "aCandlePatterns.mqh" in my expert.

how can i use the functions of this class

for example

bool Buy_Condition_1=CheckCandlestickPattern(CANDLE_PATTERN_MORNING_STAR);

is not correct and the error is:

'CheckCandlestickPattern' - function not defined  .

shoud i define another class or other else?

thank you alot

Gabor Torma
2877
Gabor Torma  
mohsen_bhr:

#include "aCandlePatterns.mqh" in my expert.

Does expert found this file?

Can you attach the files?

mohsen bahrami
312
mohsen bahrami  
VincentX:

Does expert found this file?

Can you attach the files?

hi dear friend.

i attached files and  dont know how use a function of a class into an EA.

thank you

Files:
testclass.mq5 12 kb
phi nuts
2181
phi nuts  
lease don't create multiple topic asking the same question :

Here's your other topic which I have to delete :

mohsen_bhr 2012.11.14 16:38

hi traders.

i want to make an EA based on candle patterns and i have candle pattern functions in aCandlePatterns.mqh (attached below).

i called it by:

#include "aCandlePatterns.mqh"

and 

define a new 

CCandlePattern   cc;

and i want to use "CheckPatternMorningStar()" function into my EA as follows:

bool Buy_Condition_1=cc.CheckPatternMorningStar();  


is my solution correct?

when i want to test it in strategy tester , i  have an error.

please guide me .

thanks.

 

mohsen bahrami
312
mohsen bahrami  
phi.nuts:

Please don't create multiple topic asking the same question :

Here's your other topic which I have to delete :

 

hi

ok- thank you for your comment 

leandrocsj
13
leandrocsj  

Well... i had a hard time trying to answer the same question. If i try to do any similar code, i will receive an null pointer error in debug mode. Anyone knows how to solve this?

 Thanks in advance! 

Alain Verleyen
Moderator
33773
Alain Verleyen  
leandrocsj:

Well... i had a hard time trying to answer the same question. If i try to do any similar code, i will receive an null pointer error in debug mode. Anyone knows how to solve this?

 Thanks in advance! 

Post your code.
leandrocsj
13
leandrocsj  
//+------------------------------------------------------------------+
//|                                                codigo_envio.mq5  |
//|                                       Copyright 2014,Leandro C   |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014,Leandro C"
#property link      "none"
#property version   "1.00"
//--- includes
#include <Trade\Trade.mqh>
//#include <reverse_operation.mqh>
#include "acandlepatterns.mqh"
//#include <Expert\Expert.mqh>
//--- input parameters
input double   Lot=1.0; // Lotes ou contratos
input int      TakeProfit=500;   // Take Profit
input int      StopLoss=400;   // Stop Loss
// Snap Code for getting low and max for a specified period. To fix: https://www.mql5.com/en/forum/1422
double High[],Low[];
bool   buyS=true;
//+------------------------------------------------------------------+
//| Ending the indicators loading                                    |
//+------------------------------------------------------------------+
// Defining trade variable, CTrade type and setting initial BuyPosition as true
CTrade trade;
CCandlePattern test;
//CExpert ExtExpert;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
double CurrentPrice = 0;
   if(!PositionSelect(_Symbol))
      {
            {           
            if (buyS)
               trade.Buy(Lot); //Buy Position at price, at Time
            else 
               trade.Sell(Lot);
            }             
      }
   else // there is a position
      {
      if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
         {
         CurrentPrice=(SymbolInfoDouble(_Symbol,SYMBOL_BID)-PositionGetDouble(POSITION_PRICE_OPEN));
         if(CurrentPrice>=TakeProfit)
            {
            trade.PositionClose(_Symbol);
            }
         if(CurrentPrice<=-StopLoss)
            {
            trade.PositionClose(_Symbol);
            }
         else if (test.CheckPatternAllBearish() == true)
            {
            trade.PositionClose(_Symbol);
            }     
        }
      if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)
         {
         CurrentPrice=(PositionGetDouble(POSITION_PRICE_OPEN)-SymbolInfoDouble(_Symbol,SYMBOL_ASK));
         if(CurrentPrice>=TakeProfit)
            {
            trade.PositionClose(_Symbol);
            }
         if(CurrentPrice<=-StopLoss)
            {
            trade.PositionClose(_Symbol);
            }
         else if (test.CheckPatternAllBullish() == true)
            {
            trade.PositionClose(_Symbol);
            }             
      }
   }
}
//+------------------------------------------------------------------+


 

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
Files:
Rodrigo Malacarne
Moderator
10638
Rodrigo Malacarne  
leandrocsj:
//+------------------------------------------------------------------+

Hello leandrocsj,

could you please be more specific about your doubt? What exactly is the problem?

I would advise you to create a new topic for your question, instead of keep posting your problem inside this topic.

Regards,
Malacarne 

leandrocsj
13
leandrocsj  

My question is how to do the check candle pattern: 

 (test.CheckPatternAllBullish() == true) 

without raising a null pointer error.

If you think it's better to open a new topic i can do this. 

To add comments, please log in or register