How to indicate a specific type of candle after certain condition

 

Hey guys!

Any idea how can I get a indicate a specific type of candle after meeting my condition?

What I want is, I have created a crossover signal, which I would like to add in more condition like after MA Crossover, I would like the second candle to be either Inside Bar or a Pin Bar...

I have below script is the crossover and Inside Bar candle alert, just wondering what I should add in, in order for the script to alert me once crossover come along with Inside Bar criteria meet.


Any Programming MQL4 God could offer their help to me?

Million Thanks !!


//+------------------------------------------------------------------+
//|                                              Crossover_Signal.mq4 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 clrGreen 
#property indicator_color2 clrRed
#property indicator_color3 clrOrange
#property indicator_color3 clrOrangeRed

#property indicator_width1 2
#property indicator_width2 2

extern int FasterMA =   6;
extern int FasterMode = 1; //0=sma, 1=ema, 2=smma, 3=lwma
extern int SlowerMA =   18;
extern int SlowerMode = 1; //0=sma, 1=ema, 2=smma, 3=lwma
extern int FiftyMA = 50;
extern int FiftyMAMode = 1; //0=sma, 1=ema, 2=smma, 3=lwma
extern int twohundredMA = 200;
extern int twohundredMAMode = 0; //0=sma, 1=ema, 2=smma, 3=lwma
extern bool Display_In = true;
extern bool Show_Alert = true;
datetime candletime=0;
datetime currenttime=0;

double CrossUp[];
double CrossDown[];
double val1[]; //inside bar
double val2[]; 

