//+------------------------------------------------------------------+
//|                                ronnytan_strategies_indicator.mq5 |
//|                                  Copyright 2021, MetaQuotes Ltd. |
//|                         https://www.mql5.com/ru/users/artmedia70 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Ltd."
#property link      "https://www.mql5.com/ru/users/artmedia70"
#property version   "1.00"
#property indicator_chart_window
#property indicator_plots 0

enum enStrategy {
Strategy1,
Strategy2,
};

input enStrategy    WhichStrategy   = Strategy1;
input int           BuyArrowCode    = 221;
input color         BuyArrowColor   = clrLime;
input int           BuyArrowSize    = 3;
input int           SellArrowCode   = 222;
input color         SellArrowColor  = clrRed;
input int           SellArrowSize   = 3;
input int           BarsInHistory   = 500; 

string OBJ_Prefix = "ronnytan_arrow_";
string ArrowBuyName = OBJ_Prefix+"BuyArrow";
string ArrowSellName = OBJ_Prefix+"SellArrow";
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
         
      for(int i=1; i<BarsInHistory+1; i++) 
       {
       string str_i=IntegerToString(i);
              
       ObjectCreate(ChartID(),ArrowBuyName+str_i,OBJ_ARROW,0,0,0);
       ObjectSetInteger(ChartID(),ArrowBuyName+str_i,OBJPROP_ARROWCODE,BuyArrowCode);
       ObjectSetInteger(ChartID(),ArrowBuyName+str_i,OBJPROP_COLOR,BuyArrowColor);
       ObjectSetInteger(ChartID(),ArrowBuyName+str_i,OBJPROP_WIDTH,BuyArrowSize);
       ObjectSetInteger(ChartID(),ArrowBuyName+str_i,OBJPROP_SELECTABLE,false);
       ObjectSetInteger(ChartID(),ArrowBuyName+str_i,OBJPROP_SELECTED,false);
       ObjectSetInteger(ChartID(),ArrowBuyName+str_i,OBJPROP_ANCHOR,ANCHOR_TOP);
       
       ObjectCreate(ChartID(),ArrowSellName+str_i,OBJ_ARROW,0,0,0);
       ObjectSetInteger(ChartID(),ArrowSellName+str_i,OBJPROP_ARROWCODE,SellArrowCode);
       ObjectSetInteger(ChartID(),ArrowSellName+str_i,OBJPROP_COLOR,SellArrowColor);
       ObjectSetInteger(ChartID(),ArrowSellName+str_i,OBJPROP_WIDTH,SellArrowSize);
       ObjectSetInteger(ChartID(),ArrowSellName+str_i,OBJPROP_SELECTABLE,false);
       ObjectSetInteger(ChartID(),ArrowSellName+str_i,OBJPROP_SELECTED,false);
       ObjectSetInteger(ChartID(),ArrowSellName+str_i,OBJPROP_ANCHOR,ANCHOR_BOTTOM);
       }
