Download MetaTrader 5

Using acandlepattern.mqh methods direct in OnTick

To add comments, please log in or register
leandrocsj
13
leandrocsj  
I already coded some EA but when i want to involve candles, i have no success. 

If i use the wizard to evaluate a mq5 over one of the mqls that use candles + RSI/stoch (one from the topic: https://www.mql5.com/en/forum/14482) i can obtain a working EA (through debug can't check everything but i suppose it's expected).. If i try to add any of the logics/CheckPatterns to one of my codes, i will receive an OnTick null pointer error. It stops right on the methods for checking candle pattern formation on acandlepatterns.mqh:

   //--- methods, used for check of the candlestick pattern formation
   double            AvgBody(int ind);
   double            MA(int ind)                const { return(m_MA.Main(ind));             }
   double            Open(int ind)              const { return(m_open.GetData(ind));        }
   double            High(int ind)              const { return(m_high.GetData(ind));        }
   double            Low(int ind)               const { return(m_low.GetData(ind));         }

Usually it is a matter of initializing the object but, intricate as the Candle class are, i don't know if it is the correct approaching. Below, the code (else if (test.CheckPatternAllBearish() == true is where the problem begins)

Thanks in advance for any help!

#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);
            }             
      }
   }
}
//+------------------------------------------------------------------+

 

MQL5 forum
MQL5 forum
  • www.mql5.com
MQL5: Forum on automated trading systems and strategy testing
Alain Verleyen
Moderator
33816
Alain Verleyen  
leandrocsj:
I already coded some EA but when i want to involve candles, i have no success. 

If i use the wizard to evaluate a mq5 over one of the mqls that use candles + RSI/stoch (one from the topic: https://www.mql5.com/en/forum/14482) i can obtain a working EA (through debug can't check everything but i suppose it's expected).. If i try to add any of the logics/CheckPatterns to one of my codes, i will receive an OnTick null pointer error. It stops right on the methods for checking candle pattern formation on acandlepatterns.mqh:

   //--- methods, used for check of the candlestick pattern formation
   double            AvgBody(int ind);
   double            MA(int ind)                const { return(m_MA.Main(ind));             }
   double            Open(int ind)              const { return(m_open.GetData(ind));        }
   double            High(int ind)              const { return(m_high.GetData(ind));        }
   double            Low(int ind)               const { return(m_low.GetData(ind));         }

Usually it is a matter of initializing the object but, intricate as the Candle class are, i don't know if it is the correct approaching. Below, the code (else if (test.CheckPatternAllBearish() == true is where the problem begins)

Thanks in advance for any help!

 

Yes the problem is objects initialization but you will probably take less time to code something from scratch than figuring out how to initialize this CCandlePattern object

These classes are not intended to be used standalone.

leandrocsj
13
leandrocsj  

This is the phrase that must be taken into account:

These classes are not intended to be used standalone.

To coding then :D

Thanks! 

To add comments, please log in or register