Download MetaTrader 5

Candle Pattern EA Not Trading ?

To add comments, please log in or register
surubabs Suresh Kakkattil
818
surubabs Suresh Kakkattil  

Dear all i am just following the method of candle patterns https://www.mql5.com/en/code/321, and i create an ea on this base, but its not doing any trade !!!

can any one help me ?

//+------------------------------------------------------------------+
//|                                                           Ko.mq5 |
//|                                Copyright 2013, Suresh Kakkattil. |
//|                                         http://www.Rocktrader.in |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, Suresh Kakkattil."
#property link      "http://www.Rocktrader.in"
#property version   "1.00"
#include <Expert\MySignals\ACandlePatterns.mqh>
//--- input parameters
input int bands_period= 20;        // Bollinger Bands period
input int dema_period= 20;         // DEMA period
input int bands_shift = 0;         // Bollinger Bands shift
input double deviation= 2;         // Standard deviation
input double   Lot=0.5;            // Lots to trade
//--- global variables
int BolBandsHandle;                // Bolinger Bands handle
int demaHandle;                    // DEMA handle
double BBUp[],BBLow[],BBMidle[];   // dynamic arrays for numerical values of Bollinger Bands
double demaVal[];                  // dynamic array for numerical values of Moving Average 
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- Do we have sufficient bars to work
   if(Bars(_Symbol,_Period)<60) // total number of bars is less than 60?
     {
      Alert("We have less than 60 bars on the chart, an Expert Advisor terminated!!");
      return(-1);
     }
//--- get handle of the Bollinger Bands and DEMA indicators
   BolBandsHandle=iBands(NULL,PERIOD_M30,bands_period,bands_shift,deviation,PRICE_CLOSE);
   demaHandle=iDEMA(NULL,PERIOD_D1,dema_period,0,PRICE_CLOSE);
//--- Check for Invalid Handle
   if((BolBandsHandle<0) || (demaHandle<0))
     {
      Alert("Error in creation of indicators - error: ",GetLastError(),"!!");
      return(-1);
     }

   return(0);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- release indicator handles
   IndicatorRelease(BolBandsHandle);
   IndicatorRelease(demaHandle);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- we will use the static Old_Time variable to serve the bar time.
//--- at each OnTick execution we will check the current bar time with the saved one.
//--- if the bar time isn't equal to the saved time, it indicates that we have a new tick.

   static datetime Old_Time;
   datetime New_Time[1];
   bool IsNewBar=false;

//--- copying the last bar time to the element New_Time[0]
   int copied=CopyTime(_Symbol,_Period,0,1,New_Time);
   if(copied>0) // ok, the data has been copied successfully
     {
      if(Old_Time!=New_Time[0]) // if old time isn't equal to new bar time
        {
         IsNewBar=true;   // if it isn't a first call, the new bar has appeared
         if(MQL5InfoInteger(MQL5_DEBUGGING)) Print("We have new bar here ",New_Time[0]," old time was ",Old_Time);
         Old_Time=New_Time[0];            // saving bar time
        }
     }
   else
     {
      Alert("Error in copying historical times data, error =",GetLastError());
      ResetLastError();
      return;
     }

//--- EA should only check for new trade if we have a new bar
   if(IsNewBar==false)
     {
      return;
     }

//--- do we have enough bars to work with
   int Mybars=Bars(_Symbol,_Period);
   if(Mybars<60) // if total bars is less than 60 bars
     {
      Alert("We have less than 60 bars, EA will now exit!!");
      return;
     }

   MqlRates mrate[];          // To be used to store the prices, volumes and spread of each bar   

/*
     Let's make sure our arrays values for the Rates and Indicators 
     is stored serially similar to the timeseries array
*/

// the rates arrays
   ArraySetAsSeries(mrate,true);
   ArraySetAsSeries(demaVal,true);
// the indicator arrays
   ArraySetAsSeries(BBUp,true);
   ArraySetAsSeries(BBLow,true);
   ArraySetAsSeries(BBMidle,true);

//--- Get the details of the latest 3 bars
   if(CopyRates(_Symbol,_Period,0,3,mrate)<0)
     {
      Alert("Error copying rates/history data - error:",GetLastError(),"!!");
      return;
     }

//--- Copy the new values of our indicators to buffers (arrays) using the handle
   if(CopyBuffer(BolBandsHandle,0,0,3,BBMidle)<0 || CopyBuffer(BolBandsHandle,1,0,3,BBUp)<0
      || CopyBuffer(BolBandsHandle,2,0,3,BBLow)<0)
     {
      Alert("Error copying Bollinger Bands indicator Buffers - error:",GetLastError(),"!!");
      return;
     }

   if(CopyBuffer(demaHandle,0,0,3,demaVal)<0)
     {
      Alert("Error copying DEMA indicator buffer - error:",GetLastError());
      return;
     }

   double Ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);   // Ask price
   double Bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);   // Bid price

