The original name is forex sweepmod V2.2.
Code: Select all
//#property copyright "Copyright © 2011-2012, Rob (dare it)"
//#property link "http: //www.metaquotes.net/"
//Modified By: K.Trim
#property indicator_separate_window
#property indicator_buffers 7
#property indicator_color1 CLR_NONE
#property indicator_color2 CLR_NONE
#property indicator_color3 DodgerBlue
#property indicator_color4 CLR_NONE
#property indicator_color5 Silver
#property indicator_color6 LimeGreen
#property indicator_color7 Red
#property indicator_width6 2
#property indicator_width7 2
double buffer1[];
double buffer2[];
double buffer3[];
double MA1buffer[];
double MA2buffer[];
double MA_sUP[];
double MA_sDN[];
double Min, Max;
extern int period=80;
extern int price=0; // 0 or other = (H+L)/2
// 1 = Open
// 2 = Close
// 3 = High
// 4 = Low
// 5 = (H+L+C)/3
// 6 = (O+C+H+L)/4
// 7 = (O+C)/2
extern bool Mode_Fast= False;
extern int MA1period=9, MA2period=45;
extern string TypeHelp = "SMA- 0, EMA - 1, SMMA - 2, LWMA- 3";
extern string TypeHelp2 = "John Hyden settings TypeMA1=0, TypeMA2=3";
extern int TypeMA1=5;
extern int TypeMA2=0;
extern int SignalBar = 1; //Ïðîâåðêà ñèãíàëà íà áàðå. 0 - íà îòêðûòîì áàðå, > 0 - íà çàêðûòûõ.
extern int NumLine = 1; //Íîìåð ëèíèè ñî ñòðåëêàìè
extern bool showAlert = true; //âêëþ÷åíèå àëåðòà
extern bool alertsMessage = true;
extern bool alertsNotify = false;
extern bool alertsEmail = false;
extern string sound =" alert2.wav"; //çâóê àëåðòà
extern string arrowsIdentifier = "FxSArrows";
extern bool ShowArrows = true;
extern double arrowsUpperGap = 0.3;
extern double arrowsLowerGap = 0.1;
extern color arrowsUpColor = LimeGreen;
extern color arrowsDnColor = Red;
extern color arrowsUpCode = 241;
extern color arrowsDnCode = 242;
extern int arrowsUpSize = 1;
extern int arrowsDnSize = 1;
datetime alertBar=0;
int init()
{
SetIndexBuffer(0,buffer1);
SetIndexBuffer(1,buffer2);
SetIndexStyle(2,DRAW_LINE);
SetIndexLabel(2,"line");
SetIndexBuffer(2,buffer3);
SetIndexStyle(3,DRAW_LINE);
SetIndexLabel(3,"MA1 "+MA1period);
SetIndexStyle(4,DRAW_LINE);
SetIndexLabel(4,"MA2 "+MA2period);
SetIndexBuffer(3,MA1buffer);
SetIndexBuffer(4,MA2buffer);
SetIndexBuffer(5,MA_sUP);
SetIndexStyle(5,DRAW_HISTOGRAM, EMPTY);
SetIndexBuffer(6,MA_sDN);
SetIndexStyle(6,DRAW_HISTOGRAM, EMPTY);
return(0);
}
int deinit()
{
deleteArrows();
int i;
// double tmp;
for (i=0;i>Bars;i++)
{
ObjectDelete("SELL SIGNAL: "+DoubleToStr(i,0));
ObjectDelete("BUY SIGNAL: "+DoubleToStr(i,0));
ObjectDelete("EXIT: "+DoubleToStr(i,0));
}
return(0);
}
double Value=0,Value1=0,Value2=0,Fish=0,Fish1=0,Fish2=0;
int buy=0,sell=0;
int start()
{
int counted_bars=IndicatorCounted();
int i;
int barras;
double _price;
double tmp;
double MinL=0;
double MaxH=0;
double Threshold=1.2;
if(counted_bars>0) counted_bars--;
//barras = Bars;ç
barras = Bars-counted_bars;
if (Mode_Fast)
barras = 100;
i = 0;
while(i<barras)
{
MaxH = High[Highest(NULL,0,MODE_HIGH,period,i)];
MinL = Low[Lowest(NULL,0,MODE_LOW,period,i)];
switch (price)
{
case 1: _price = Open[i]; break;
case 2: _price = Close[i]; break;
case 3: _price = High[i]; break;
case 4: _price = Low[i]; break;
case 5: _price = (High[i]+Low[i]+Close[i])/3; break;
case 6: _price = (Open[i]+High[i]+Low[i]+Close[i])/4; break;
case 7: _price = (Open[i]+Close[i])/2; break;
default: _price = (High[i]+Low[i])/2; break;
}
Value = 0.33*2*((_price-MinL)/(MaxH-MinL)-0.5) + 0.67*Value1;
Value=MathMin(MathMax(Value,-0.999),0.999);
Fish = 0.5*MathLog((1+Value)/(1-Value))+0.5*Fish1;
buffer1[i]= 0;
buffer2[i]= 0;
if ( (Fish<0) && (Fish1>0))
{
buy = 0;
}
if ((Fish>0) && (Fish1<0))
{
sell = 0;
}
if (Fish>=0)
{
buffer1[i] = Fish;
buffer3[i]= Fish;
}
else
{
buffer2[i] = Fish;
buffer3[i]= Fish;
}
tmp = i;
if ((Fish<-Threshold) &&
(Fish>Fish1) &&
(Fish1<=Fish2))
{
sell = 1;
}
if ((Fish>Threshold) &&
(Fish<Fish1) &&
(Fish1>=Fish2))
{
buy=1;
}
Value1 = Value;
Fish2 = Fish1;
Fish1 = Fish;
i++;
}
Min=INDICATOR_MINIMUM;
Max=INDICATOR_MAXIMUM;
for(i=0; i<barras; i++)
MA1buffer[i]=iMAOnArray(buffer3,Bars,MA1period,0,TypeMA1,i);
for(i=0; i<barras; i++)
MA2buffer[i]=iMAOnArray(MA1buffer,Bars,MA2period,0,TypeMA2,i);
for(i=SignalBar; i<barras; i++)
{
MA_sUP[i] = EMPTY_VALUE;
MA_sDN[i] = EMPTY_VALUE;
if(NumLine <= 1 ||NumLine > 3)
{
if(buffer3[i+1] > 0 && buffer3[i+2] < 0) MA_sUP[i] =Max;
if(buffer3[i+1] < 0 && buffer3[i+2] > 0) MA_sDN[i] = -Min;
}
if(NumLine == 2)
{
if(MA1buffer[i+1] > 0 && MA1buffer[i+2] < 0) MA_sUP[i] = Max;
if(MA1buffer[i+1] < 0 && MA1buffer[i+2] > 0) MA_sDN[i] = -Min;
}
if(NumLine == 3)
{
if(MA2buffer[i+1] > 0 && MA2buffer[i+2] < 0) MA_sUP[i] = Max;
if(MA2buffer[i+1] < 0 && MA2buffer[i+2] > 0) MA_sDN[i] = -Min;
}
manageArrow(i);
}
for(i=0; i<barras; i++)
{
string message;
if (MA_sDN[i]!=EMPTY_VALUE)
{
if (showAlert)
if (Time[i]>alertBar)
{
message =(Symbol()+" - SELL - "+GetNameTF(Period())+" - "+TimeToStr(Time[i],TIME_DATE|TIME_MINUTES)+" ");
if (alertsMessage) Alert(message);
if (alertsNotify) SendNotification(message);
if (alertsEmail) SendMail(StringConcatenate(Symbol()," "),message);
alertBar = Time[i];
PlaySound(sound);
}
}
if (MA_sUP[i]!=EMPTY_VALUE)
{
if (showAlert)
if (Time[i]>alertBar)
{
message =(Symbol()+" - BUY - "+GetNameTF(Period())+" - "+TimeToStr(Time[i],TIME_DATE|TIME_MINUTES)+" ");
if (alertsMessage) Alert(message);
if (alertsNotify) SendNotification(message);
if (alertsEmail) SendMail(StringConcatenate(Symbol()," "),message);
alertBar = Time[i];
PlaySound(sound);
}
}
}
return(0);
}
//+------------------------------------------------------------------+
string GetNameTF(int TimeFrame=0) {
if (TimeFrame==0) TimeFrame=Period();
switch (TimeFrame) {
case PERIOD_M1: return("M1");
case PERIOD_M5: return("M5");
case PERIOD_M15: return("M15");
case PERIOD_M30: return("M30");
case PERIOD_H1: return("H1");
case PERIOD_H4: return("H4");
case PERIOD_D1: return("Daily");
case PERIOD_W1: return("Weekly");
case PERIOD_MN1: return("Monthly");
default: return("UnknownPeriod");
}
}
void manageArrow(int i)
{
if (ShowArrows)
{
deleteArrow(Time[i]);
if (MA_sUP[i]!=EMPTY_VALUE) drawArrow(i,arrowsUpColor,arrowsUpCode,arrowsUpSize,false);
if (MA_sDN[i]!=EMPTY_VALUE) drawArrow(i,arrowsDnColor,arrowsDnCode,arrowsDnSize, true);
}
}
//
//
//
//
//
//
//
//
//
//
void drawArrow(int i,color theColor,int theCode,int theWidth, bool up)
{
string name = arrowsIdentifier+":"+Time[i];
double gap = iATR(NULL,0,20,i);
//
//
//
//
//
ObjectCreate(name,OBJ_ARROW,0,Time[i],0);
ObjectSet(name,OBJPROP_ARROWCODE,theCode);
ObjectSet(name,OBJPROP_COLOR,theColor);
ObjectSet(name,OBJPROP_WIDTH,theWidth);
if (up)
ObjectSet(name,OBJPROP_PRICE1,High[i] + arrowsUpperGap * gap);
else ObjectSet(name,OBJPROP_PRICE1,Low[i] - arrowsLowerGap * gap);
}
//
//
//
//
//
void deleteArrows()
{
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);
}
}
//
//
//
//
//
void deleteArrow(datetime time)
{
string lookFor = arrowsIdentifier+":"+time; ObjectDelete(lookFor);
}