//---
   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[])
  {
//---
   
     for(int i=0; i<BarsInHistory+1; i++) 
      {
      string str_i=IntegerToString(i);
      if(WhichStrategy==Strategy1)
       {
// Define the conditions long entry
/*
cond2 = open[0]<close[0]
cond4 = high[1]<high[0]
cond5 = low[1]>low[0]
cond6 = close[0]>high[1]
*/
       if(iOpen(_Symbol,_Period,i)<iClose(_Symbol,_Period,i)&&
          iHigh(_Symbol,_Period,i+1)<iHigh(_Symbol,_Period,i)&&
          iLow(_Symbol,_Period,i+1)>iLow(_Symbol,_Period,i)&&
          iClose(_Symbol,_Period,i)>iHigh(_Symbol,_Period,i+1))
         {
         ObjectSetDouble(ChartID(),ArrowBuyName+str_i,OBJPROP_PRICE,0,iLow(_Symbol,_Period,i));
         ObjectSetInteger(ChartID(),ArrowBuyName+str_i,OBJPROP_TIME,0,iTime(_Symbol,_Period,i));
         } 
// Define the conditions short entry
/*
cond2S = open[0]>close[0]
cond4S = high[1]<high[0]
cond5S = low[1]>low[0]
cond6S = close[0] < low[1]
*/
       if(iOpen(_Symbol,_Period,i)>iClose(_Symbol,_Period,i)&&
          iHigh(_Symbol,_Period,i+1)<iHigh(_Symbol,_Period,i)&&
          iLow(_Symbol,_Period,i+1)>iLow(_Symbol,_Period,i)&&
          iClose(_Symbol,_Period,i)<iLow(_Symbol,_Period,i))
         {
         ObjectSetDouble(ChartID(),ArrowSellName+str_i,OBJPROP_PRICE,0,iHigh(_Symbol,_Period,i));
         ObjectSetInteger(ChartID(),ArrowSellName+str_i,OBJPROP_TIME,0,iTime(_Symbol,_Period,i));
         } 
       }
      else
      if(WhichStrategy==Strategy2)
       {
// Define the conditions long entry
       if(iOpen(_Symbol,_Period,i+2)>iClose(_Symbol,_Period,i+2)&&
          iHigh(_Symbol,_Period,i)>iHigh(_Symbol,_Period,i+1)&&
          iOpen(_Symbol,_Period,i)<iClose(_Symbol,_Period,i)&&
          iHigh(_Symbol,_Period,i+1)<iHigh(_Symbol,_Period,i+2)&&
          iLow(_Symbol,_Period,i+1)<iLow(_Symbol,_Period,i+2)&&
          iLow(_Symbol,_Period,i)>iLow(_Symbol,_Period,i+1)&&
          iClose(_Symbol,_Period,i)>iHigh(_Symbol,_Period,i+1))
         {
         ObjectSetDouble(ChartID(),ArrowBuyName+str_i,OBJPROP_PRICE,0,iLow(_Symbol,_Period,i));
         ObjectSetInteger(ChartID(),ArrowBuyName+str_i,OBJPROP_TIME,0,iTime(_Symbol,_Period,i));
         } 
// Define the conditions short entry
       if(iOpen(_Symbol,_Period,i+2)<iClose(_Symbol,_Period,i+2)&&
          iLow(_Symbol,_Period,i)<iLow(_Symbol,_Period,i+1)&&
          iOpen(_Symbol,_Period,i)>iClose(_Symbol,_Period,i)&&
          iLow(_Symbol,_Period,i+1)>iLow(_Symbol,_Period,i+2)&&
          iHigh(_Symbol,_Period,i+1)>iHigh(_Symbol,_Period,i+2)&&
          iHigh(_Symbol,_Period,i)<iHigh(_Symbol,_Period,i+1)&&
          iClose(_Symbol,_Period,i)<iLow(_Symbol,_Period,i+2)
          )
         {
         ObjectSetDouble(ChartID(),ArrowSellName+str_i,OBJPROP_PRICE,0,iHigh(_Symbol,_Period,i));
         ObjectSetInteger(ChartID(),ArrowSellName+str_i,OBJPROP_TIME,0,iTime(_Symbol,_Period,i));
         } 
       
       }
      }
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
 {
     objectsDelete(OBJ_Prefix);
 }
//+------------------------------------------------------------------+
void objectsDelete(string name)
{
   int objTotal = ObjectsTotal(ChartID()); 
   for(int i=objTotal-1; i>=0; i--)  
  {
      string objName = ObjectName(ChartID(),i);
      if(StringFind(objName,name,0) == 0) 
      ObjectDelete(0,objName); 
   }
}
//+------------------------------------------------------------------+
/*
1st strategy
//@version=5


strategy(" Engulfing Bear / Bull v2")



// Define the conditions short entry
cond2S = open[0]>close[0]
cond4S = high[1]<high[0]
cond5S = low[1]>low[0]
cond6S = close[0] < low[1]


// Define the conditions long entry
cond2 = open[0]<close[0]
cond4 = high[1]<high[0]
cond5 = low[1]>low[0]
cond6 = close[0]>high[1]

// Define the strategy long entry
long_entry = cond2 and cond4 and cond5 and cond6
// Define the strategy short entry
short_entry = cond2S and cond4S and cond5S and cond6S


strategy 2

//@version=5
strategy(" 3 Candle Outside Break v2")



// Define the conditions long entry
cond1 = open[2]>close[2] // candle 3 is red
cond2 = high[0]>high[1]
cond3 = open[0]<close[0] // candle 1 is green
cond4 = high[1]<high[2]
cond5 = low [1]<low[2] // low candle 2 is lower than candle 3
cond6 = low[0]>low[1]
cond7 = close [0]>high[2] // close candle 1 is lower than close candle 2

// Define the conditions short entry
cond1S = open[2]<close[2] // candle 3 is green
cond2S = low[0]<low[1]
cond3S = open[0]>close[0] // candle 1 is red
cond4S = low[1]>low[2] // high candle 2 higher than high candle 3
cond5S = high[1]>high[2]
cond6S = high[0]<high[1]
cond7S = close [0]<low[2] // close candle 1 is lower than close candle 2

// Define the strategy long entry
long_entry = cond1 and cond2 and cond3 and cond4 and cond5 and cond6 and cond7
// Define the strategy short entry
short_entry = cond1S and cond2S and cond3S and cond4S and cond5S and cond6S and cond7S
*/
