#property copyright "FILTER-EXTRA"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_width1 2
#property indicator_width2 2
extern int timeFrame = 0;
extern int Length = 1;
extern int barsback = 500;
bool alertsOn = true;
bool alertsOnCurrent = false;
bool alertsMessage = true;
bool alertsSound = false;
bool alertsNotify = false;
bool alertsEmail = false;
string soundfile = "alert2.wav";
extern bool arrowsVisible = true;
extern string arrowsIdentifier = "filterArrows";
extern double arrowsDisplacement = 0.5;
extern color arrowsUpColor = DeepSkyBlue;
extern color arrowsDnColor = Red;
extern int arrowsUpCode = 233;
extern int arrowsDnCode = 234;
extern int arrowsUpSize = 1;
extern int arrowsDnSize = 1;
extern bool UseSound = true;
extern bool AlertSound = true;
extern string SoundFileBuy = "alert2.wav";
extern string SoundFileSell = "email.wav";
extern bool SendMailPossible = false;
extern int SIGNAL_BAR = 0;
bool SoundBuy = False;
bool SoundSell = False;
double buffer1[];
double buffer2[];
bool cer;
bool cer2;
bool cer3 = TRUE;
string fileName;
int init() {
cer3 = TRUE;
SetIndexStyle(0, DRAW_HISTOGRAM);
SetIndexBuffer(0, buffer1);
SetIndexStyle(1, DRAW_HISTOGRAM);
SetIndexBuffer(1, buffer2);
fileName=WindowExpertName();
timeFrame = MathMax(timeFrame,Period());
return (0);
}
int deinit() {
string lookFor = arrowsIdentifier+":";
int lookForLength = StringLen(lookFor);
for (int i=ObjectsTotal()-1; i>=0; i--)
{
string objectName = ObjectName(i);
if (StringSubstr(objectName,0,lookForLength) == lookFor) ObjectDelete(objectName);
}
return (0);
}
int start() {
if (timeFrame!=Period())
{
int limit = MathMin(Bars-1,barsback*timeFrame/Period());
for (int i = limit; i >= 0; i--)
{
int y = iBarShift(NULL,timeFrame,Time);
buffer1 = iCustom(NULL,timeFrame,fileName,0,Length,barsback, alertsOn,alertsOnCurrent,alertsMessage,alertsSound ,alertsNotify,alertsEmail,soundfile,arrowsVisible, arrowsIdentifier,arrowsDisplacement,arrowsUpColor, arrowsDnColor,arrowsUpCode,arrowsDnCode,arrowsUpSi ze,arrowsDnSize,0,y);
buffer2 = iCustom(NULL,timeFrame,fileName,0,Length,barsback, alertsOn,alertsOnCurrent,alertsMessage,alertsSound ,alertsNotify,alertsEmail,soundfile,arrowsVisible, arrowsIdentifier,arrowsDisplacement,arrowsUpColor, arrowsDnColor,arrowsUpCode,arrowsDnCode,arrowsUpSi ze,arrowsDnSize,1,y);
}
return(0);
}
double low1;
double high1;
double cero[10000][3];
if (!cer3) return (0);
int pep = 0;
int bep = 0;
int tep = 0;
double high60 = High[barsback];
double low68 = Low[barsback];
int li3 = barsback;
int li6 = barsback;
for (int li2 = barsback; li2 >= 0; li2--) {
low1 = 10000000;
high1 = -100000000;
for (int li8 = li2 + Length; li8 >= li2 + 1; li8--) {
if (Low[li8] < low1) low1 = Low[li8];
if (High[li8] > high1) high1 = High[li8];
}
if (Low[li2] < low1 && High[li2] > high1) {
bep = 2;
if (pep == 1) li3 = li2 + 1;
if (pep == -1) li6 = li2 + 1;
} else {
if (Low[li2] < low1) bep = -1;
if (High[li2] > high1)bep = 1;
}
if (bep != pep && pep != 0) {
if (bep == 2) {
bep = -pep;
high60 = High[li2];
low68 = Low[li2];
cer = FALSE;
cer2 = FALSE;
}
tep++;
if (bep == 1) {
cero[tep][1] = li6;
cero[tep][2] = low68;
cer = FALSE;
cer2 = TRUE;
}
if (bep == -1) {
cero[tep][1] = li3;
cero[tep][2] = high60;
cer = TRUE;
cer2 = FALSE;
}
high60 = High[li2];
low68 = Low[li2];
}
if (bep == 1) {
if (High[li2] >= high60) {
high60 = High[li2];
li3 = li2;
}
}
if (bep == -1) {
if (Low[li2] <= low68) {
low68 = Low[li2];
li6 = li2;
}
}
pep = bep;
if (cer2 == TRUE) {
buffer2[li2] = 1;
buffer1[li2] = 0;
}
if (cer == TRUE) {
buffer2[li2] = 0;
buffer1[li2] = 1;
}
manageArrow(li2);
}
string message = StringConcatenate("FILTER-EXTRA(", Symbol(), ", ", Period(), ") - BUY!!!"," Price - ",Ask ," !!! Time - " ,TimeToStr(TimeLocal(),TIME_SECONDS));
string message2 = StringConcatenate("FILTER-EXTRA(", Symbol(), ", ", Period(), ") - SELL!!!"," Price - ",Bid," !!! Time - " ,TimeToStr(TimeLocal(),TIME_SECONDS));
if (buffer2[SIGNAL_BAR] != EMPTY_VALUE && buffer2[SIGNAL_BAR] != 0 && SoundBuy)
{
SoundBuy = False;
if (UseSound) PlaySound (SoundFileBuy);
if(AlertSound){
Alert(message);
if (SendMailPossible) SendMail(Symbol(),message);
}
}
if (!SoundBuy && (buffer2[SIGNAL_BAR] == EMPTY_VALUE || buffer2[SIGNAL_BAR] == 0)) SoundBuy = True;
if (buffer1[SIGNAL_BAR] != EMPTY_VALUE && buffer1[SIGNAL_BAR] != 0 && SoundSell)
{
SoundSell = False;
if (UseSound) PlaySound (SoundFileSell);
if(AlertSound){
Alert(message2);
if (SendMailPossible) SendMail(Symbol(),message2);
}
}
if (!SoundSell && (buffer1[SIGNAL_BAR] == EMPTY_VALUE || buffer1[SIGNAL_BAR] == 0)) SoundSell = True;
//+------------------------------------------------------------------+
return (0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
void manageArrow(int i)
{
if (arrowsVisible)
{
ObjectDelete(arrowsIdentifier+":"+Time);
if (buffer2 == 1 && buffer2[i+1] == 0) drawArrow(i,arrowsUpColor,arrowsUpCode,arrowsUpSiz e,false);
if (buffer1 == 1 && buffer1[i+1] == 0) drawArrow(i,arrowsDnColor,arrowsDnCode,arrowsDnSiz e,true);
}
}
//
//
//
//
//
void drawArrow(int i,color theColor,int theCode,int theSize, bool up)
{
string name = arrowsIdentifier+":"+Time;
double gap = iATR(NULL,0,20,i);
//
//
//
//
//
ObjectCreate(name,OBJ_ARROW,0,Time,0);
ObjectSet(name,OBJPROP_ARROWCODE,theCode);
ObjectSet(name,OBJPROP_COLOR, theColor);
ObjectSet(name,OBJPROP_WIDTH, theSize);
if (up)
ObjectSet(name,OBJPROP_PRICE1,High + arrowsDisplacement * gap);
else ObjectSet(name,OBJPROP_PRICE1, Low - arrowsDisplacement * gap);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//