#property copyright "Copyright © 2008, Don Steinitz" #property link "steinitz@cox.net" #property indicator_chart_window #property indicator_buffers 5 #property indicator_color1 LawnGreen #property indicator_color2 Red #property indicator_color3 Red #property indicator_color4 Blue #property indicator_color5 Orange int gi_76; extern int YourAccountNumber = 12345; bool gi_84 = FALSE; int gi_88 = 12; int gi_92 = 31; int gi_96 = 2008; extern bool Alert_SoundON = TRUE; extern bool EmailON = FALSE; extern bool ShowTradeArrowsOnly = FALSE; extern bool ShowBuySellLines = TRUE; extern string mt = "Mode 0=SMA, 1=EMA, 2=SMMA, 3=LWMA"; extern int MA_Mode = 0; extern int MA_Period = 50; extern double AngleTreshold = 0.25; extern int PrevMAShift = 2; extern int CurMAShift = 0; bool gi_148 = TRUE; bool gi_152 = TRUE; extern int Arrow_Position = 5; extern string to = "---Text Object Settings---"; extern int Text_X_Offset = 20; extern int StatusTxtSize = 10; extern color StatusColor = White; extern int CommentTxtSize = 10; extern color CommentColor = White; extern color BuyColor = Aqua; extern color SellColor = Yellow; int g_datetime_196; double g_ibuf_200[]; double g_ibuf_204[]; double g_ibuf_208[]; double g_ibuf_212[]; double g_ibuf_216[]; int gi_220 = 0; int gi_224 = 0; double gd_228; double gd_236; string gs_244 = ""; string gs_252; string gs_260; int g_datetime_268; int gi_272; int gi_276; int gi_280; string gs_284; string gs_292; string gs_300; string gs_308 = "Steinitz Fractal Breakout Status"; int gi_316; bool gi_320 = FALSE; string gs_324 = "_SFBInd_"; int g_time_332 = 0; bool gi_336 = TRUE; int init() { string ls_0; string ls_8; string ls_16; SetIndexStyle(0, DRAW_ARROW, EMPTY); SetIndexArrow(0, 233); SetIndexBuffer(0, g_ibuf_200); SetIndexStyle(1, DRAW_ARROW, EMPTY); SetIndexArrow(1, 234); SetIndexBuffer(1, g_ibuf_204); SetIndexStyle(2, DRAW_LINE, STYLE_SOLID); SetIndexBuffer(2, g_ibuf_208); SetIndexStyle(3, DRAW_LINE, STYLE_SOLID); SetIndexBuffer(3, g_ibuf_212); SetIndexStyle(4, DRAW_LINE, STYLE_SOLID); SetIndexBuffer(4, g_ibuf_216); switch (MA_Mode) { case 0: ls_0 = "sma10"; ls_8 = "sma21"; ls_16 = "sma50"; break; case 1: ls_0 = "ema10"; ls_8 = "ema21"; ls_16 = "ema50"; break; case 2: ls_0 = "smma10"; ls_8 = "smma21"; ls_16 = "smma50"; break; case 3: ls_0 = "lwma10"; ls_8 = "lwma21"; ls_16 = "lwma50"; break; default: ls_0 = "sma10"; ls_8 = "sma21"; ls_16 = "sma50"; } SetIndexLabel(2, ls_0); SetIndexLabel(3, ls_8); SetIndexLabel(4, ls_16); gd_228 = Get_mFactor(); gi_320 = FALSE; ClearArrows(); DeleteBadLabels(); if (IsDemo() == TRUE) gi_320 = TRUE; if (gi_320 == FALSE) gi_320 = CheckAccountNumber(); if (gi_320 == TRUE) { DeleteExistingLabels(); SetupLabels(); ClearLabels(); gd_236 = SetPoint(); if (MA_Mode >= 4) MA_Mode = 0; OutputStatusToChart(gs_308 + " INITIALIZED SUCCESSFULLY"); if (gi_84 == TRUE) OutputComment1ToChart("Expires on " + gi_88 + "/" + gi_92 + "/" + gi_96); else OutputComment1ToChart("No expiration"); } if (CurMAShift >= PrevMAShift) { Print("Error: CurMAShift >= PrevMAShift"); PrevMAShift = 6; CurMAShift = 0; } return (0); } int deinit() { ClearLabels(); DeleteExistingLabels(); ClearArrows(); DeleteFractObjects(); return (0); } double Get_mFactor() { double ld_ret_0 = 10000.0; string ls_8 = StringSubstr(Symbol(), 3, 3); if (ls_8 == "JPY") ld_ret_0 = 100.0; int li_16 = PrevMAShift - CurMAShift; ld_ret_0 /= li_16; return (ld_ret_0); } int start() { bool li_0; bool li_4; double l_ihigh_8; double l_ilow_16; double l_ima_24; double l_ima_32; double ld_40; int li_48; double l_ima_52; double l_ima_60; double l_ima_68; int li_76 = IndicatorCounted(); if (gi_276 < 10) { SetupLabels(); ClearLabels(); DeleteExistingLabels(); SetupLabels(); } if (gi_320 == FALSE) return (0); gi_316 = CheckTradeFilters(); if (gi_316 == 1) return (0); if (li_76 < 0) return (-1); if (li_76 > 0) li_76--; int li_80 = Bars - li_76; if (g_time_332 == Time[0]) return (0); g_time_332 = Time[0]; if (gi_336) { ClearArrows(); gi_336 = FALSE; } int li_84 = 0; if (ShowTradeArrowsOnly) li_84 = 1; for (int li_88 = li_80 - li_84; li_88 >= 0; li_88--) { l_ima_52 = iMA(NULL, 0, 10, 0, MA_Mode, PRICE_CLOSE, li_88 + li_84); l_ima_60 = iMA(NULL, 0, 21, 0, MA_Mode, PRICE_CLOSE, li_88 + li_84); l_ima_68 = iMA(NULL, 0, 50, 0, MA_Mode, PRICE_CLOSE, li_88 + li_84); g_ibuf_208[li_88 + li_84] = l_ima_52; g_ibuf_212[li_88 + li_84] = l_ima_60; g_ibuf_216[li_88 + li_84] = l_ima_68; g_ibuf_200[li_88] = 0; g_ibuf_204[li_88] = 0; l_ima_24 = iMA(NULL, 0, MA_Period, 0, MA_Mode, PRICE_MEDIAN, li_88 + CurMAShift + li_84); l_ima_32 = iMA(NULL, 0, MA_Period, 0, MA_Mode, PRICE_MEDIAN, li_88 + PrevMAShift + li_84); ld_40 = gd_228 * (l_ima_24 - l_ima_32) / 2.0; ld_40 = NormalizeDouble(ld_40, 2); li_0 = FALSE; li_4 = FALSE; if (ld_40 > AngleTreshold) { li_0 = TRUE; gs_252 = "BUY"; } else { if (ld_40 < -AngleTreshold) { li_4 = TRUE; gs_252 = "SELL"; } } if (gi_148 == TRUE) { if (li_0) if (Low[li_88 + li_84] > l_ima_52) li_0 = FALSE; if (li_4) if (High[li_88 + li_84] < l_ima_52) li_4 = FALSE; } if (gi_152 == TRUE) { if (li_0) if (High[li_88 + li_84] > High[li_88 + 1 + li_84]) li_0 = FALSE; if (li_4) if (Low[li_88 + li_84] < Low[li_88 + 1 + li_84]) li_4 = FALSE; } if (ShowTradeArrowsOnly) { if (li_0) { l_ihigh_8 = iHigh(NULL, 0, li_88 + li_84); if (iHigh(NULL, 0, li_88) <= l_ihigh_8) li_0 = FALSE; } if (li_4) { l_ilow_16 = iLow(NULL, 0, li_88 + li_84); if (iLow(NULL, 0, li_88) >= l_ilow_16) li_4 = FALSE; } } if (l_ima_52 > l_ima_68 && l_ima_60 > l_ima_68 && li_0) { if (ShowTradeArrowsOnly) { if (li_88 == 0 && gi_220 == FALSE) { gi_220 = TRUE; gi_224 = FALSE; if (Alert_SoundON) Alert("BUY Trade ", Symbol(), " on ", tf2txt(Period()), " Steinitz"); if (EmailON) SendMail("BUY Trade " + Symbol(), "Date=" + gs_260 + " on " + tf2txt(Period())); } } else { if (li_88 == 1 && gi_220 == FALSE) { gi_220 = TRUE; gi_224 = FALSE; if (Alert_SoundON) Alert("BUY Alert ", Symbol(), " on ", tf2txt(Period()), " Steinitz"); if (EmailON) SendMail("BUY Alert " + Symbol(), "Date=" + gs_260 + " on " + tf2txt(Period())); } } li_48 = MathRound((High[li_88 + li_84] - l_ima_68) / gd_236); g_datetime_268 = iTime(NULL, 0, li_88 + li_84); gs_260 = TimeToStr(g_datetime_268, TIME_DATE) + " " + TimeHour(g_datetime_268) + ":"; if (TimeMinute(g_datetime_268) < 10) gs_260 = gs_260 + "0"; gs_260 = gs_260 + TimeMinute(g_datetime_268); gs_244 = gs_252 + " - D:" + li_48 + " A:" + DoubleToStr(ld_40, 2) + " at " + gs_260; OutputComment2ToChart(gs_244); g_ibuf_200[li_88] = iLow(NULL, 0, li_88) - Arrow_Position * gd_236; l_ihigh_8 = iHigh(NULL, 0, li_88 + li_84); g_datetime_196 = Time[0]; if (ShowBuySellLines) { DisplayLine("FractBuy", l_ihigh_8, BuyColor); RemoveLine("FractSell"); } } else { if (l_ima_52 < l_ima_68 && l_ima_60 < l_ima_68 && li_4) { if (ShowTradeArrowsOnly) { if (li_88 == 0 && gi_224 == FALSE) { gi_224 = TRUE; gi_220 = FALSE; if (Alert_SoundON) Alert("SELL Trade", Symbol(), " on ", tf2txt(Period()), " Steinitz"); if (EmailON) SendMail("SELL Trade" + Symbol(), "Date=" + gs_260 + " on " + tf2txt(Period())); } } else { if (li_88 == 1 && gi_224 == FALSE) { gi_224 = TRUE; gi_220 = FALSE; if (Alert_SoundON) Alert("SELL Alert", Symbol(), " on ", tf2txt(Period()), " Steinitz"); if (EmailON) SendMail("SELL Alert" + Symbol(), "Date=" + gs_260 + " on " + tf2txt(Period())); } } li_48 = MathRound((l_ima_68 - (Low[li_88 + li_84])) / gd_236); g_datetime_268 = iTime(NULL, 0, li_88 + li_84); gs_260 = TimeToStr(g_datetime_268, TIME_DATE) + " " + TimeHour(g_datetime_268) + ":"; if (TimeMinute(g_datetime_268) < 10) gs_260 = gs_260 + "0"; gs_260 = gs_260 + TimeMinute(g_datetime_268); gs_244 = gs_252 + " - D:" + li_48 + " A:" + DoubleToStr(ld_40, 2) + " at " + gs_260; OutputComment2ToChart(gs_244); g_ibuf_204[li_88] = iHigh(NULL, 0, li_88) + Arrow_Position * gd_236; l_ilow_16 = iLow(NULL, 0, li_88 + li_84); g_datetime_196 = Time[0]; if (ShowBuySellLines) { DisplayLine("FractSell", l_ilow_16, SellColor); RemoveLine("FractBuy"); } } } } return (0); } void ClearArrows() { for (int li_0 = Bars; li_0 >= 0; li_0--) { g_ibuf_204[li_0] = 0; g_ibuf_200[li_0] = 0; } } int CheckTradeFilters() { bool li_0; bool li_ret_4 = FALSE; if (gi_84 == TRUE) { li_0 = FALSE; if (Year() > gi_96) li_0 = TRUE; if (li_0 == FALSE) { if (Year() == gi_96 && Month() > gi_88) li_0 = TRUE; if (li_0 == FALSE) if (Year() == gi_96 && Month() == gi_88 && Day() > gi_92) li_0 = TRUE; } if (li_0 == TRUE) OutputComment1ToChart("Indicator has expired - renew license"); li_ret_4 = li_0; } return (li_ret_4); } double SetPoint() { double ld_ret_0; if (Digits < 4) ld_ret_0 = 0.01; else ld_ret_0 = 0.0001; return (ld_ret_0); } int CheckAccountNumber() { if (YourAccountNumber == AccountNumber() && YourAccountNumber == gi_76) return (1); Alert("AccountNumber entered is incorrect.\n You entered ", YourAccountNumber); return (0); } void ClearLabels() { string ls_0 = " "; OutputLabelToChart(gs_284, gi_272, StatusTxtSize, StatusColor, ls_0, " "); OutputLabelToChart(gs_292, gi_276, CommentTxtSize, CommentColor, ls_0, " "); OutputLabelToChart(gs_300, gi_280, CommentTxtSize, CommentColor, ls_0, " "); } void DeleteBadLabels() { string l_name_0; int l_objs_total_8 = ObjectsTotal(OBJ_LABEL); if (l_objs_total_8 > 0) { for (int l_objs_total_12 = l_objs_total_8; l_objs_total_12 >= 0; l_objs_total_12--) { l_name_0 = ObjectName(l_objs_total_12); if (StringFind(l_name_0, gs_324 + "FractalStatus", 0) >= 0) if (StringFind(l_name_0, Symbol(), 0) < 0) ObjectDelete(l_name_0); if (StringFind(l_name_0, gs_324 + "FractalComment", 0) >= 0) if (StringFind(l_name_0, Symbol(), 0) < 0) ObjectDelete(l_name_0); } } } void DeleteExistingLabels() { string l_name_0; int l_objs_total_8 = ObjectsTotal(OBJ_LABEL); if (l_objs_total_8 > 0) { for (int l_objs_total_12 = l_objs_total_8; l_objs_total_12 >= 0; l_objs_total_12--) { l_name_0 = ObjectName(l_objs_total_12); if (StringFind(l_name_0, Symbol() + gs_324 + "FractalStatus", 0) >= 0) ObjectDelete(l_name_0); else if (StringFind(l_name_0, Symbol() + gs_324 + "FractalComment", 0) >= 0) ObjectDelete(l_name_0); } } } void SetupLabels() { gi_272 = 12; gi_276 = gi_272 + StatusTxtSize + 4; gi_280 = gi_276 + CommentTxtSize + 4; gs_284 = Symbol() + gs_324 + "FractalStatus"; gs_292 = Symbol() + gs_324 + "FractalComment1"; gs_300 = Symbol() + gs_324 + "FractalComment2"; } void OutputLabelToChart(string a_name_0, int a_y_8, int a_fontsize_12, color a_color_16, string a_text_20, string as_unused_28) { if (ObjectFind(a_name_0) != 0) { ObjectCreate(a_name_0, OBJ_LABEL, 0, 0, 0); ObjectSet(a_name_0, OBJPROP_CORNER, 0); ObjectSet(a_name_0, OBJPROP_XDISTANCE, Text_X_Offset); ObjectSet(a_name_0, OBJPROP_YDISTANCE, a_y_8); } ObjectSetText(a_name_0, a_text_20, a_fontsize_12, "Arial Bold", a_color_16); } void OutputStatusToChart(string as_0) { OutputLabelToChart(gs_284, gi_272, StatusTxtSize, StatusColor, as_0, "*"); } void OutputComment1ToChart(string as_0) { OutputLabelToChart(gs_292, gi_276, CommentTxtSize, CommentColor, as_0, "*"); } void OutputComment2ToChart(string as_0) { OutputLabelToChart(gs_300, gi_280, CommentTxtSize, CommentColor, as_0, "*"); } string tf2txt(int ai_0) { switch (ai_0) { case 1: return ("M1"); case 5: return ("M5"); case 15: return ("M15"); case 30: return ("M30"); case 60: return ("H1"); case 240: return ("H4"); case 1440: return ("D1"); case 10080: return ("W1"); case 43200: return ("MN"); } return ("??"); } void DisplayLine(string as_0, double a_price_8, color a_color_16) { string l_name_20 = gs_324 + as_0; if (ObjectFind(l_name_20) != 0) { ObjectCreate(l_name_20, OBJ_HLINE, 0, g_datetime_196, a_price_8); ObjectSet(l_name_20, OBJPROP_STYLE, STYLE_DASHDOTDOT); ObjectSet(l_name_20, OBJPROP_COLOR, a_color_16); ObjectSet(l_name_20, OBJPROP_WIDTH, 1); return; } ObjectMove(l_name_20, 0, g_datetime_196, a_price_8); } void DeleteFractObjects() { ObjectDelete(gs_324 + "FractBuy"); ObjectDelete(gs_324 + "FractSell"); } void RemoveLine(string as_0) { ObjectDelete(gs_324 + as_0); }