//BMI for Pin Bar
//extern double   BMI=25.0;
//extern int minsize=50; //size of the candle at least 5 pip long
//double upGreen[];
//double downRed[];


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicator
   SetIndexStyle(0, DRAW_ARROW, EMPTY);//cross up
   SetIndexArrow(0, 233);
   SetIndexBuffer(0, CrossUp);
   SetIndexStyle(1, DRAW_ARROW, EMPTY);//cross down
   SetIndexArrow(1, 234);
   SetIndexBuffer(1, CrossDown);
   SetIndexStyle(2,DRAW_ARROW, EMPTY);//inside bar
   SetIndexArrow(2, 234);
   SetIndexBuffer(2,val1);
   SetIndexStyle(3,DRAW_ARROW,EMPTY);
   SetIndexArrow(3, 234);
   SetIndexBuffer(3,val2);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
      watermark();
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start() {
//----Crossover Declaration
   int limit, i, counter;
   double fasterMAnow, slowerMAnow, fasterMAprevious, slowerMAprevious, fasterMAafter, slowerMAafter;
   double FiftyMANow, FiftyMAprevious, FiftyMAafter, twohundredMANow, twohundredMAprevious, twohundredMAafter;
   currenttime=Time[0];
//   double sixMANow, sixMAprevious, sixMAafter;
//   double OneEightMANow, OneEightMAprevious, OneEightMAafter;
   double Range, AvgRange;
   int counted_bars=IndicatorCounted();
//----End Declaration   
   
//----Inside Bar Declaration
   int    counted_bars1=IndicatorCounted();

   double Range1, AvgRange1;
   int counter1, setalert;
   static datetime prevtime = 0;
   int shift;
   int shift1;
   int shift2;
   string pattern, period;
   int setPattern = 0;
   int alert = 0;
   double O, O1, C, C1, L, L1, H, H1;
//----End Declaration

//----Inside Bar
   if(prevtime == Time[0]) {
      return(0);
   }
   prevtime = Time[0];
   
   switch (Period()) {

      case 1:
         period = "M1";
         break;
      case 5:
         period = "M5";
         break;
      case 15:
         period = "M15";
         break;
      case 30:
         period = "M30";
         break;      
      case 60:
         period = "H1";
         break;
      case 240:
         period = "H4";
         break;
      case 1440:
         period = "D1";
         break;
      case 10080:
         period = "W1";
         break;
      case 43200:
         period = "MN";
         break;
   }
   
   for (int j = 0; j < Bars; j++) { 
 
   }

   for (shift = 0; shift < Bars; shift++) {
      setalert = 0;
      counter1=shift;
      Range1=0;
      AvgRange1=0;
      
      for (counter1=shift ;counter1<=shift+9;counter1++) {
         AvgRange1=AvgRange1+MathAbs(High[counter1]-Low[counter1]);
      }
      Range1=AvgRange1/9;
      shift1 = shift ;
      shift2 = shift + 1;
      
      O = Open[shift1];
      O1 = Open[shift2];
      H = High[shift1];
      H1 = High[shift2];
      L = Low[shift1];
      L1 = Low[shift2];
      C = Close[shift1];
      C1 = Close[shift2];

      // Check for Inside Bar Pattern

    /*  if ((H<H1) && (L>L1)) {
         if (Display_In == true) {   
         	{
		         val1[shift]=High[shift]; val2[shift]=Low[shift];
            }
         if (setalert == 0 && Show_Alert == true && (FiftyMANow > twohundredMANow)) {
            pattern="Inside Bar";
            setalert = 1;
         }
      }
      }*/

   } // End of for loop
   
   
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;

   limit=Bars-counted_bars;
   
   for(i = 0; i <= limit; i++) {
   
      counter=i;
      Range=0;
      AvgRange=0;
      for (counter=i ;counter<=i+9;counter++)
      {
         AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
      }
      Range=AvgRange/10;
       
      fasterMAnow = iMA(NULL, 0, FasterMA, 0, FasterMode, PRICE_CLOSE, i);
      fasterMAprevious = iMA(NULL, 0, FasterMA, 0, FasterMode, PRICE_CLOSE, i+1);
      fasterMAafter = iMA(NULL, 0, FasterMA, 0, FasterMode, PRICE_CLOSE, i-1);

      slowerMAnow = iMA(NULL, 0, SlowerMA, 0, SlowerMode, PRICE_CLOSE, i);
      slowerMAprevious = iMA(NULL, 0, SlowerMA, 0, SlowerMode, PRICE_CLOSE, i+1);
      slowerMAafter = iMA(NULL, 0, SlowerMA, 0, SlowerMode, PRICE_CLOSE, i-1);

      FiftyMANow = iMA(NULL, 0, FiftyMA, 0, FiftyMAMode, PRICE_CLOSE, i);
      FiftyMAprevious = iMA(NULL, 0, FiftyMA, 0,FiftyMAMode, PRICE_CLOSE, i+1);
      FiftyMAafter = iMA(NULL, 0, FiftyMA, 0,FiftyMAMode, PRICE_CLOSE, i-1);
      
      twohundredMANow = iMA(NULL, 0, twohundredMA, 0, twohundredMAMode, PRICE_CLOSE, i);
      twohundredMAprevious = iMA(NULL, 0, twohundredMA, 0,twohundredMAMode, PRICE_CLOSE, i+1);
      twohundredMAafter = iMA(NULL, 0, twohundredMA, 0,twohundredMAMode, PRICE_CLOSE, i-1);
      
      if ((fasterMAnow > slowerMAnow) && (fasterMAprevious < slowerMAprevious) && (fasterMAafter > slowerMAafter) && (FiftyMANow > twohundredMANow) 
      && (fasterMAnow > FiftyMANow) && (slowerMAnow > FiftyMANow)) {
         CrossUp[i] = Low[i] - Range*0.6;
         //
         if((H<H1) && (L>L1)){
         
            val1[shift]=High[shift]; val2[shift]=Low[shift];
            
            if(currenttime!=candletime && i==1)
            {
               Alert((string)Period()+"M ",Symbol()," "+"Long!");
               SendNotification((string)Period()+"M "+Symbol()+" "+"Long!");
            }
         }
        candletime=Time[0]; //Current Time is Time[0];
      }
      else if ((fasterMAnow < slowerMAnow) && (fasterMAprevious > slowerMAprevious) && (fasterMAafter < slowerMAafter) && (FiftyMANow < twohundredMANow) 
      && (fasterMAnow < FiftyMANow) && (slowerMAnow < FiftyMANow)) {
         CrossDown[i] = High[i] + Range*0.6;
         //val1[shift]=High[shift]; val2[shift]=Low[shift];
         if((H<H1) && (L>L1)){
         
            val1[shift]=High[shift]; val2[shift]=Low[shift];
            
            if(currenttime!=candletime && i==1)
            {
               Alert((string)Period()+"M ",Symbol()," "+"Long!");
               SendNotification((string)Period()+"M "+Symbol()+" "+"Long!");
            }
         }
        candletime=Time[0]; //Current Time is Time[0];
      }
   }
   
   return(0);
}




/*void insideBar()
  {
   //----Inside Bar Declaration
   int    counted_bars1=IndicatorCounted();

   double Range1, AvgRange1;
   int counter1, setalert;
   static datetime prevtime = 0;
   int shift;
   int shift1;
   int shift2;
   string pattern, period;
   int setPattern = 0;
   int alert = 0;
   double O, O1, C, C1, L, L1, H, H1;
//----End Declaration
   
//----Inside Bar
   if(prevtime == Time[0]) {
      return(0);
   }
   prevtime = Time[0];
   
   switch (Period()) {

      case 1:
         period = "M1";
         break;
      case 5:
         period = "M5";
         break;
      case 15:
         period = "M15";
         break;
      case 30:
         period = "M30";
         break;      
      case 60:
         period = "H1";
         break;
      case 240:
         period = "H4";
         break;
      case 1440:
         period = "D1";
         break;
      case 10080:
         period = "W1";
         break;
      case 43200:
         period = "MN";
         break;
   }
   
   for (int j = 0; j < Bars; j++) { 
   
   }

   for (shift = 0; shift < Bars; shift++) {
      setalert = 0;
      counter1=shift;
      Range1=0;
      AvgRange1=0;
      
      for (counter1=shift ;counter1<=shift+9;counter1++) {
         AvgRange1=AvgRange1+MathAbs(High[counter1]-Low[counter1]);
      }
      Range1=AvgRange1/9;
      shift1 = shift ;
      shift2 = shift + 1;
      
      O = Open[shift1];
      O1 = Open[shift2];
      H = High[shift1];
      H1 = High[shift2];
      L = Low[shift1];
      L1 = Low[shift2];
      C = Close[shift1];
      C1 = Close[shift2];

      // Check for Inside Bar Pattern

      if ((H<H1)&&(L>L1)) {
         if (Display_In == true) {   
         	{
		         val1[shift]=High[shift]; val2[shift]=Low[shift];
            }
         if (setalert == 0 && Show_Alert == true) {
            pattern="In";
            setalert = 1;
         }
      }
      }

   } // End of for loop
   return(0);
  }
*/

 
Any Programming MQL4 God could offer their help to me?

