Código:
//-------------------------------------------------------------
// GNUSoft Ltda. Forex EA and Script Generator version 6.2 EA
//-------------------------------------------------------------
// Keywords: MT4, Forex EA builder, create EA, expert advisor developer
#property copyright "Copyright © 2014-2017, GNUSoft. Forex EA Generator v6.2"
#property link "http://www.generador-mql.com"
#include <stdlib.mqh>
#include <WinUser32.mqh>
// exported variables
extern double BuyLots10 = 0.1;
extern int BuyStoploss10 = 0;
extern int BuyTakeprofit10 = 0;
extern string BuyExpertName10 = "";
extern double SellLots11 = 0.1;
extern int SellStoploss11 = 0;
extern int SellTakeprofit11 = 0;
extern string SellExpertName11 = "";
// local variables
double PipValue=1; // this variable is here to support 5-digit brokers
bool Terminated = false;
string LF = "\n"; // use this in custom or utility blocks where you need line feeds
int NDigits = 4; // used mostly for NormalizeDouble in Flex type blocks
int ObjCount = 0; // count of all objects created on the chart, allows creation of objects with unique names
int current = 0; // current bar index, used by Cross Up, Cross Down and many other blocks
int varylots[101]; // used by Buy Order Varying, Sell Order Varying and similar
int flag1=0,flag2=0; //
int init()
{
NDigits = Digits;
if (false) ObjectsDeleteAll(); // clear the chart
Comment(""); // clear the chart
return (0);
}
// Expert start
int start()
{
if (Bars < 10)
{
Comment("Not enough bars");
return (0);
}
if (Terminated == true)
{
Comment("EA Terminated.");
return (0);
}
OnEveryTick1();
return (0);
}
void OnEveryTick1()
{
PipValue = 1;
if (NDigits == 3 || NDigits == 5) PipValue = 10;
IfOrderExists12();
IfOrderExists13();
IfOrderDoesNotExist2();
IfOrderDoesNotExist3();
}
void IfOrderExists12()
{
bool exists = false;
for (int i=OrdersTotal()-1; i >= 0; i--)
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == 1)
{
exists = true;
}
}
else
{
Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
}
if (exists)
{
TechnicalAnalysis14();
}
}
void TechnicalAnalysis14()
{
if (iCustom(NULL, PERIOD_CURRENT, "3_Level_ZZ_Semafor",4,current) > 0)
{
CloseOrder16();
flag1=0;
}
}
void CloseOrder16()
{
int orderstotal = OrdersTotal();
int orders = 0;
int ordticket[90][2];
for (int i = 0; i < orderstotal; i++)
{
bool sel = OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if (OrderType() != OP_BUY || OrderSymbol() != Symbol() || OrderMagicNumber() != 1)
{
continue;
}
ordticket[orders][0] = OrderOpenTime();
ordticket[orders][1] = OrderTicket();
orders++;
}
if (orders > 1)
{
ArrayResize(ordticket,orders);
ArraySort(ordticket);
}
for (i = 0; i < orders; i++)
{
if (OrderSelect(ordticket[i][1], SELECT_BY_TICKET) == true)
{
bool ret = OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 4, Blue);
if (ret == false)
Print("OrderClose() error - ", ErrorDescription(GetLastError()));
}
}
}
void IfOrderExists13()
{
bool exists = false;
for (int i=OrdersTotal()-1; i >= 0; i--)
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == 1)
{
exists = true;
}
}
else
{
Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
}
if (exists)
{
TechnicalAnalysis15();
flag2=0;
}
}
void TechnicalAnalysis15()
{
if (iCustom(NULL, PERIOD_CURRENT, "3_Level_ZZ_Semafor",5,current) > 0)
{
CloseOrder17();
}
}
void CloseOrder17()
{
int orderstotal = OrdersTotal();
int orders = 0;
int ordticket[90][2];
for (int i = 0; i < orderstotal; i++)
{
bool sel = OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if (OrderType() != OP_SELL || OrderSymbol() != Symbol() || OrderMagicNumber() != 1)
{
continue;
}
ordticket[orders][0] = OrderOpenTime();
ordticket[orders][1] = OrderTicket();
orders++;
}
if (orders > 1)
{
ArrayResize(ordticket,orders);
ArraySort(ordticket);
}
for (i = 0; i < orders; i++)
{
if (OrderSelect(ordticket[i][1], SELECT_BY_TICKET) == true)
{
bool ret = OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 4, Red);
if (ret == false)
Print("OrderClose() error - ", ErrorDescription(GetLastError()));
}
}
}
void IfOrderDoesNotExist2()
{
bool exists = false;
for (int i=OrdersTotal()-1; i >= 0; i--)
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == 1)
{
exists = true;
}
}
else
{
Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
}
if (exists == false)
{
TechnicalAnalysis4();
}
if (exists == false && flag1 == 1)
{
TechnicalAnalysis5();
}
}
void TechnicalAnalysis4()
{
if (iCustom(NULL, PERIOD_CURRENT, "3_Level_ZZ_Semafor",5,current) > 0)
{
flag1=1;
flag2=0;
Print(flag1," flag1 ",flag2 );
}
}
void TechnicalAnalysis5()
{
if (iCustom(NULL, PERIOD_CURRENT, "KRSI",9,1,current) > iCustom(NULL, PERIOD_CURRENT, "KRSI",9,2,current))
{
BuyOrder10();
}
}
void BuyOrder10()
{
double SL = Ask - BuyStoploss10*PipValue*Point;
if (BuyStoploss10 == 0) SL = 0;
double TP = Ask + BuyTakeprofit10*PipValue*Point;
if (BuyTakeprofit10 == 0) TP = 0;
int ticket = -1;
if (true)
ticket = OrderSend(Symbol(), OP_BUY, BuyLots10, Ask, 4, 0, 0, BuyExpertName10, 1, 0, Blue);
else
ticket = OrderSend(Symbol(), OP_BUY, BuyLots10, Ask, 4, SL, TP, BuyExpertName10, 1, 0, Blue);
if (ticket > -1)
{
if (true)
{
bool sel = OrderSelect(ticket, SELECT_BY_TICKET);
bool ret = OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0, Blue);
if (ret == false)
Print("OrderModify() error - ", ErrorDescription(GetLastError()));
}
}
else
{
Print("OrderSend() error - ", ErrorDescription(GetLastError()));
}
}
void IfOrderDoesNotExist3()
{
bool exists = false;
for (int i=OrdersTotal()-1; i >= 0; i--)
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == 1)
{
exists = true;
}
}
else
{
Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
}
if (exists == false)
{
TechnicalAnalysis6();
}
if (exists == false && flag2 == 1)
{
TechnicalAnalysis7();
}
}
void TechnicalAnalysis6()
{
if (iCustom(NULL, PERIOD_CURRENT, "3_Level_ZZ_Semafor",4,current) > 0)
{
flag2=1;
flag1=0;
Print(flag1," flag2 ",flag2 );
}
}
void TechnicalAnalysis7()
{
if (iCustom(NULL, PERIOD_CURRENT, "KRSI",9,2,current) > iCustom(NULL, PERIOD_CURRENT, "KRSI",9,1,current))
{
SellOrder11();
}
}
void SellOrder11()
{
double SL = Bid + SellStoploss11*PipValue*Point;
if (SellStoploss11 == 0) SL = 0;
double TP = Bid - SellTakeprofit11*PipValue*Point;
if (SellTakeprofit11 == 0) TP = 0;
int ticket = -1;
if (true)
ticket = OrderSend(Symbol(), OP_SELL, SellLots11, Bid, 4, 0, 0, SellExpertName11, 1, 0, Red);
else
ticket = OrderSend(Symbol(), OP_SELL, SellLots11, Bid, 4, SL, TP, SellExpertName11, 1, 0, Red);
if (ticket > -1)
{
if (true)
{
bool sel = OrderSelect(ticket, SELECT_BY_TICKET);
bool ret = OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0, Red);
if (ret == false)
Print("OrderModify() error - ", ErrorDescription(GetLastError()));
}
}
else
{
Print("OrderSend() error - ", ErrorDescription(GetLastError()));
}
}
int deinit()
{
if (false) ObjectsDeleteAll();
return (0);
}