//--- Declare bool type variables to hold our Buy and Sell Conditions
   bool Buy_Condition =(mrate[1].close > BBMidle[2] && CANDLE_PATTERN_MORNING_STAR || CANDLE_PATTERN_THREE_WHITE_SOLDIERS || CANDLE_PATTERN_MORNING_DOJI
   ||CANDLE_PATTERN_BULLISH_ENGULFING || CANDLE_PATTERN_HAMMER || CANDLE_PATTERN_HANGING_MAN || CANDLE_PATTERN_PIERCING_LINE ||
     CANDLE_PATTERN_BULLISH_HARAMI || CANDLE_PATTERN_BULLISH_MEETING_LINES );          // and DEMA is growing up
                       

   bool Sell_Condition = (mrate[1].close < BBMidle[2] && CANDLE_PATTERN_THREE_BLACK_CROWS || CANDLE_PATTERN_DARK_CLOUD_COVER 
  || CANDLE_PATTERN_EVENING_DOJI || CANDLE_PATTERN_BEARISH_ENGULFING || CANDLE_PATTERN_BEARISH_HARAMI 
  || CANDLE_PATTERN_EVENING_STAR || CANDLE_PATTERN_BEARISH_MEETING_LINES || CANDLE_PATTERN_HAMMER 
  || CANDLE_PATTERN_HANGING_MAN );        // 
                         

   bool Buy_Close=(mrate[1].close<BBUp[1] && mrate[1].open>BBUp[1]);              // Black candle crossed the Upper Band from above to below

   bool Sell_Close=(mrate[1].close>BBLow[1] && mrate[1].open<BBLow[1]);           // White candle crossed the Lower Band from below to above

   if(Buy_Condition && !PositionSelect(_Symbol))    // Open long position
     {                                              // DEÌÀ is growing up
      LongPositionOpen();                           // and white candle crossed the Lower Band from below to above
     }

   if(Sell_Condition && !PositionSelect(_Symbol))   // Open short position
     {                                              // DEÌÀ is falling down
      ShortPositionOpen();                          // and Black candle crossed the Upper Band from above to below
     }

   if(Buy_Close && PositionSelect(_Symbol))         // Close long position
     {                                              // Black candle crossed the Upper Band from above to below
      LongPositionClose();
     }

   if(Sell_Close && PositionSelect(_Symbol))        // Close short position
     {                                              // White candle crossed the Lower Band from below to above
      ShortPositionClose();
     }

   return;
  }
//+------------------------------------------------------------------+
//| Open Long position                                               |
//+------------------------------------------------------------------+
void LongPositionOpen()
  {
   MqlTradeRequest mrequest;                             // Will be used for trade requests
   MqlTradeResult mresult;                               // Will be used for results of trade requests
   
   ZeroMemory(mrequest);
   ZeroMemory(mresult);
   
   double Ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);    // Ask price
   double Bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);    // Bid price

   if(!PositionSelect(_Symbol))
     {
      mrequest.action = TRADE_ACTION_DEAL;               // Immediate order execution
      mrequest.price = NormalizeDouble(Ask,_Digits);     // Lastest Ask price
      mrequest.sl = 0;                                   // Stop Loss
      mrequest.tp = 0;                                   // Take Profit
      mrequest.symbol = _Symbol;                         // Symbol
      mrequest.volume = Lot;                             // Number of lots to trade
      mrequest.magic = 0;                                // Magic Number
      mrequest.type = ORDER_TYPE_BUY;                    // Buy Order
      mrequest.type_filling = ORDER_FILLING_FOK;         // Order execution type
      mrequest.deviation=5;                              // Deviation from current price
      OrderSend(mrequest,mresult);                       // Send order
     }
  }
//+------------------------------------------------------------------+
//| Open Short position                                              |
//+------------------------------------------------------------------+
void ShortPositionOpen()
  {
   MqlTradeRequest mrequest;                             // Will be used for trade requests
   MqlTradeResult mresult;                               // Will be used for results of trade requests
   
   ZeroMemory(mrequest);
   ZeroMemory(mresult);
   
   double Ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);    // Ask price
   double Bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);    // Bid price

   if(!PositionSelect(_Symbol))
     {
      mrequest.action = TRADE_ACTION_DEAL;               // Immediate order execution
      mrequest.price = NormalizeDouble(Bid,_Digits);     // Lastest Bid price
      mrequest.sl = 0;                                   // Stop Loss
      mrequest.tp = 0;                                   // Take Profit
      mrequest.symbol = _Symbol;                         // Symbol
      mrequest.volume = Lot;                             // Number of lots to trade
      mrequest.magic = 0;                                // Magic Number
      mrequest.type= ORDER_TYPE_SELL;                    // Sell order
      mrequest.type_filling = ORDER_FILLING_FOK;         // Order execution type
      mrequest.deviation=5;                              // Deviation from current price
      OrderSend(mrequest,mresult);                       // Send order
     }
  }
