20-pips-per-day_v1.5

include
include
extern string StartOpenOrdersOn = "FROM 00:00 UNTIL 01:00"; // look on your chart to see when your daily bar open
extern bool UseStopLoss = true;
extern bool IPreferStopOrders = true;
extern int DistanceFromOpen = 20; // Distance the Limit Orders Should be placed
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;
extern int MagicNumber = 123456789;
static int LASTRUN_v1_1; // verifica se uma nova bar for aberta
int ticket_buy_20PPD = 0, 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 Start 20-pips-per-day:", TimeDay(TimeCurrent()),"/",TimeMonth(TimeCurrent()),"/",TimeYear(TimeCurrent()));
} else {
Comment("EA will trade only on this time: ", StartOpenOrdersOn);
return(0);
}
ticket_buy_20PPD = 0;
ticket_sell_20PPD = 0;
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;
int order_buy_type,order_sell_type;
// now we choose depending on what people want
if (IPreferStopOrders) {
buy_price = curr_open+DistanceFromOpenPoint; sell_price = curr_open-DistanceFromOpenPoint;
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-(StopLossPoint); sell_stoploss = sell_price+(StopLossPoint);
} else {
buy_stoploss = 0;
sell_stoploss = 0;
}
buy_take_profit = buy_price+(TakeProfitPoint); sell_take_profit = sell_price-(TakeProfitPoint);
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,MagicNumber,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,MagicNumber,0,clOpenSell);
if (ticket_sell_20PPD < 0) {
Alert("Open SELL order error: ", ErrorDescription(GetLastError()));
}
}
//----
return(0);
}
//+------------------------------------------------------------------+