今晚金价一砸 15分钟和1小时直接吵起来了 写了个共振提醒
今晚金价砸到4025又拉回来,现在伦敦金报4039,我盯着盘口发现一件挺烦的事,15分钟图上均线刚翻空,1小时的还在多头排列,4小时压根没动,3个周期各说各话的时候看信号基本等于碰运气。所以写了个小脚本,跑一遍把4小时、1小时、15分钟3个周期的均线方向各算一次,三边全同向才弹窗写日志,只要有一个不跟就闭嘴。参数就快慢2个均线周期加1个提醒间隔,周期别填太密,我一般用20和50,太密3个周期会互相打架。脚本只提醒不下单,不碰任何交易函数,挂哪个品种都行。
//+------------------------------------------------------------------+
//| _resonance.mq5 多周期共振提醒(只报警不下单) |
//+------------------------------------------------------------------+
#property copyright "MT54"
#property version "1.00"
#property script_show_inputs
input int InpFastEMA = 20; // 快均线周期
input int InpSlowEMA = 50; // 慢均线周期
input int InpCooldown = 30; // 同向重复提醒间隔(分钟)
input bool InpAlert = true; // 弹窗提醒
input bool InpLog = true; // 写日志
string g_file = "resonance_log.csv";
double EmaVal(ENUM_TIMEFRAMES tf, int period)
{
int h = iMA(_Symbol, tf, period, 0, MODE_EMA, PRICE_CLOSE);
if(h == INVALID_HANDLE) return 0.0;
double buf[];
if(CopyBuffer(h, 0, 0, 1, buf) <= 0) { IndicatorRelease(h); return 0.0; }
IndicatorRelease(h);
return buf[0];
}
int DirOf(ENUM_TIMEFRAMES tf)
{
double f = EmaVal(tf, InpFastEMA);
double s = EmaVal(tf, InpSlowEMA);
if(f == 0.0 || s == 0.0) return 0;
if(f > s) return 1;
if(f < s) return -1;
return 0;
}
string NameOf(int d)
{
if(d > 0) return "多";
if(d < 0) return "空";
return "平";
}
void Log(string msg)
{
if(!InpLog) return;
int h = FileOpen(g_file, FILE_READ|FILE_WRITE|FILE_CSV|FILE_ANSI);
if(h == INVALID_HANDLE) return;
FileSeek(h, 0, SEEK_END);
FileWrite(h, TimeToString(TimeCurrent(), TIME_DATE|TIME_MINUTES), msg);
FileClose(h);
}
void OnStart()
{
int d4 = DirOf(PERIOD_H4);
int d1 = DirOf(PERIOD_H1);
int d15 = DirOf(PERIOD_M15);
string s4 = NameOf(d4), s1 = NameOf(d1), s15 = NameOf(d15);
Print(_Symbol, " 4H=", s4, " 1H=", s1, " 15M=", s15);
if(d4 == 0 || d1 == 0 || d15 == 0)
{
Log("有周期取不到均线,跳过");
return;
}
if(d4 == d1 && d1 == d15)
{
string txt = _Symbol + " 三周期同向 " + s4 + " 快" + IntegerToString(InpFastEMA)
+ " 慢" + IntegerToString(InpSlowEMA);
Log(txt);
if(InpAlert) Alert(txt);
}
else
Log("周期不一致 " + s4 + "/" + s1 + "/" + s15);
}全部回复(20)
发表回复
请先登录后再回复。
