Custom Candle Stick Pattern

DocT
Trader
Posts: 149
Joined: Mon Apr 23, 2012 9:44 am
Location: Aberdeen

Custom Candle Stick Pattern

Post by DocT »

Paul

Hartelijk gefeliciteerd met Uw verjaardag :!!:

Doc

ps love monster and will get around to purchasing it this year ;-)
montyy

Custom Candle Stick Pattern

Post by montyy »

Baluda » Wed Feb 25, 2015 2:44 pm wrote:As we say in the Netherlands,
There are different ways to get to Rome.
Meaning problems can be solved in several ways.

This is why I came up with this to identify engulfing candles:

Code: Select all

//+------------------------------------------------------------------+
//|                                              WhatsThisCandle.mq4 |
//|                                        Copyright 2015, Deltabron |
//|                                          http://www.deltabron.nl |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, Deltabron, Paul Geirnaerdt"
#property link      "http://www.deltabron.nl"
#property version   "1.00"
#property strict
#property indicator_chart_window

enum ENUM_CANDLE_TYPES
{
   BULL,
   BEAR,
   DOJI
};
string candleType[] = { "BULLISH", "BEARISH", "DOJI" };


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
   return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
   return(rates_total);
}

//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
{
   if ( id == CHARTEVENT_CLICK )
   {
      int x = (int)lparam;
      int y = (int)dparam;
      datetime dt = 0;
      double price = 0;
      int window = 0;
      
      if ( ChartXYToTimePrice( 0, x, y, window, dt, price ) )
      {
         int shift = iBarShift( NULL, 0, dt );
         
         if ( High[shift] > price && price > Low[shift] )
         {
            // Candle hit!
            ENUM_CANDLE_TYPES candle;
            Print (candleType[candle], " candle is ", IsEngulfing( shift, candle, 2 ) ? "engulfing" : "NOT engulfing");
         
         }
      }
   }
}

ENUM_CANDLE_TYPES GetCandleType( int shift )
{
   ENUM_CANDLE_TYPES result = DOJI;
   
   if ( Close[shift] > Open[shift] ) result = BULL;
   
   else if ( Close[shift] < Open[shift] ) result = BEAR;
   
   return ( result );
}

bool IsEngulfing( int shift, ENUM_CANDLE_TYPES &candle, int count = 1 )
{
   bool result = true;
   
   candle = GetCandleType( shift );
   
   for ( int i = shift + 1; i <= shift + count; i++ )
   {
      switch ( candle )
      {
         case BULL:

            if ( GetCandleType( i ) == BULL ) result = false;

            if ( Open[i] < Open[shift] ) result = false;
            else if ( Close[i] > Close[shift] ) result = false;
            
            break;
         
         case BEAR:

            if ( GetCandleType( i ) == BEAR ) result = false;

            if ( Open[i] > Open[shift] ) result = false;
            else if ( Close[i] < Close[shift] ) result = false;
            
            break;
         
         case DOJI:
         default:
            
            result = false;
            break;
      }   
   }
   
   return ( result );
}
This indicator identifies candles that are clicked on, check the 'Experts' tab. File added to this post.

Ask away if the code is not clear enough.

Enjoy, it is my birthday today.

Paul
Thank you milanese, stevehopwood, baluda, till now problem is not solved, i'll check the code and Happy birthday Baluda sir.
dietcoke
Trader
Posts: 162
Joined: Tue Nov 15, 2011 9:59 pm

Custom Candle Stick Pattern

Post by dietcoke »

try this Montyy

Code: Select all

 if(
       Close[i] > Open[i] //This bar is bullish
    && Close[i+1] > Open[i+1] //last bar is bullish
    && Close[i]>Close[i+1] //This close above last  close
    && Open[i]<=Open[i+1]//This open is below or level with the last open
        {
         LongBuffer[i]=Low[i]-Range;
         if(alertTag!=Time[0] && i==0 && useAlert==true)
           {
            Alert("BULL_BULL-Alert");
            alertTag=Time[0];
           }
        }
Image
montyy

Custom Candle Stick Pattern

Post by montyy »

Baluda » Wed Feb 25, 2015 2:44 pm wrote:As we say in the Netherlands,
There are different ways to get to Rome.
Meaning problems can be solved in several ways.

This is why I came up with this to identify engulfing candles:

Code: Select all

//+------------------------------------------------------------------+
//|                                              WhatsThisCandle.mq4 |
//|                                        Copyright 2015, Deltabron |
//|                                          http://www.deltabron.nl |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, Deltabron, Paul Geirnaerdt"
#property link      "http://www.deltabron.nl"
#property version   "1.00"
#property strict
#property indicator_chart_window

enum ENUM_CANDLE_TYPES
{
   BULL,
   BEAR,
   DOJI
};
string candleType[] = { "BULLISH", "BEARISH", "DOJI" };


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
   return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
   return(rates_total);
}

//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
{
   if ( id == CHARTEVENT_CLICK )
   {
      int x = (int)lparam;
      int y = (int)dparam;
      datetime dt = 0;
      double price = 0;
      int window = 0;
      
      if ( ChartXYToTimePrice( 0, x, y, window, dt, price ) )
      {
         int shift = iBarShift( NULL, 0, dt );
         
         if ( High[shift] > price && price > Low[shift] )
         {
            // Candle hit!
            ENUM_CANDLE_TYPES candle;
            Print (candleType[candle], " candle is ", IsEngulfing( shift, candle, 2 ) ? "engulfing" : "NOT engulfing");
         
         }
      }
   }
}

ENUM_CANDLE_TYPES GetCandleType( int shift )
{
   ENUM_CANDLE_TYPES result = DOJI;
   
   if ( Close[shift] > Open[shift] ) result = BULL;
   
   else if ( Close[shift] < Open[shift] ) result = BEAR;
   
   return ( result );
}

bool IsEngulfing( int shift, ENUM_CANDLE_TYPES &candle, int count = 1 )
{
   bool result = true;
   
   candle = GetCandleType( shift );
   
   for ( int i = shift + 1; i <= shift + count; i++ )
   {
      switch ( candle )
      {
         case BULL:

            if ( GetCandleType( i ) == BULL ) result = false;

            if ( Open[i] < Open[shift] ) result = false;
            else if ( Close[i] > Close[shift] ) result = false;
            
            break;
         
         case BEAR:

            if ( GetCandleType( i ) == BEAR ) result = false;

            if ( Open[i] > Open[shift] ) result = false;
            else if ( Close[i] < Close[shift] ) result = false;
            
            break;
         
         case DOJI:
         default:
            
            result = false;
            break;
      }   
   }
   
   return ( result );
}
This indicator identifies candles that are clicked on, check the 'Experts' tab. File added to this post.

Ask away if the code is not clear enough.

Enjoy, it is my birthday today.

Paul
Hi sir, it's not working for me, i'm using version 4 765 built, does this code working on your terminal?
User avatar
milanese
TechAdmin
Posts: 3293
Joined: Wed Jan 09, 2013 9:02 am
Location: btr rdx, r8 +

Custom Candle Stick Pattern

Post by milanese »

I locked this thread, as the user is only creating confusion and nothing else, montyy you will in the next weeks only be able to read in this board and to learn..

Cheers :)

Tommaso
Global Prime is the official SHF broker :yahoo:
Searching for Servers and Workstations with individual configuration?
Just PM
:smile: Click here to go to the BoardKnowledgeBase
NOTE: Cookies and JavaScript are required for the using the board, with full functionality
Locked

Return to “Coders Hangout”