这个EA使用了远程访问网页,调取GMT时区。
#include <stdlib.mqh>
#import "wininet.dll"
int InternetOpenA(string a0, int a1, string a2, string a3, int a4);
int InternetOpenUrlA(int a0, string a1, string a2, int a3, int a4, int a5);
int InternetReadFile(int a0, string a1, int a2, int& a3[]);
int InternetCloseHandle(int a0);
#import
extern int Account_Number = 112233;
extern int Magic = 1643164;
extern int OrdersType = 1;
extern bool Agressive = FALSE;
extern int EnvPeriod = 4;
extern double EnvDev = 0.05;
extern int SL = 25;
extern int TP = 20;
extern bool MM = TRUE;
extern int Risk = 10;
extern double MinLot = 0.1;
extern bool CloseBy = TRUE;
extern int ClosePips = 3;
extern bool Auto_GMT_Offset = TRUE;
extern int Manual_GMT_Offset = 0;
extern string GMT_Trading_Hour = "Default 20 and 0";
extern int OpenHour = 0;
extern int CloseHour = 23;
extern int Friday = 65;
extern int Monday = 5;
extern bool Use_Trailing = FALSE;
extern int TrailingStart = 1;
extern int TrailingStop = 15;
extern int MaxSpread = 2;
extern int EnvMethod = 0;
extern int EnvPrice = 1;
extern int Slippage = 3;
int gi_196 = 0;
string gs_200 = "http://www.eaturbo.com/gmt.php";
string gs_208 = "AlexGmtOffset 1.0";
int gi_216 = -1;
bool gi_unused_220 = TRUE;
bool gi_unused_224 = TRUE;
int gi_228;
string gs_232;
string gs_240;
string gs_248;
string gs_256;
bool gi_264 = TRUE;
bool gi_268;
double gd_unused_272;
double gd_unused_280;
int gi_288;
int gi_292;
int g_datetime_296 = 0;
int g_datetime_300 = 0;
int g_datetime_304 = 0;
int g_datetime_308 = 0;
int g_datetime_312 = 0;
int g_datetime_316 = 0;
int g_leverage_320;
string g_comment_324 = "Night Turbo";
double gd_332;
string gs_340;
int gi_348;
string gs_352;
int gi_360;
int gi_364;
string gs_368 = "2010.12.31";
bool gi_376 = TRUE;
bool gi_unused_380 = TRUE;
void ads() {
}
void SetLab(string a_name_0, int a_x_8, int a_y_12, int a_corner_16, string a_text_20, int a_fontsize_28, string a_fontname_32, color a_color_40 = -1) {
ObjectCreate(a_name_0, OBJ_LABEL, 0, 0, 0);
ObjectSet(a_name_0, OBJPROP_XDISTANCE, a_x_8);
ObjectSet(a_name_0, OBJPROP_YDISTANCE, a_y_12);
ObjectSet(a_name_0, OBJPROP_CORNER, a_corner_16);
ObjectSetText(a_name_0, a_text_20, a_fontsize_28, a_fontname_32, a_color_40);
}
void DisplayInfo() {
if (Agressive) gs_340 = "*** AGRESSIVE MODE ***";
else gs_340 = "*** MODERATE MODE ***";
double l_stoplevel_0 = MarketInfo(Symbol(), MODE_STOPLEVEL);
Comment(" ---------------------------------------------",
"\n ", gs_340, " ", gs_256,
"\n ---------------------------------------------",
"\n :: Take Profit : ", TP,
"\n :: Stop Loss : ", SL,
"\n :: Indi Period : ", EnvPeriod,
"\n :: Indi Dev. : ", EnvDev,
"\n -----------------------------------",
"\n :: Use Close By: ", ClosePips, " ", gs_232,
"\n :: Use Trailing : ", gs_248,
"\n :: Trailing Stop : ", TrailingStop,
"\n -----------------------------------",
"\n :: Use MM : ", gs_240,
"\n :: Maximum Risk : ", Risk,
"\n :: Current Lots : ", Lots(),
"\n -----------------------------------",
"\n :: Symbol : ", Symbol(),
"\n :: Spread : ", MarketInfo(Symbol(), MODE_SPREAD),
"\n :: Stop Level : ", l_stoplevel_0,
"\n :: Magic : ", Magic,
"\n :: Trading Type : ", OrdersType,
"\n -----------------------------------",
"\n :: GMT Offset : ", DoubleToStr(gi_228, 1), " TT:", TradingTime(),
"\n :: Trade Hour (GMT): ", DoubleToStr(OpenHour, 2), " - ", DoubleToStr(CloseHour, 2),
"\n :: Trade Hour (Server): ", DoubleToStr(gi_360, 2), "-", DoubleToStr(gi_364, 2),
"\n :: Current Hours (server) : ", Hour(), ":", Minute(),
"\n -----------------------------------");
}
int init() {
Comment("Waiting for quotes...");
if (!IsTesting()) {
if (!IsDllsAllowed()) {
Alert("Set \"AllowDLL Imports\" ON in menu Tools->Options->ExpertAdvisors!");
Print("Set \"AllowDLL Imports\" ON in menu Tools->Options->ExpertAdvisors!");
Comment("Warning: Set Parameter \"AllowDLL Imports\" ON in menu Tools -> Options -> ExpertAdvisors!");
return (0);
}
}
gi_348 = Account_Number;
if (Digits == 5) {
TP = 10 * TP;
SL = 10 * SL;
ClosePips = 10 * ClosePips;
TrailingStart = 10 * TrailingStart;
TrailingStop = 10 * TrailingStop;
MaxSpread = 10 * MaxSpread;
Print("Digits = ", Digits);
}
g_leverage_320 = AccountLeverage();
gs_352 = Symbol();
string ls_0 = StringSubstr(gs_352, 0, 6);
if (ls_0 != "EURGBP" && ls_0 != "EURCHF" && ls_0 != "GBPCHF" && ls_0 != "AUDNZD") {
Alert("This EA only designed for EURCHF,EURGPB,GBPCHF,AUDNZD!");
Print("This EA only designed for EURCHF,EURGPB,GBPCHF,AUDNZD!");
Comment("Error: Wrong Currency Pair! Use EA BOSS on EURCHF,EURGPB,GBPCHF,AUDNZD only!");
return (0);
}
if (Auto_GMT_Offset) Manual_GMT_Offset = AutoGMTCalculation();
gi_228 = Manual_GMT_Offset;
if (gi_228 < 0) gi_228 += 24;
if (gi_228 == -2147483624) {
Sleep(60000);
return (0);
}
gi_360 = OpenHour + gi_228;
gi_364 = CloseHour + gi_228;
while (true) {
if (gi_360 >= 24) {
gi_360 -= 24;
continue;
}
if (gi_360 >= 0) break;
gi_360 += 24;
}
while (true) {
if (gi_364 >= 24) {
gi_364 -= 24;
continue;
}
if (gi_364 >= 0) break;
gi_364 += 24;
}
return (0);
}
int start() {
int l_str2time_0;
double l_price_12;
double l_price_20;
int l_ticket_28;
int li_32;
int li_36;
int li_40;
int li_44;
int l_ticket_48;
int l_ticket_52;
double l_ord_open_price_56;
double l_ord_open_price_64;
int li_72;
if (MarketInfo(Symbol(), MODE_SPREAD) > MaxSpread) {
Comment("\n Spread too big!",
"\n Max Spread Setting : ", MaxSpread,
"\n Current Spread : ", Ask - Bid,
"\n If you still want to trade, change MaxSpead Setting");
return;
}
int li_unused_76 = gi_348;
if (gi_376) {
l_str2time_0 = StrToTime(gs_368);
if (TimeCurrent() >= l_str2time_0) {
Alert("Your EA Error " + g_leverage_320 + ", please contact eaturbo.com");
return (0);
}
}
ads();
DisplayInfo();
if (CloseBy) gs_232 = "ON";
else gs_232 = "OFF";
if (MM) gs_240 = "ON";
else gs_240 = "OFF";
if (Use_Trailing) gs_248 = "ON";
else gs_248 = "OFF";
if (CloseBy) CloseProfit();
if (Friday > 0) {
if (TimeDayOfWeek(TimeCurrent()) == 5) {
if (TimeCurrent() > 86400 * (TimeCurrent() / 86400) + 86400 - 60 * Friday) {
fOrderDeleteLimit();
fOrderCloseMarket();
return (0);
}
}
}
if (Monday > 0) {
if (TimeDayOfWeek(TimeCurrent()) == 1)
if (TimeCurrent() < 86400 * (TimeCurrent() / 86400) + 60 * Monday) return (0);
}
if (Ask - Bid <= MaxSpread * Point) {
if (TradingTime() == 1) {
if (gi_264) {
gd_unused_272 = Ask;
gd_unused_280 = Bid;
gi_264 = FALSE;
return (0);
}
gs_256 = "";
if (OrdersType == 0) {
l_price_12 = ND(iEnvelopes(NULL, 0, EnvPeriod, EnvMethod, 0, EnvPrice, EnvDev, MODE_UPPER, 0));
l_price_20 = ND(iEnvelopes(NULL, 0, EnvPeriod, EnvMethod, 0, EnvPrice, EnvDev, MODE_LOWER, 0) - (Ask - Bid));
li_32 = 0;
li_36 = 0;
li_40 = 0;
li_44 = 0;
li_72 = fOrdersCounter(li_32, li_36, li_40, li_44, l_ord_open_price_56, l_ord_open_price_64, l_ticket_48, l_ticket_52);
if (li_72 == -1) return;
if (li_40 == 0 && li_32 == 0 || Agressive) {
if (Close[0] < l_price_20 && gi_288 != Time[0]) {
l_ticket_28 = OrderSend(Symbol(), OP_BUY, Lots(), Ask, Slippage, Ask - SL * Point, Ask + TP * Point, g_comment_324, Magic, 0, Blue);
if (l_ticket_28 > 0) gi_288 = Time[0];
Print(GetLastError());
Sleep(500);
RefreshRates();
}
}
if (li_44 == 0 && li_36 == 0 || Agressive) {
if (Close[0] > l_price_12 && gi_292 != Time[0]) {
l_ticket_28 = OrderSend(Symbol(), OP_SELL, Lots(), Bid, Slippage, Bid + SL * Point, Bid - TP * Point, g_comment_324, Magic, 0, Red);
if (l_ticket_28 > 0) gi_292 = Time[0];
Print(GetLastError());
Sleep(500);
RefreshRates();
}
}
}
if (OrdersType == 1) {
l_price_12 = ND(iEnvelopes(NULL, 0, EnvPeriod, EnvMethod, 0, EnvPrice, EnvDev, MODE_UPPER, 0));
l_price_20 = ND(iEnvelopes(NULL, 0, EnvPeriod, EnvMethod, 0, EnvPrice, EnvDev, MODE_LOWER, 0) - (Ask - Bid));
li_32 = 0;
li_36 = 0;
li_40 = 0;
li_44 = 0;
li_72 = fOrdersCounter(li_32, li_36, li_40, li_44, l_ord_open_price_56, l_ord_open_price_64, l_ticket_48, l_ticket_52);
if (li_72 == -1) return;
if (li_40 == 0 && li_32 == 0) {
if (l_price_20 < ND(Ask - Point * MarketInfo(Symbol(), MODE_STOPLEVEL))) {
l_ticket_28 = OrderSend(Symbol(), OP_BUYLIMIT, Lots(), l_price_20, 0, l_price_20 - SL * Point, l_price_20 + TP * Point, g_comment_324, Magic, 0, DarkGreen);
Print("BuyLimit: " + GetLastError());
Sleep(500);
RefreshRates();
}
} else {
if (ND(l_ord_open_price_56) != l_price_20 && gi_288 != Time[0]) {
OrderModify(l_ticket_48, l_price_20, l_price_20 - SL * Point, l_price_20 + TP * Point, 0, DarkGreen);
gi_288 = Time[0];
Print("Modify BuyLimit: " + GetLastError());
Sleep(500);
RefreshRates();
}
}
if (li_44 == 0 && li_36 == 0) {
if (l_price_12 > ND(Bid + Point * MarketInfo(Symbol(), MODE_STOPLEVEL))) {
l_ticket_28 = OrderSend(Symbol(), OP_SELLLIMIT, Lots(), l_price_12, 0, l_price_12 + SL * Point, l_price_12 - TP * Point, g_comment_324, Magic, 0, DeepPink);
Print("SellLimit: " + GetLastError());
Sleep(500);
RefreshRates();
}
} else {
if (ND(l_ord_open_price_64) != l_price_12 && gi_292 != Time[0]) {
OrderModify(l_ticket_52, l_price_12, l_price_12 + SL * Point, l_price_12 - TP * Point, 0, DarkGreen);
gi_292 = Time[0];
Print("Modify SellLimit: " + GetLastError());
Sleep(500);
RefreshRates();
}
}
}
} else {
gs_256 = "Waiting for trading hour!";
if (OrdersType == 1) fOrderDeleteLimit();
}
}
gd_unused_272 = Ask;
gd_unused_280 = Bid;
if (Use_Trailing) fTrailingStop();
return (0);
}
void CloseProfit() {
int li_unused_0 = 0;
int li_unused_4 = 0;
double ld_unused_8 = 0;
if (OrdersTotal() > 0) {
for (int l_pos_16 = OrdersTotal() + 1; l_pos_16 >= 0; l_pos_16--) {
if (OrderSelect(l_pos_16, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol() == Symbol()) {
if (OrderMagicNumber() == Magic) {
if (OrderCloseTime() == 0) {
if (OrderType() == OP_BUY) {
RefreshRates();
if (Bid > OrderOpenPrice() + ClosePips * Point) {
Print("del");
del(OrderTicket());
}
}
if (OrderType() == OP_SELL) {
RefreshRates();
if (Ask < OrderOpenPrice() - ClosePips * Point) {
Print("del");
del(OrderTicket());
}
}
}
}
}
}
}
}
}
void del(int a_ticket_0) {
int l_error_4;
string l_symbol_8;
double l_bid_16;
for (int l_count_24 = 0; l_count_24 < 1; l_count_24++) {
GetLastError();
OrderSelect(a_ticket_0, SELECT_BY_TICKET, MODE_TRADES);
l_symbol_8 = OrderSymbol();
if (OrderType() == OP_BUY) {
RefreshRates();
l_bid_16 = MarketInfo(l_symbol_8, MODE_BID);
if (!OrderClose(a_ticket_0, OrderLots(), l_bid_16, 3, Green)) l_error_4 = GetLastError();
}
if (OrderType() == OP_SELL) {
RefreshRates();
l_bid_16 = MarketInfo(l_symbol_8, MODE_ASK);
if (!OrderClose(a_ticket_0, OrderLots(), l_bid_16, 3, Green)) l_error_4 = GetLastError();
}
if (l_error_4 == 0/* NO_ERROR */) {
PlaySound("expert.wav");
return;
}
if (l_error_4 != 0/* NO_ERROR */) {
PlaySound("timeout.wav");
Print("Error for Close Funtion =", l_error_4);
}
while (!IsTradeAllowed()) Sleep(5000);
if (l_error_4 == 146/* TRADE_CONTEXT_BUSY */) while (IsTradeContextBusy()) Sleep(11000);
}
}
double ND(double ad_0) {
return (NormalizeDouble(ad_0, Digits));
}
int fOrdersCounter(int &a_count_0, int &a_count_4, int &a_count_8, int &a_count_12, double &a_ord_open_price_16, double &a_ord_open_price_24, int &a_ticket_32, int &a_ticket_36) {
a_count_0 = 0;
a_count_4 = 0;
a_count_8 = 0;
a_count_12 = 0;
a_ord_open_price_16 = 0;
a_ord_open_price_24 = 0;
a_ticket_32 = 0;
a_ticket_36 = 0;
for (int l_pos_40 = 0; l_pos_40 < OrdersTotal(); l_pos_40++) {
if (OrderSelect(l_pos_40, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol() == Symbol()) {
if (OrderMagicNumber() == Magic) {
switch (OrderType()) {
case OP_BUY:
a_count_0++;
break;
case OP_SELL:
a_count_4++;
break;
case OP_BUYLIMIT:
a_count_8++;
a_ord_open_price_16 = OrderOpenPrice();
a_ticket_32 = OrderTicket();
break;
case OP_SELLLIMIT:
a_count_12++;
a_ord_open_price_24 = OrderOpenPrice();
a_ticket_36 = OrderTicket();
}
}
}
} else return (-1);
}
return (a_count_0 + a_count_4);
}
double Lots() {
int li_0;
double ld_4 = NormalizeDouble(MarketInfo(Symbol(), MODE_LOTSTEP), 2);
if (ld_4 == 0.01) li_0 = 2;
else li_0 = 1;
if (MM) gd_332 = NormalizeDouble(AccountFreeMargin() * Risk / 100000.0 / (g_leverage_320 / 100), li_0);
else gd_332 = MinLot;
double ld_12 = NormalizeDouble(MarketInfo(Symbol(), MODE_MINLOT), 2);
double ld_20 = NormalizeDouble(MarketInfo(Symbol(), MODE_MAXLOT), 2);
if (gd_332 < ld_12) gd_332 = ld_12;
if (gd_332 > ld_20) gd_332 = ld_20;
return (gd_332);
}
int fOrderDeleteLimit(bool ai_0 = TRUE, bool ai_4 = TRUE) {
int li_ret_8 = 0;
for (int l_pos_12 = OrdersTotal() - 1; l_pos_12 >= 0; l_pos_12--) {
if (OrderSelect(l_pos_12, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol() == Symbol()) {
if (OrderType() == OP_BUYLIMIT) {
if (ai_0) {
RefreshRates();
if (!IsTradeContextBusy()) {
if (!OrderDelete(OrderTicket())) li_ret_8 = -1;
} else {
if (TimeCurrent() > g_datetime_296 + 20) {
g_datetime_296 = TimeCurrent();
Print("Need delete BUYLIMIT " + OrderTicket() + ". Trade Context Busy");
}
return (-2);
}
}
}
if (OrderType() == OP_SELLLIMIT) {
if (ai_4) {
RefreshRates();
if (!IsTradeContextBusy()) {
if (!OrderDelete(OrderTicket())) li_ret_8 = -1;
} else {
if (TimeCurrent() > g_datetime_300 + 20) {
g_datetime_300 = TimeCurrent();
Print("Need delete SELLSTOP " + OrderTicket() + ". Trade Context Busy");
}
return (-2);
}
}
}
}
}
}
return (li_ret_8);
}
int fOrderCloseMarket(bool ai_0 = TRUE, bool ai_4 = TRUE) {
int l_error_8;
int li_ret_12 = 0;
for (int l_pos_16 = OrdersTotal() - 1; l_pos_16 >= 0; l_pos_16--) {
if (OrderSelect(l_pos_16, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol() == Symbol()) {
if (ai_0) {
if (OrderType() == OP_BUY) {
RefreshRates();
if (!IsTradeContextBusy()) {
if (!OrderClose(OrderTicket(), OrderLots(), ND(Bid), 3, CLR_NONE)) {
l_error_8 = GetLastError();
Print("Error close BUY " + OrderTicket() + " " + l_error_8);
li_ret_12 = -1;
}
} else {
if (TimeCurrent() > g_datetime_304 + 0) {
g_datetime_304 = TimeCurrent();
Print("Need close BUY " + OrderTicket() + ". Trade Context Busy");
}
return (-2);
}
}
}
if (ai_4) {
if (OrderType() == OP_SELL) {
RefreshRates();
if (!IsTradeContextBusy()) {
if (!OrderClose(OrderTicket(), OrderLots(), ND(Ask), 3, CLR_NONE)) {
l_error_8 = GetLastError();
Print("Error close SELL " + OrderTicket() + " " + l_error_8);
li_ret_12 = -1;
}
} else {
if (TimeCurrent() > g_datetime_308 + 20) {
g_datetime_308 = TimeCurrent();
Print("Need close SELL " + OrderTicket() + ". Trade Context Busy");
}
return (-2);
}
}
}
}
}
}
return (li_ret_12);
}
void fTrailingStop() {
double l_price_0;
int l_error_8;
for (int l_pos_12 = 0; l_pos_12 < OrdersTotal(); l_pos_12++) {
if (OrderSelect(l_pos_12, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) {
if (OrderType() == OP_BUY) {
RefreshRates();
if (ND(Bid - OrderOpenPrice()) <= ND((-Point) * TrailingStart)) {
l_price_0 = ND(Bid + Point * TrailingStop);
if (ND(OrderTakeProfit()) > l_price_0 || ND(OrderTakeProfit()) == 0.0) {
if (!IsTradeContextBusy()) {
if (!OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), l_price_0, 0, CLR_NONE)) {
l_error_8 = GetLastError();
Print("Error trailingprofit BUY " + OrderTicket() + " - " + l_error_8);
}
} else {
if (g_datetime_312 + 15 < TimeCurrent()) {
g_datetime_312 = TimeCurrent();
Print("Need trailingprofit BUY " + OrderTicket() + ". Trade Context Busy");
}
}
}
}
}
if (OrderType() == OP_SELL) {
RefreshRates();
if (ND(OrderOpenPrice() - Ask) <= ND((-Point) * TrailingStart)) {
l_price_0 = ND(Ask - Point * TrailingStop);
if (!IsTradeContextBusy()) {
if (ND(OrderTakeProfit()) < l_price_0) {
if (!OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), l_price_0, 0, CLR_NONE)) {
l_error_8 = GetLastError();
Print("Error trailingprofit SELL " + OrderTicket() + " - " + l_error_8);
}
}
} else {
if (g_datetime_316 + 15 < TimeCurrent()) {
g_datetime_316 = TimeCurrent();
Print("Need trailingprofit SELL " + OrderTicket() + ". Trade Context Busy");
}
}
}
}
}
}
}
}
int AutoGMTCalculation() {
string ls_0;
int li_ret_8;
int li_12;
gi_216 = InternetOpenA(gs_208, 0, "0", "0", 0);
string ls_16 = "XXXXXXXXXX";
if (!GetData(gs_200, ls_16)) {
if (gi_196 == 0) ls_0 = "Error getting data to server.";
else ls_0 = "Apaan sih";
Comment(ls_0);
Print(ls_0);
li_ret_8 = -2147483648;
} else {
li_12 = TimeCurrent() - StrToInteger(ls_16);
li_ret_8 = MathFloor((li_12 + 1800) / 3600);
}
InternetCloseHandle(gi_216);
return (li_ret_8);
}
bool GetData(string as_0, string &as_8) {
int li_16 = InternetOpenUrlA(gi_216, as_0, "0", 0, -2080374528, 0);
if (li_16 == 0) return (FALSE);
int lia_20[] = {1};
string ls_24 = "xxxxxxxxxx";
int li_32 = InternetReadFile(li_16, ls_24, 10, lia_20);
if (li_16 != 0) InternetCloseHandle(li_16);
as_8 = ls_24;
return (TRUE);
}
int TradingTime() {
gi_268 = FALSE;
if (gi_360 > gi_364) {
if (TimeHour(TimeCurrent()) >= gi_360 || TimeHour(TimeCurrent()) < gi_364) gi_268 = TRUE;
} else
if (TimeHour(TimeCurrent()) >= gi_360 && TimeHour(TimeCurrent()) < gi_364) gi_268 = TRUE;
return (gi_268);
发表评论