// AGM Levels
//______________________________________________________________________________________
#property indicator_chart_window
extern string pref="AGM1.3_";
#define label "AGM1.3"
//extern bool maFiltr=true;
//extern int maPer=100;
//extern ENUM_MA_METHOD maMethod=1;
//extern ENUM_APPLIED_PRICE maPrice=0;
//extern int Nbars = 3;
extern color ColorHigh = clrRed;
extern color ColorLow = clrAqua;
extern int LineWidth = 3;
extern int HistoryBars = 300;
bool UP_pre=false;
bool DOWN_pre=false;
bool UP=false;
bool DOWN=false;
int limit;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int init()
{
/*IndicatorDigits(Digits);
IndicatorBuffers(4);
SetIndexBuffer(0,Green1);
SetIndexBuffer(1,Yellow2);
SetIndexBuffer(2,White3);
SetIndexBuffer(3,Red1);
*/
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int deinit()
{
LEVELS_delete();
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void LEVELS_delete()
{
string name;
for(int s=ObjectsTotal()-1; s>=0; s--)
{
name=ObjectName(s);
if(StringSubstr(name,0,StringLen(pref))==pref) ObjectDelete(name);
if(StringSubstr(name,0,StringLen(label))==label) ObjectDelete(name);
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
int i,BarsCount=IndicatorCounted();
string name,ZoneColor;
if(BarsCount<0) return(-1);
if(BarsCount>0) BarsCount--;
limit=MathMin(Bars-BarsCount,HistoryBars);
for(i=limit; i>=0; i--)
{
UP=High[i+2]<=High[i+1] &&
//High[i+1]<=High[i+0] &&
//Low[i+2] <=Low[i+1] &&
High[i+2]<=Low[i+0];
DOWN=Low[i+2]>=Low[i+1] &&
//Low[i+1] >=Low[i+0] &&
//High[i+2]>=High[i+1]&&
Low[i+2]>=High[i+0];
if(UP /*&& !UP_pre*/)
{
DrawLines("RED_"+TimeToStr(Time[i])+"-"+IntegerToString(i),Time[i+2],High[i+2],LineWidth,ColorHigh);
UP_pre=true;
UP=false;
}
else
{
ObjectDelete(pref+"RED_"+TimeToStr(Time[i])+"-"+IntegerToString(i));
}
if(DOWN /*&& !DOWN_pre*/)
{
DrawLines("GREEN_"+TimeToStr(Time[i])+"-"+IntegerToString(i),Time[i+2],Low[i+2],LineWidth,ColorLow);
DOWN_pre=true;
DOWN=false;
}
else
{
ObjectDelete(pref+"GREEN_"+TimeToStr(Time[i])+"-"+IntegerToString(i));
}
}
return(0);
}
// ---- end
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool DrawLines(string name,datetime time,double price,int width,color LColor)
{
int s=iBarShift(NULL,_Period,time);
if(!ObjectCreate(pref+name,OBJ_TREND,0,time,price,Time[s-2],price)) return(false);
ObjectSet(pref+name,OBJPROP_COLOR,LColor);
ObjectSet(pref+name,OBJPROP_WIDTH,width);
ObjectSet(pref+name,OBJPROP_RAY_RIGHT,false);
return(true);
}
//+------------------------------------------------------------------+