//+------------------------------------------------------------------+ //| 20-pips-per-day.mq4 | //| Copyright © 2007, LEGRUPO | //| http://www.legrupo.com | //| Version: 1.3 | //| History: | //| 1.0 => Release version to the public | //| 1.1 => bugs fixed by Dave (dmieluk@exemail.com.au): | //| 1) StopLoss was wrong; | //| 2) StopLoss was conflicting with each other; | //| 3) The is_able_to_continue is now much better coded; | //| 3.1) The is_able_to_continue now works on any pair; | //| 4) Now the errors have descriptions instead of numbers. | //| 1.2 => LASTRUN now is display in human readable format by Dave. | //| 1.3 => Added these features: | //| 1) Added the StartOpenOrdersOn to open orders at a | //| specific candle time. It's is good because sometimes you | //| need to close the plataform and reopen, and with this | //| function the EA do not open the orders again since the | //| time allowed is not reached. | //| 2) Added the option to use StopLoss or not. | //| 3) Added the option to use BuyStop and SellStop | //| 4) No anoying alerts anymore. | //+------------------------------------------------------------------+ #include #include #property copyright "MT4Íâ»ã¸úµ¥ÏµÍ³(www.fx789.com)" #property link "http://www.fx789.com" extern string Tips="www.fx789.comÕвÙÅÌÊÖ"; extern string Tips1="MT4±¾µØÍâ»ã×Ô¶¯¸úµ¥ÏµÍ³"; extern string Tips2="Ìṩº°µ¥·þÎñQQ:278118436"; ObjectCreate("label_object_B1", OBJ_LABEL, 0, 0, 0); ObjectSetText("label_object_B1","MT4±¾µØÍâ»ã×Ô¶¯¸úµ¥ÏµÍ³Ãâ·ÑÊÔÓà £ºwww.fx789.com/gendan.rar ",9,"Arial",Yellow); ObjectSet("label_object_B1", OBJPROP_XDISTANCE, 5); ObjectSet("label_object_B1", OBJPROP_YDISTANCE, 10); extern string StartOpenOrdersOn = "FROM 02:14 UNTIL 03:15"; // look on your chart to see when your daily bar open extern bool UseStopLoss = false; extern bool IPreferStopOrders = true; extern int DistanceFromOpen = 20; // Distance the Limit Orders Should be placed extern double TakeProfit = 20; extern double StopLoss = 10; extern double StopAndReverseOnLossOf = 100; extern int MinimumToContinue = 100; // pips the daily bar must have extern double LotSize = 0.1; extern double Slippage = 15; extern string BuyComment = "20 pips per day BUY"; extern string SellComment = "20 pips per day SELL"; extern color clOpenBuy = Blue; extern color clOpenSell = Red; static int LASTRUN_v1_1; // verifica se uma nova bar for aberta int ticket_buy_20PPD, ticket_sell_20PPD = 0; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- int total_orders = OrdersTotal(); int minute = TimeMinute(TimeCurrent()); int hour = TimeHour(TimeCurrent()); //"FROM 02:14 UNTIL 03:15" string temp_variable = ""; // variable used for conversions temp_variable = StringSubstr(StartOpenOrdersOn,5,6); int start_allowed_time_hour = StrToInteger(temp_variable); temp_variable = StringSubstr(StartOpenOrdersOn,8,9); int start_allowed_time_minute = StrToInteger(temp_variable); temp_variable = StringSubstr(StartOpenOrdersOn,17,18); int end_allowed_time_hour = StrToInteger(temp_variable); temp_variable = StringSubstr(StartOpenOrdersOn,20,21); int end_allowed_time_minute = StrToInteger(temp_variable); if (hour >= start_allowed_time_hour && minute >= start_allowed_time_minute && hour <= end_allowed_time_hour && minute <= end_allowed_time_minute ) { Comment("EA will trade only on this time: ", StartOpenOrdersOn); return(0); } else { Comment("EA Start 20-pips-per-day:", TimeDay(TimeCurrent()),"/",TimeMonth(TimeCurrent()),"/",TimeYear(TimeCurrent())); } double curr_open = iOpen(NULL, 0, 0); double last_high = iHigh(NULL, 0, 1); double last_low = iLow(NULL, 0, 1); double last_close = iClose(NULL, 0, 1); double is_able_to_continue = (last_high - last_low)*MathPow(10,Digits); Comment("is_able_to_continue: ", is_able_to_continue); if (is_able_to_continue < MinimumToContinue) { Comment("EA is not able to continue previous bar moved less than ", MinimumToContinue, " pips"); return(0); } else { Comment("EA is able to continue :). Good trade."); } double buy_stoploss,sell_stoploss, buy_price, sell_price, buy_take_profit, sell_take_profit = 0; int order_buy_type,order_sell_type; // now we choose depending on what people want if (IPreferStopOrders) { buy_price = curr_open+DistanceFromOpen*Point; sell_price = curr_open-DistanceFromOpen*Point; order_buy_type = OP_BUYSTOP; order_sell_type = OP_SELLSTOP; } else { buy_price = Ask; sell_price = Bid; order_buy_type = OP_BUY; order_sell_type = OP_SELL; } if (UseStopLoss) { buy_stoploss = buy_price-(StopLoss*Point); sell_stoploss = sell_price+(StopLoss*Point); } else { buy_stoploss = 0; sell_stoploss = 0; } buy_take_profit = buy_price+(TakeProfit*Point); sell_take_profit = sell_price-(TakeProfit*Point); if (OrderSelect(ticket_buy_20PPD, SELECT_BY_TICKET, MODE_TRADES) == false) { ticket_buy_20PPD = OrderSend(Symbol(),order_buy_type,LotSize,buy_price,Slippage,buy_stoploss,buy_take_profit,BuyComment,0,0,clOpenBuy); if (ticket_buy_20PPD < 0) { Alert("Open BUY order error: ", ErrorDescription(GetLastError())); } } if (OrderSelect(ticket_sell_20PPD, SELECT_BY_TICKET, MODE_TRADES) == false) { ticket_sell_20PPD = OrderSend(Symbol(),order_sell_type,LotSize,sell_price,Slippage,sell_stoploss,sell_take_profit,SellComment,0,0,clOpenSell); if (ticket_sell_20PPD < 0) { Alert("Open SELL order error: ", ErrorDescription(GetLastError())); } } //---- return(0); } //+------------------------------------------------------------------+