LearnMQL5/CheckConsBars.mq5
super.admin 6a3edd6cd7 convert
2025-05-30 15:03:27 +02:00

148 lines
7.2 KiB
MQL5

//+------------------------------------------------------------------+
//| Candle.mq5 |
//| Copyright 2020, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
input int min_cons_candle=1; //MIN. COS. CANDLE
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//Print("Init");
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
if(IsNewBar())
{
//---
bool is_cons_bull=true;
//---
for(int x=1; x<min_cons_candle+1; x++)
{
//---
if(!isbullish(x))
{
is_cons_bull=false;
break;
}
}
//---
if(is_cons_bull)
{
Print("Trigger: ");
}
//---
bool is_cons_bear=true;
//---
for(int x=1; x<min_cons_candle+1; x++)
{
//---
if(!isbearish(x))
{
is_cons_bear=false;
break;
}
}
//---
if(is_cons_bear)
{
Print("BEAR");
}
}
//---
}
//+------------------------------------------------------------------+
//| isbullish |
//+------------------------------------------------------------------+
bool isbullish(int shift)
{
//---
double close=(iClose(_Symbol,PERIOD_CURRENT,shift));
//---
double open=(iOpen(_Symbol,PERIOD_CURRENT,shift));
//---
if(close>open)
{
return(true);
}
else
{
return(false);
}
//---
}
//+------------------------------------------------------------------+
//| isbearish |
//+------------------------------------------------------------------+
bool isbearish(int shift)
{
//---
double close=(iClose(_Symbol,PERIOD_CURRENT,shift));
//---
double open=(iOpen(_Symbol,PERIOD_CURRENT,shift));
//---
if(close<open)
{
return(true);
}
else
{
return(false);
}
//---
}
//+------------------------------------------------------------------+
//| IsNewBar |
//+------------------------------------------------------------------+
bool IsNewBar()
{
//---
datetime time_now=iTime(_Symbol,PERIOD_CURRENT,0);
//---
static datetime last_time=0;
//---
if(time_now!=last_time)
{
//---
last_time=time_now;
//---
return(true);
}
else
{
return(false);
}
//---
}
//+------------------------------------------------------------------+