//+------------------------------------------------------------------+
//| first-green.mq4 |
//| Copyright 2022, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
int last_Red_candle_index=1;
int last_Green_candle_index=1;
static datetime last_Red_candle_time=0;
static datetime last_Green_candle_time=0;
static datetime alert_reference_time=0;
static datetime alert_reference_time0=0;
while(true)
{
if(iOpen(Symbol(),0,last_Red_candle_index)>iClose(Symbol(),0,last_Red_candle_index))
{
last_Red_candle_time=iTime(Symbol(),0,last_Red_candle_index);
break;
}
last_Red_candle_index++;
if(iOpen(Symbol(),0,last_Green_candle_index)<iClose(Symbol(),0,last_Green_candle_index))
{
last_Green_candle_time=iTime(Symbol(),0,last_Green_candle_index);
break;
}
last_Green_candle_index++;
}
if(alert_reference_time!=last_Red_candle_time)
{
double red_candle_high=iHigh(Symbol(),0,last_Red_candle_index);
for(int x=last_Red_candle_index-1;x>0;x--)
{
if(iClose(Symbol(),0,x)>red_candle_high)
{
Alert("Close Above Red Candle High "+Symbol()," ",TimeToStr(CurTime(),TIME_DATE|TIME_MINUTES),
" M",Period()," ",Open[0]);
alert_reference_time=last_Red_candle_time;
break;
}
}
}
if(alert_reference_time0 != last_Green_candle_time)
{
double green_candle_low=iLow(Symbol(),0,last_Green_candle_index);
for(int y=last_Green_candle_index-1;y>0;y--)
{
if(iClose(Symbol(),0,y)<green_candle_low)
{
Alert("Close Above green Candle low "+Symbol()," ",TimeToStr(CurTime(),TIME_DATE|TIME_MINUTES),
" M",Period()," ");
alert_reference_time0 = last_Green_candle_time;
break;
}
}
}
//---
Comment("last red candle",last_Red_candle_time,"last green candle",last_Green_candle_time);
}
No comments:
Post a Comment