//+------------------------------------------------------------------+
//|                                                     pin bars.mq4 |
//|                      Copyright © 2010, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2005, MetaQuotes Software Corp."
#property  link      "http://www.metaquotes.net/"
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 3
#property  indicator_color1  Black
#property  indicator_color2  Green
#property  indicator_color3  Red

//Min_Length - defines the minimum height of a candle from High to Low
//Max_Body - defines the maximum height of the body between open & close

int count;
int count1;
string i;
string instrument;

extern double  Min_Gap       = 30;    // Minimum Gap required to show here

extern bool showAlert=true;

extern bool daily=true;

extern bool forex=true;


bool check=true;

double    Pip;

bool runCount=0;

double gapArray[14];

string gapPrinter="\n Symbol     Gap     Action     Entry\n==========================";


//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {

   
   return(0);
  }
  
  
  void Identify_Gap(string symb,  int tf, int shift)
{
   
   double barO = iOpen(symb,tf,shift);
   double barC = iClose(symb,tf,shift+1);
   
    double point =MarketInfo(symb,MODE_POINT);
      Pip = point;
  // if(Digits==3||Digits==5){Pip*=10;}
   
  // Print(symb + "  open " + barO + " close "+barC + " Gap "+ MathAbs(barO-barC)/Pip+" min "+Min_Gap);
   
   if (MathAbs(barO-barC) > Min_Gap*Pip){
      string action;
       if (barO>barC) action="Buy"; else action="Sell";
       Print("Gap on "+symb + "  for " + (barO-barC)/Pip + " pips");
       if(showAlert) Alert("Gap on "+symb + "  for " + (barO-barC)/Pip + " pips");
       gapPrinter = gapPrinter +("\n"+symb + "   " + (barO-barC)/Pip + "   "+ action + "   "+barO);
   }
   

}
  
  
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
if (count == 80)
  {
   count=count-80;
  }

//Comment("count = ",count);

if (runCount==0)
  {
  runCount=runCount+1;
  // Print("..................  Find Gap running ..................... ");
   while(count <= 28)
    {
     count=count+1;
     if (forex == true && count == 1)
       {
        i="AUDCAD";
        check=true;
       }  
     if (forex == true && count == 2)
       {
        i="AUDCHF";
        check=true;
       }  
     if (forex == true && count == 3)
       {
        i="AUDJPY";
        check=true;
       }
     if (forex == true && count == 4)
       {
        i="AUDNZD";
        check=true;
       }
     if (forex == true && count == 5)
       {
        i="AUDUSD";
        check=true;
       }
     if (forex == true && count == 6)
       {
        i="CADCHF";
        check=true;
       }
     if (forex == true && count == 7)
       {
        i="CADJPY";
        check=true;
       }
     if (forex == true && count == 8)
       {
        i="CHFJPY";
        check=true;
       }
    
     if (forex == true && count == 9)
       {
        i="EURAUD";
        check=true;
       }
     if (forex == true && count == 10)
       {
        i="EURCAD";
        check=true;
       }
     if (forex == true && count == 11)
       {
        i="EURCHF";
        check=true;
       }
     
     if (forex == true && count == 12)
       {
        i="EURGBP";
        check=true;
       }
     if (forex == true && count == 13)
       {
        i="EURJPY";
        check=true;
       }
     
     
     if (forex == true && count == 14)
       {
        i="EURNZD";
        check=true;
       }
    
     
     if (forex == true && count == 15)
       {
        i="EURUSD";
        check=true;
       }
     if (forex == true && count == 16)
       {
        i="GBPAUD";
        check=true;
       }
     if (forex == true && count == 17)
       {
        i="GBPCAD";
        check=true;
       }
     if (forex == true && count == 18)
       {
        i="GBPCHF";
        check=true;
       }
     if (forex == true && count == 19)
       {
        i="GBPJPY";
        check=true;
       }
     if (forex == true && count == 20)
       {
        i="GBPNZD";
        check=true;
       }
      
     if (forex == true && count1 == 21)
       {
        i="GBPUSD";
        check=true;
       }  
     
     if (forex == true && count1 == 22)
       {
        i="NZDCAD";
        check=true;
       }
     if (forex == true && count1 == 23)
       {
        i="NZDCHF";
        check=true;
       }
     if (forex == true && count1 == 24)
       {
        i="NZDJPY";
        check=true;
       }
     if (forex == true && count1 == 25)
       {
        i="NZDUSD";
        check=true;
       }
     if (forex == true && count == 26)
       {
        i="USDCHF";
        check=true;
       }
    
     if (forex == true && count == 27)
       {
        i="USDJPY";
        check=true;
       }
      
     //Print("Double doji running ... ");
                   
     //Low and Lower close up pin bar------------------------------------------------------------------------------------          
     
       
       if ( i != instrument && check == true && daily == true)
       {       
        Identify_Gap(i,PERIOD_D1,0);
        instrument=i;
       }
      
     } 
     
     Comment(gapPrinter); 
   Sleep(36000000);  // 1 hour
  }
  


//----
   return(0);
  }
//+------------------------------------------------------------------+