//+------------------------------------------------------------------+ //| UsingTextStub.mq4 | //| | //| This stub shows how to use text objects to replace comments | //| | //+------------------------------------------------------------------+ #property copyright "Robert Hill" #property link "None" #include #define FLAT 0 #define LONG 1 #define SHORT 2 bool UseExpire = true; // change to true for expiration int ExpireMonth = 2; int ExpireDay = 10; int ExpireYear = 2010; //extern variables extern int MagicNumber = 12345; // Use 3 SMAs to determine trend extern int MA_Period1 = 7; extern int MA_Period2 = 14; extern int MA_Period3 = 21; extern string to="---Text Object Settings---"; extern int StatusTxtSize = 10; extern color StatusColor = White; extern int CommentTxtSize = 10; extern color CommentColor = White; extern int TrendTxtSize = 12; extern color TrendTxtColorLong = Green; extern color TrendTxtColorShort = Red; int StatusY, Comment1Y, Comment2Y, TrendY; string StatusLabel, Comment1Label, Comment2Label, TrendLabel; string StatusStr = "TextStub Status"; double myPoint; int myDigit; bool YesStop; int init() { DeleteExistingLabels(); SetupLabels(); ClearLabels(); myPoint = SetPoint(); myDigit = SetDigit(); OutputStatusToChart(StatusStr + " INITIALIZED SUCCESSFULLY"); return(0); } int deinit() { ClearLabels(); DeleteExistingLabels(); return(0); } int start() { int NumOrders = 0, Signal; if (Comment1Y < 10) { SetupLabels(); ClearLabels(); DeleteExistingLabels(); SetupLabels();// Make sure label settings are OK } if (IsTesting() == false) { if (IsExpertEnabled() == false) { OutputComment1ToChart("Expert is not enabled"); return(0); } } if (IsTradeAllowed()==false ) return(0); NumOrders = CalculateCurrentOrders(); if(NumOrders == 0) { YesStop = CheckTradeFilters(); if (YesStop == false) { Signal = CheckForOpenNewTrades(); } } else { RefreshRates(); CheckForCloseTrades(); } return(0); } //+------------------------------------------------------------------+ int CheckForOpenNewTrades() { int mySignal; OutputComment2ToChart("Looking for Trade Signal"); mySignal = GetMA_CrossSignal(); if (mySignal == LONG) OutputTrendToChart( "Trend is UP on " + tf2txt(Period()), TrendTxtColorLong); if (mySignal == SHORT) OutputTrendToChart( "Trend is DOWN on " + tf2txt(Period()), TrendTxtColorShort); if (mySignal == FLAT) OutputTrendToChart( "Trend is FLAT on " + tf2txt(Period()), White); return(mySignal); } //+------------------------------------------------------------------+ // Use 3 SMAs to determine trend int GetMA_CrossSignal() { double ma1, ma2, ma3; int myOrder = FLAT; ma1 = iMA(NULL, 0, MA_Period1, 0, MODE_SMA, PRICE_CLOSE, 1); ma2 = iMA(NULL, 0, MA_Period2, 0, MODE_SMA, PRICE_CLOSE, 1); ma3 = iMA(NULL, 0, MA_Period3, 0, MODE_SMA, PRICE_CLOSE, 1); ma1 = NormalizeDouble(ma1, myDigit); ma2 = NormalizeDouble(ma2, myDigit); ma3 = NormalizeDouble(ma3, myDigit); if (ma1 > ma3) { if (ma2 > ma3) myOrder = LONG; else myOrder = FLAT; } if (ma1 < ma3) { if (ma2 < ma3) myOrder = SHORT; else myOrder = FLAT; } return (myOrder); } // Add your code to exit trades void CheckForCloseTrades() { } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| Filters_inc.mqh | //| Copyright © 2007 | //| | //+------------------------------------------------------------------+ bool CheckTradeFilters() { bool myStop, Expired; double CurrentSpread; myStop = false; if (UseExpire == true) { Expired = false; if (Year() > ExpireYear) Expired = true; if (Expired == false) { if (Year() == ExpireYear && Month() > ExpireMonth) Expired = true; if (Expired == false) { if (Year() == ExpireYear && Month() == ExpireMonth && Day() > ExpireDay) Expired = true; } } if (Expired == true) { OutputComment1ToChart ("EA has expired - renew license"); } else OutputComment1ToChart("Expires on " + ExpireMonth + "/" + ExpireDay + "/" + ExpireYear); myStop = Expired; } else OutputComment1ToChart ("EA has no expiration"); return(myStop); } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| Utils_inc.mqh | //| Copyright © 2007 | //| | //+------------------------------------------------------------------+ double SetPoint() { double mPoint; if (Digits < 4) mPoint = 0.01; else mPoint = 0.0001; return(mPoint); } double SetDigit() { double mDigit; if (Digits < 4) mDigit = 2; else mDigit = 4; return(mDigit); } int CalculateCurrentOrders() { int buys = 0, sells = 0, num = 0; for(int i=0;i 0) { for (int i = objLabels; i >= 0;i--) { objName = ObjectName(i); if (StringFind(objName,Symbol() + "Status", 0) >= 0) { ObjectDelete(objName); continue; } if (StringFind(objName,Symbol() + "Comment", 0) >= 0) { ObjectDelete(objName); continue; } if (StringFind(objName,Symbol() + "Trend", 0) >= 0) { ObjectDelete(objName); continue; } } } } void SetupLabels() { StatusY = 12; Comment1Y = StatusY + StatusTxtSize + 4; Comment2Y = Comment1Y + CommentTxtSize + 4; TrendY = Comment2Y + CommentTxtSize + 4; StatusLabel = Symbol() + "Status"; Comment1Label = Symbol() + "Comment1"; Comment2Label = Symbol() + "Comment2"; TrendLabel = Symbol() + "Trend"; } void OutputLabelToChart(string LabelName, int LabelY, int LabelTxtSize, color LabelColor, string LabelStr) { if(ObjectFind(LabelName) != 0) { ObjectCreate(LabelName, OBJ_LABEL, 0, 0, 0); ObjectSet(LabelName, OBJPROP_CORNER, 0); ObjectSet(LabelName, OBJPROP_XDISTANCE, 20); ObjectSet(LabelName, OBJPROP_YDISTANCE, LabelY); } ObjectSetText(LabelName, LabelStr, LabelTxtSize, "Arial Bold", LabelColor); } void OutputStatusToChart(string mComment) { OutputLabelToChart(StatusLabel, StatusY, StatusTxtSize, StatusColor, mComment); } void OutputComment1ToChart(string mComment) { OutputLabelToChart(Comment1Label, Comment1Y, CommentTxtSize, CommentColor, mComment); } void OutputComment2ToChart(string mComment) { OutputLabelToChart(Comment2Label, Comment2Y, CommentTxtSize, CommentColor, mComment); } void OutputTrendToChart(string mComment, color mColor) { OutputLabelToChart(TrendLabel, TrendY, TrendTxtSize, mColor, mComment); } //+------------------------------------------------------------------+