20-pips-per-day_v1.2





//+------------------------------------------------------------------+
//|                                              20-pips-per-day.mq4 |
//|                                        Copyright © 2007, LEGRUPO |
//|                                           http://www.legrupo.com |
//|                                                     Version: 1.2 |
//| 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.  |
//+------------------------------------------------------------------+

#include <stderror.mqh>
#include <stdlib.mqh>

#property copyright "Copyright © 2007, LEGRUPO Version 1.2"
#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_v1_1; // 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_v1_1==Time[0])
   return(0);
   LASTRUN_v1_1 = Time[0];
    Alert("EA Start 20-pips-per-day:", TimeDay(LASTRUN_v1_1),"/",TimeMonth(LASTRUN_v1_1),"/",TimeYear(LASTRUN_v1_1));
    
   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);
  }
//+------------------------------------------------------------------+



Sample





Analysis



Market Information Used:

Series array that contains open time of each bar
Series array that contains open prices of each bar
Series array that contains the highest prices of each bar
Series array that contains the lowest prices of each bar
Series array that contains close prices for each bar


Indicator Curves created:


Indicators Used:



Custom Indicators Used:

Order Management characteristics:
Checks for the total of open orders
It automatically opens orders when conditions are reached

Other Features:

It issuies visual alerts to the screen