//+------------------------------------------------------------------+ //| 20-pips-per-day.mq4 | //| Copyright © 2007, LEGRUPO | //| http://www.legrupo.com | //| Version: 1.1 | //| 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. | //+------------------------------------------------------------------+ #include #include #property copyright "Copyright © 2007, LEGRUPO Version 1.1" #property link "http://www.legrupo.com" extern double TakeProfit = 40; extern double StopLoss = 20; 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_4; // verifica se uma nova bar for aberta int ticket_buy, ticket_sell = 0; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- int total_orders = OrdersTotal(); if (LASTRUN_4==Time[0]) return(0); LASTRUN_4 = Time[0]; Alert("EA Start 20-pips-per-day:", LASTRUN_4); 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); Print("is_able_to_continue: ", is_able_to_continue); if (is_able_to_continue < MinimumToContinue) { return(0); } //if (total_orders == 0) { ticket_buy = OrderSend(Symbol(),OP_BUY,LotSize,Ask,Slippage,Ask-(StopLoss*Point),Ask+(TakeProfit*Point),BuyComment,0,0,clOpenBuy); if (ticket_buy < 0) { Alert("Open BUY order error: ", ErrorDescription(GetLastError())); } ticket_sell = OrderSend(Symbol(),OP_SELL,LotSize,Bid,Slippage,Bid+(StopLoss*Point),Bid-(TakeProfit*Point),SellComment,0,0,clOpenSell); if (ticket_sell < 0) { Alert("Open SELL order error: ", ErrorDescription(GetLastError())); } //} //---- return(0); } //+------------------------------------------------------------------+