Indicators Used
Miscellaneous
0
Views
0
Downloads
0
Favorites
simpletrading-v1_0
//+------------------------------------------------------------------+
//| simple_trading_system.mq4 |
//| evillive |
//| |
//+------------------------------------------------------------------+
#property copyright "2014, Vitalie Postolache"
#property link "http://www.mql4.com"
#property version "1.0"
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Aqua
#property indicator_color2 Magenta
//+------------------------------------------------------------------+
//| User parameters |
//+------------------------------------------------------------------+
extern int period = 2; //MA period
extern ENUM_MA_METHOD method = MODE_SMA; //MA method
extern ENUM_APPLIED_PRICE price = PRICE_CLOSE; //Applied price
extern int shift = 4; //Bar shift for second MA value
extern double ashift=0.3; //Arrow vertical shift
extern bool ocb=false; //Only completed bars counted
//----
extern string _alerts_="alerts section";
extern bool alertsON =false; //Allow alerts globally
extern bool alert =false; //Pop-up alert
extern bool sound =false; //Play sound
extern bool email =false; //Send e-mail
extern bool notify =false; //Send push notification
extern string soundname = "news.wav"; //Sound file name
//----
double ma00,ma01,atr;
double Up[];
double Dn[];
double Hlv[];
string name;
int m=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
IndicatorBuffers(3);
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,225);
SetIndexBuffer(0,Up);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1,226);
SetIndexBuffer(1,Dn);
SetIndexLabel(0,"BUY!");
SetIndexLabel(1,"SELL!");
SetIndexBuffer(2,Hlv);
name = MQLInfoString(MQL_PROGRAM_NAME);
IndicatorShortName(name);
IndicatorDigits(_Digits);
if(ocb==true) m=1;
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Main program body |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
//----
int i;
int limit;
//----
if(rates_total-1 < (period+shift))
return(0);
//----
if(prev_calculated<1)
{
for(i=0; i<=rates_total-1-(period+shift); i++)
{
Up[i]=0.0;
Dn[i]=0.0;
Hlv[i]=0.0;
}
}
//----
if(prev_calculated>1)
limit=rates_total-1-prev_calculated;
else
limit=rates_total-1-(period+shift);
//---- starting calculation
for(i=m; i<=limit; i++)
{
Up[i]=0.0;
Dn[i]=0.0;
Hlv[i]=0.0;
ma00 = iMA(NULL,0,period,0,method,price,i);
ma01 = iMA(NULL,0,period,0,method,price,i+shift);
atr = iATR(NULL,0,period,i);
if(ma00<=ma01 && Close[i]>=Close[i+shift] && Close[i]<=Close[i+period+shift] && Close[i]<Open[i])
{
Up[i]=Low[i]-atr*ashift;
Hlv[i]=1;
}
if(ma00>=ma01 && Close[i]<=Close[i+shift] && Close[i]>=Close[i+period+shift] && Close[i]>Open[i])
{
Dn[i]=High[i]+atr*ashift;
Hlv[i]=-1;
}
}
//----
if (alertsON)
if (Hlv[m]!=0.0 && Hlv[m]!=Hlv[m+1])
{
if (Hlv[m]==1.0) doAlert(Up[m],"'UP'");
else doAlert(Dn[m],"'DOWN'");
}
//----
return(rates_total);
}
//+------------------------------------------------------------------+
//| Alerts section |
//+------------------------------------------------------------------+
void doAlert(double pr, string doWhat)
{
static string previousAlert="nothing";
static datetime previousTime;
string message;
//----
if (!IsTesting() && (previousAlert!=doWhat || previousTime!=Time[0]))
{
previousAlert =doWhat;
previousTime =Time[0];
//----
message= StringConcatenate(MQLInfoString(MQL_PROGRAM_NAME)," indicator direction changed to ",doWhat,", value: ",DoubleToStr(pr,_Digits),
", symbol: ",Symbol(),", time: ",TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS));
if (alert) Alert(message);
if (email) SendMail(StringConcatenate(MQLInfoString(MQL_PROGRAM_NAME), " on ",Symbol(),", at ",TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS)),message);
if (notify) SendNotification(message);
if (sound) PlaySound(soundname);
}
}
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---