//+------------------------------------------------------------------+
//| test.mq4 |
//| Copyright 2015, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
extern string flag1 = "快线";
input int l_fast = 5;
extern string flag2 = "慢线";
input int l_slow = 20;
extern string flag3 = "信号线";
input int l_signal = 18;
extern string flag4 = "误差值";
input double deviation = 0.0;
extern string flag5 = "K线推移(0为当前K线)";
input int shift = 0;
datetime now = 0;
int OnInit()
{
//--- create timer
EventSetTimer(60);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//--- destroy timer
EventKillTimer();
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
if(now != Time[0])
{ now = Time[0];
double main0 = iMACD(Symbol(), 0, l_fast, l_slow, l_signal, PRICE_CLOSE, MODE_MAIN, shift);
double signal0 = iMACD(Symbol(), 0, l_fast, l_slow, l_signal, PRICE_CLOSE, MODE_SIGNAL, shift);
double main1 = iMACD(Symbol(), 0, l_fast, l_slow, l_signal, PRICE_CLOSE, MODE_MAIN, shift + 1);
double signal1 = iMACD(Symbol(), 0, l_fast, l_slow, l_signal, PRICE_CLOSE, MODE_SIGNAL, shift + 1);
if(main0 > 0 && main1 < 0)
{
Alert("MACD上穿");
PlaySound("Alert.wav");
}
else if(main0 < 0 && main1 > 0)
{
Alert("MACD下穿");
PlaySound("Alert.wav");
}
if(signal0 > 0 && signal1 < 0)
{
Alert("信号线上穿");
PlaySound("Alert.wav");
}
else if(signal0 < 0 && signal1 > 0)
{
Alert("信号线下穿");
PlaySound("Alert.wav");
}
}
}
//+------------------------------------------------------------------+
//| Timer function |
//+------------------------------------------------------------------+
void OnTimer()
{
//---
}
//+------------------------------------------------------------------+
//| Tester function |
//+------------------------------------------------------------------+
double OnTester()
{
//---
double ret=0.0;
//---
//---
return(ret);
}
//+------------------------------------------------------------------+
//| ChartEvent function |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
const long &lparam,
const double &dparam,
const string &sparam)
{
//---
}
//+------------------------------------------------------------------+
|