#property copyright "Tono" #define SIGNAL_BUY 1 #define SIGNAL_SELL 2 extern bool SignalMail = True; extern bool EachTickMode = False; extern string LongTimeFrame = "D1"; extern int LongPeriodRSI =13; extern int LongPeriodStoch= 8; extern int LongPeriodSK = 5; extern int LongPeriodSD = 5; extern int LongMAMode = 0; extern string ShortTimeFrame = "Current time frame"; extern int ShortPeriodRSI =13; extern int ShortPeriodStoch= 8; extern int ShortPeriodSK = 5; extern int ShortPeriodSD = 5; extern int ShortMAMode = 0; int BarCount; int Current; bool TickCheck = False; string title; string message; double LongSK; double LongSD; double ShortSK_now; double ShortSD_now; double ShortSK_before; double ShortSD_before; int i = 0; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { BarCount = Bars; if (EachTickMode) Current = 0; else Current = 1; return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { if (Bars == BarCount) return(0); BarCount = Bars; //+------------------------------------------------------------------+ //| Begin | //+------------------------------------------------------------------+ SetVariables(); showDebug(); if (!(LongSK > 75 && LongSD > 75) && ((LongSK > LongSD)) && ShortSK_before < ShortSD_before && ShortSK_now > ShortSD_now) { MakeMessageBuy(); Mail(SIGNAL_BUY); } else if (!(LongSK < 25 && LongSD < 25) && ((LongSK < LongSD)) && ShortSK_before > ShortSD_before && ShortSK_now < ShortSD_now) { MakeMessageSell(); Mail(SIGNAL_SELL); } return(0); } /** * 変数の内容をセットします。 */ void SetVariables(){ LongSK = iCustom(NULL, 0, "DT Oscillator", LongTimeFrame, LongPeriodRSI, LongPeriodStoch, LongPeriodSK, LongPeriodSD, LongMAMode, 0, Current); LongSD = iCustom(NULL, 0, "DT Oscillator", LongTimeFrame, LongPeriodRSI, LongPeriodStoch, LongPeriodSK, LongPeriodSD, LongMAMode, 1, Current); ShortSK_now = iCustom(NULL, 0, "DT Oscillator", ShortTimeFrame, ShortPeriodRSI, ShortPeriodStoch, ShortPeriodSK, ShortPeriodSD, ShortMAMode,0, Current); ShortSD_now = iCustom(NULL, 0, "DT Oscillator", ShortTimeFrame, ShortPeriodRSI, ShortPeriodStoch, ShortPeriodSK, ShortPeriodSD, ShortMAMode, 1, Current); ShortSK_before = iCustom(NULL, 0, "DT Oscillator", ShortTimeFrame, ShortPeriodRSI, ShortPeriodStoch, ShortPeriodSK, ShortPeriodSD, ShortMAMode, 0, Current + 1); ShortSD_before = iCustom(NULL, 0, "DT Oscillator", ShortTimeFrame, ShortPeriodRSI, ShortPeriodStoch, ShortPeriodSK, ShortPeriodSD, ShortMAMode, 1, Current + 1); } /** * 買いシグナルのメッセージを作成します。 */ void MakeMessageBuy() { title = "Buy Signal " + Symbol() + " " + Period(); message = "[Buy Signal]\n" + "[" + Symbol() + "] \n" + "Price:" + DoubleToStr(Ask, Digits) + "\n" + MakeHighLow(); } /** * 売りシグナルのメッセージを作成します。 */ void MakeMessageSell() { title = "Sell Signal " + Symbol() + " " + Period(); message = "[Sell Signal]\n" + "[" + Symbol() + "] \n" + "Price:" + DoubleToStr(Ask, Digits) + "\n" + MakeHighLow(); } string MakeHighLow() { string highLow = ""; for (int i = 1; i < 11; i++) { highLow = (highLow + "high" + i + ":" + High[i] + " low" + i + ":" + Low[i] + "\n"); } return (highLow); } /** * メールを送信します。 * テストモードの時にはPrintを行います。 */ void Mail(int signal) { if (IsTesting()) { Print("Mailed. title:" + title + " message:" + message); } else { SendMail(title, message); } string name = "arrow" + i; ObjectCreate(name, OBJ_ARROW, 0, Time[1], Close[1]); if (signal == SIGNAL_BUY) { ObjectSet(name, OBJPROP_COLOR, Magenta); ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_THUMBSUP); } else { ObjectSet(name, OBJPROP_COLOR, Turquoise); ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_THUMBSDOWN); } i = i + 1; } void showDebug() { string str = ""; int height = 0; height += 20; str = "LongSK: " + DoubleToStr(LongSK, 0); ObjectCreate("LongSK", OBJ_LABEL, 0, 0, 0); ObjectSetText("LongSK", str, 10, "Verdana", White); ObjectSet("LongSK", OBJPROP_CORNER, 0); ObjectSet("LongSK", OBJPROP_XDISTANCE, 20); ObjectSet("LongSK", OBJPROP_YDISTANCE, height); height += 20; str = "LongSD: " + DoubleToStr(LongSD, 0); ObjectCreate("LongSD", OBJ_LABEL, 0, 0, 0); ObjectSetText("LongSD", str, 10, "Verdana", White); ObjectSet("LongSD", OBJPROP_CORNER, 0); ObjectSet("LongSD", OBJPROP_XDISTANCE, 20); ObjectSet("LongSD", OBJPROP_YDISTANCE, height); height += 20; str = "ShortSK_now: " + DoubleToStr(ShortSK_now, 0); ObjectCreate("ShortSK_now", OBJ_LABEL, 0, 0, 0); ObjectSetText("ShortSK_now", str, 10, "Verdana", White); ObjectSet("ShortSK_now", OBJPROP_CORNER, 0); ObjectSet("ShortSK_now", OBJPROP_XDISTANCE, 20); ObjectSet("ShortSK_now", OBJPROP_YDISTANCE, height); height += 20; str = "ShortSD_now: " + DoubleToStr(ShortSD_now, 0); ObjectCreate("ShortSD_now", OBJ_LABEL, 0, 0, 0); ObjectSetText("ShortSD_now", str, 10, "Verdana", White); ObjectSet("ShortSD_now", OBJPROP_CORNER, 0); ObjectSet("ShortSD_now", OBJPROP_XDISTANCE, 20); ObjectSet("ShortSD_now", OBJPROP_YDISTANCE, height); height += 20; str = "ShortSK_before: " + DoubleToStr(ShortSK_before, 0); ObjectCreate("ShortSK_before", OBJ_LABEL, 0, 0, 0); ObjectSetText("ShortSK_before", str, 10, "Verdana", White); ObjectSet("ShortSK_before", OBJPROP_CORNER, 0); ObjectSet("ShortSK_before", OBJPROP_XDISTANCE, 20); ObjectSet("ShortSK_before", OBJPROP_YDISTANCE, height); height += 20; str = "ShortSD_before: " + DoubleToStr(ShortSD_before, 0); ObjectCreate("ShortSD_before", OBJ_LABEL, 0, 0, 0); ObjectSetText("ShortSD_before", str, 10, "Verdana", White); ObjectSet("ShortSD_before", OBJPROP_CORNER, 0); ObjectSet("ShortSD_before", OBJPROP_XDISTANCE, 20); ObjectSet("ShortSD_before", OBJPROP_YDISTANCE, height); } //+------------------------------------------------------------------+