//————————————————————-
// Etasoft Inc. Forex EA and Script Generator version 4.1 EA
//————————————————————-
// Keywords: MT4, Forex EA builder, create EA, expert advisor developer#property copyright “Copyright ?2011, Etasoft Inc. Forex EA Generator v4.1”
#property link “http://www.forexgenerator.com/”#include <stdlib.mqh>
#include <WinUser32.mqh>// exported variables
extern double BuyLots2 = 1;
extern int BuyStoploss2 = 20;
extern int BuyTakeprofit2 = 20;
extern int PriceOffset2 = 20;
extern double SellLots3 = 1;
extern int SellStoploss3 = 20;
extern int SellTakeprofit3 = 20;
extern int PriceOffset3 = 20;// 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;
int init()
{
NDigits = Digits;if (false) ObjectsDeleteAll(); // clear the chart
Comment(“”); // clear the chart
}// Expert start
int start()
{
if (Bars < 10)
{
Comment(“Not enough bars”);
return (0);
}
if (Terminated == true)
{
Comment(“EA Terminated.”);
return (0);
}OnEveryTick1();
}
void OnEveryTick1()
{
if (true == false && false) PipValue = 10;
if (true && (NDigits == 3 || NDigits == 5)) PipValue = 10;IfOrderExists8();
IfOrderExists16();
IfOrderDoesNotExist7();
IfOrderDoesNotExist22();}
void IfOrderExists8()
{
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)
{
DeletePendingOrder9();}
}void DeletePendingOrder9()
{for (int i=OrdersTotal()-1; i >= 0; i–)
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderType() == OP_SELLSTOP && OrderSymbol() == Symbol() && OrderMagicNumber() == 2)
{
bool ret = OrderDelete(OrderTicket(), Red);if (ret == false)
{
Print(“OrderDelete() error – “, ErrorDescription(GetLastError()));
}
}
}}
void IfOrderExists16()
{
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() == 2)
{
exists = true;
}
}
else
{
Print(“OrderSelect() error – “, ErrorDescription(GetLastError()));
}if (exists)
{
DeletePendingOrder18();}
}void DeletePendingOrder18()
{for (int i=OrdersTotal()-1; i >= 0; i–)
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderType() == OP_BUYSTOP && OrderSymbol() == Symbol() && OrderMagicNumber() == 1)
{
bool ret = OrderDelete(OrderTicket(), Red);if (ret == false)
{
Print(“OrderDelete() error – “, ErrorDescription(GetLastError()));
}
}
}}
void IfOrderDoesNotExist7()
{
bool exists = false;
for (int i=OrdersTotal()-1; i >= 0; i–)
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderType() == OP_BUYSTOP && OrderSymbol() == Symbol() && OrderMagicNumber() == 1)
{
exists = true;
}
}
else
{
Print(“OrderSelect() error – “, ErrorDescription(GetLastError()));
}if (exists == false)
{
BuyPendingOrder2();}
}void BuyPendingOrder2()
{
int expire = TimeCurrent() + 60 * 6000000;
double price = NormalizeDouble(Ask, NDigits) + PriceOffset2*PipValue*Point;
double SL = price – BuyStoploss2*PipValue*Point;
if (BuyStoploss2 == 0) SL = 0;
double TP = price + BuyTakeprofit2*PipValue*Point;
if (BuyTakeprofit2 == 0) TP = 0;
if (6000000 == 0) expire = 0;
int ticket = OrderSend(Symbol(), OP_BUYSTOP, BuyLots2, price, 4, SL, TP, “My Expert”, 1, expire, Blue);
if (ticket == -1)
{
Print(“OrderSend() error – “, ErrorDescription(GetLastError()));
}
SellPendingOrder3();}
void SellPendingOrder3()
{
int expire = TimeCurrent() + 60 * 600000;
double price = NormalizeDouble(Bid, NDigits) – PriceOffset3*PipValue*Point;
double SL = price + SellStoploss3*PipValue*Point;
if (SellStoploss3 == 0) SL = 0;
double TP = price – SellTakeprofit3*PipValue*Point;
if (SellTakeprofit3 == 0) TP = 0;
if (600000 == 0) expire = 0;
int ticket = OrderSend(Symbol(), OP_SELLSTOP, SellLots3, price, 4, SL, TP, “My Expert”, 2, expire, Red);
if (ticket == -1)
{
Print(“OrderSend() error – “, ErrorDescription(GetLastError()));
}}
void IfOrderDoesNotExist22()
{
bool exists = false;
for (int i=OrdersTotal()-1; i >= 0; i–)
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderType() == OP_SELLSTOP && OrderSymbol() == Symbol() && OrderMagicNumber() == 2)
{
exists = true;
}
}
else
{
Print(“OrderSelect() error – “, ErrorDescription(GetLastError()));
}if (exists == false)
{
BuyPendingOrder2();}
}
int deinit()
{
if (false) ObjectsDeleteAll();}
相关资源
暂无评论...