-
Notifications
You must be signed in to change notification settings - Fork 2
/
Neds_CFB_0.1.mq4
196 lines (173 loc) · 6.41 KB
/
Neds_CFB_0.1.mq4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
//+------------------------------------------------------------------+
//| Neds Indicators|
//| Copyright 2016, Neddihrehat |
//+------------------------------------------------------------------+
// Please report any bug you occur
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 White
#property indicator_color2 White
#property indicator_width1 0
#property indicator_width2 0
extern string NOTE1="Only set 1 as true";
extern bool CFBOriginal=False;
extern bool CFBMod=True;
//+------------------------------------------------------------------+
extern string NOTE2="Alert Settings";
extern bool ShowArrows=True;
extern bool VerticalLines=False;
extern ENUM_LINE_STYLE LineStyle=STYLE_DASH;
extern color UPColor=clrGreen;
extern color DownColor=clrRed;
int ArrowsUpCode = 233;
int ArrowsDnCode = 234;
extern bool AlertsOn = True;
extern bool AlertsOnCurrent = True;
bool AlertsMessage=True;
string UniqueID="Neds_CFB";
//+------------------------------------------------------------------+
double ArrowsBuy[],ArrowsSell[],Trend[];
bool up=False;
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(6);
SetIndexBuffer(0,ArrowsBuy); SetIndexStyle(0,DRAW_ARROW,NULL,NULL,UPColor); SetIndexArrow(0,ArrowsUpCode);
SetIndexBuffer(1,ArrowsSell); SetIndexStyle(1,DRAW_ARROW,NULL,NULL,DownColor); SetIndexArrow(1,ArrowsDnCode);
SetIndexBuffer(2,Trend);
//+------------------------------------------------------------------+
SetIndexLabel(0,"Up Signal");
SetIndexLabel(1,"Down Signal");
if(!ShowArrows) { SetIndexStyle(0,DRAW_NONE); SetIndexStyle(1,DRAW_NONE); }
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int deinit()
{
DeleteThings();
//+------------------------------------------------------------------+
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
int limit=MathMin(Bars-counted_bars,Bars-1);
//+------------------------------------------------------------------+
bool sellrules,buyrules;
for(int i=limit; i>=0; i--)
{
if(CFBOriginal)
{
sellrules = (High[i]>High[i+1] && Open[i+1]<Close[i+1] && High[i+1]>Close[i]);
buyrules = (Low[i]<Low[i+1]&& Open[i+1]>Close[i+1]&& Low[i+1]<Close[i]);
}
else if(CFBMod)
{
sellrules=(High[i]>High[i+1] && Open[i+1]<Close[i+1] && Open[i]>Close[i]);
buyrules =(Low[i]<Low[i+1]&& Open[i+1]>Close[i+1]&& Open[i]<Close[i]);
}
Trend[i]=Trend[i+1];
if(// SELL
sellrules
) Trend[i]=-1;
else if(// BUY
buyrules
) Trend[i]=1;
else Trend[i]=0;
ArrowsBuy[i] = EMPTY_VALUE;
ArrowsSell[i] = EMPTY_VALUE;
if(Trend[i]!=Trend[i+1] && Trend[i]==1)
{
ArrowsBuy[i]=Low[i];
if(AlertsOn)
{
doAlert(0,"Call Signal");
up=True;
}
if(VerticalLines) CreateVLine(UniqueID+"Line"+i+Time[i],Time[i],UPColor);
}
else if(Trend[i]!=Trend[i+1] && Trend[i]==-1)
{
ArrowsSell[i]=High[i];
if(AlertsOn)
{
doAlert(0,"Put Signal");
up=False;
}
if(VerticalLines) CreateVLine(UniqueID+"Line"+i+Time[i],Time[i],DownColor);
}
}
return 0;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CreateVLine(string LineName,datetime time,color LineColor)
{
ObjectCreate(LineName,OBJ_VLINE,0,time,0);
ObjectSet(LineName,OBJPROP_STYLE,LineStyle);
ObjectSet(LineName,OBJPROP_COLOR,LineColor);
ObjectSet(LineName,OBJPROP_HIDDEN,true);
ObjectSet(LineName,OBJPROP_SELECTABLE,false);
ObjectSet(LineName,OBJPROP_BACK,true);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void DeleteThings()
{
for(int i=ObjectsTotal()-1; i>=0; i--)
{
string name = UniqueID;
string label = ObjectName(i);
if(StringSubstr(label,0,StringLen(name))!=name)
continue;
ObjectDelete(label);
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void doAlert(int forBar,string doWhat)
{
static string previousAlert="Nothing";
static datetime previousTime;
string message;
if(previousAlert!=doWhat && previousTime!=Time[forBar])
{
previousAlert = doWhat;
previousTime = Time[forBar];
message=StringConcatenate(Symbol()," - ",TimeFrameToString(Period())," - "+UniqueID+": ",doWhat);
if(AlertsMessage) Alert(message);
//if (AlertsCopier) signalcopier(Symbol(),doWhat,Expiry);
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
string TimeFrameToString(int tf)
{
string tfs;
switch(tf)
{
case PERIOD_M1: tfs = "M1"; break;
case PERIOD_M5: tfs = "M5"; break;
case PERIOD_M15: tfs = "M15"; break;
case PERIOD_M30: tfs = "M30"; break;
case PERIOD_H1: tfs = "H1"; break;
case PERIOD_H4: tfs = "H4"; break;
case PERIOD_D1: tfs = "D1"; break;
case PERIOD_W1: tfs = "W1"; break;
case PERIOD_MN1: tfs = "MN";
default: tfs="M"+DoubleToStr(tf,0);
}
return(tfs);
}
//+------------------------------------------------------------------+