//+------------------------------------------------------------------+
//| Close Long position                                              |
//+------------------------------------------------------------------+
void LongPositionClose()
  {
   MqlTradeRequest mrequest;                             // Will be used for trade requests
   MqlTradeResult mresult;                               // Will be used for results of trade requests
   
   ZeroMemory(mrequest);
   ZeroMemory(mresult);
   
   double Ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);    // Ask price
   double Bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);    // Bid price

   if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
     {
      mrequest.action = TRADE_ACTION_DEAL;               // Immediate order execution
      mrequest.price = NormalizeDouble(Bid,_Digits);     // Lastest Bid price
      mrequest.sl = 0;                                   // Stop Loss
      mrequest.tp = 0;                                   // Take Profit
      mrequest.symbol = _Symbol;                         // Symbol
      mrequest.volume = Lot;                             // Number of lots to trade
      mrequest.magic = 0;                                // Magic Number
      mrequest.type= ORDER_TYPE_SELL;                    // Sell order
      mrequest.type_filling = ORDER_FILLING_FOK;         // Order execution type
      mrequest.deviation=5;                              // Deviation from current price
      OrderSend(mrequest,mresult);                       // Send order
     }
  }
//+------------------------------------------------------------------+
//| Close Short position                                             |
//+------------------------------------------------------------------+
void ShortPositionClose()
  {
   MqlTradeRequest mrequest;                             // Will be used for trade requests
   MqlTradeResult mresult;                               // Will be used for results of trade requests
   
   ZeroMemory(mrequest);
   ZeroMemory(mresult);
   
   double Ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);    // Ask price
   double Bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);    // Bid price

   if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)
     {
      mrequest.action = TRADE_ACTION_DEAL;               // Immediate order execution
      mrequest.price = NormalizeDouble(Ask,_Digits);     // Latest ask price
      mrequest.sl = 0;                                   // Stop Loss
      mrequest.tp = 0;                                   // Take Profit
      mrequest.symbol = _Symbol;                         // Symbol
      mrequest.volume = Lot;                             // Number of lots to trade
      mrequest.magic = 0;                                // Magic Number
      mrequest.type = ORDER_TYPE_BUY;                    // Buy order
      mrequest.type_filling = ORDER_FILLING_FOK;         // Order execution type
      mrequest.deviation=5;                              // Deviation from current price
      OrderSend(mrequest,mresult);                       // Send order
     }
  }
//+------------------------------------------------------------------+
MQL5 Wizard - Trade Signals Based on Bullish/Bearish Meeting Lines + RSI
MQL5 Wizard - Trade Signals Based on Bullish/Bearish Meeting Lines + RSI
  • votes: 5
  • 2011.03.24
  • MetaQuotes Software Corp.
  • www.mql5.com
Trade signals based on "Bullish/Bearish Meeting Lines" candlestick pattern, confirmed by RSI (Relative Strength Index) indicator is considered. The code of the Expert Advisor based on this strategy can be generated automatically using the MQL5 Wizard.
Simon Gniadkowski
Moderator
18023
Simon Gniadkowski  
surubabs:

Dear all i am just following the method of candle patterns https://www.mql5.com/en/code/321, and i create an ea on this base, but its not doing any trade !!!

can any one help me ?

What is the point in getting the result of the order if you never use it ?  don't you want to know why it failed when it failed ?
surubabs Suresh Kakkattil
818
surubabs Suresh Kakkattil  
RaptorUK:
What is the point in getting the result of the order if you never use it ?  don't you want to know why it failed when it failed ?

i ddnt get what you meen, i did many  strategy test but there is no trade happning , why ?..

i given buy and sell condition if any of the pattern formed, a trade should take place, but itsnot happning Raptor, do u find any mistake in my code ?

Alain Verleyen
Moderator
31984
Alain Verleyen  
surubabs:

Dear all i am just following the method of candle patterns https://www.mql5.com/en/code/321, and i create an ea on this base, but its not doing any trade !!!

can any one help me ?

It works for me.


surubabs Suresh Kakkattil
818
surubabs Suresh Kakkattil  
angevoyageur:

It works for me.

Yes Its working in bellow 1 hour chart only, thanks to every one, problem solved,
Simon Gniadkowski
Moderator
18023
Simon Gniadkowski  
surubabs:

i ddnt get what you meen, i did many  strategy test but there is no trade happning , why ?..

i given buy and sell condition if any of the pattern formed, a trade should take place, but itsnot happning Raptor, do u find any mistake in my code ?

What is the point of this ?

MqlTradeResult mresult; 
To add comments, please log in or register