No need as you can help yourself - very easily.

Search for "pinbar" (the lens top right and in the codebase) and "inside bar" and you'll have a lot of code that detects that what you want and you can probably choose between several solutions ...

Varying a German saying "Erst denken, dann handeln => think first then do" you should practice "Search First then Code" - as there is practically nothing that does not already exists for MT4/5!

 
Carl Schreiber:

No need as you can help yourself - very easily.

Search for "pinbar" (the lens top right and in the codebase) and "inside bar" and you'll have a lot of code that detects that what you want and you can probably choose between several solutions ...

Hi Carl,


Firstly Thank you for your prompt reply!!

1st Criteria : Stated Moving Averages crossover

2nd Criteria : Candlestick appear to be either Inside Bar or Pin Bar


Just wondering do you aware which thread I could read? or Do you know how to change my code?

 
Carl Schreiber:

No need as you can help yourself - very easily.

Search for "pinbar" (the lens top right and in the codebase) and "inside bar" and you'll have a lot of code that detects that what you want and you can probably choose between several solutions ...

Varying a German saying "Erst denken, dann handeln => think first then do" you should practice "Search First then Code" - as there is practically nothing that does not already exists for MT4/5!

Hi Carl,

I did search for it. But some how i couldn't find a way to combine the two indicators together. Probably Im stupid enough and don't really know the algorithm.

So sorry... Will try the search on the lens you mentioned.


Anyone else could offer some edit on the code that I have posted? 

 
Hey guys!

Seriously I couldn't find a way to solve it! Just wondering anyone could offer your help at my above code? 

or assist me on which website or link i could refer to !


Million Thanks !!

 
Oscar Sim:

1st Criteria : Stated Moving Averages crossover

2nd Criteria : Candlestick appear to be either Inside Bar or Pin Bar


Just wondering do you aware which thread I could read? or Do you know how to change my code?

  1. You know how to code a cross over?
  2. You know how to code  IB/PB?
  3. No reading required. Code it.
Help you with what? You haven't stated a problem. Show us your attempt (using CODE button) and state the nature of your problem.
          No free help
          urgent help.
 
whroeder1:
  1. You know how to code a cross over?
  2. You know how to code  IB/PB?
  3. No reading required. Code it.
Help you with what? You haven't stated a problem. Show us your attempt (using CODE button) and state the nature of your problem.
          No free help
          urgent help.

Hey Whroeder1,

I believe that I have posted my code at my 1st post. I added crossover and IB inside the code button at my very first post...

I have also stated my problem at my first post... Just wondering did you notice that?

Everyone need a guide, or a mentor. Probably not all are so smart like you, especially im not the one. Thanks if you could offer your guidance on which post I can referring to. 


Thanks

 
Oscar Sim: I believe that I have posted my code at my 1st post.
I have also stated my problem at my first post...
Thanks if you could offer your guidance on which post I can referring to.
  1. You posted your code but never stated a problem with it. You stated in #2 what you want.
  2. You didn't state a problem, you stated a wants. You want someone to design your code for you. You want someone to code it for you.
  3. You keep asking us to show you posts. We're not going to code it for you.
  4. Oscar Sim: just wondering what I should add in, in order for the script to alert me once crossover come along with Inside Bar criteria meet.
    Do your indicator code. Remove that currenttime and setalert junk. That has nothing to do with your computation. After the loop, then test if a condition has changed for your alert.
 
whroeder1:
  1. You posted your code but never stated a problem with it. You stated in #2 what you want.
  2. You didn't state a problem, you stated a wants. You want someone to design your code for you. You want someone to code it for you.
  3. You keep asking us to show you posts. We're not going to code it for you.
  4. Do your indicator code. Remove that currenttime and setalert junk. That has nothing to do with your computation. After the loop, then test if a condition has changed for your alert.
Thanks bro! Will try on it tomorrow morning! 
Reason: