Enigma

Enigma 最新版

开心版 无广告 60

更新日期:2022-03-14 分类标签: 语言:中文 平台:没限制

7 人已下载 手机查看

/*
Generated by EX4-TO-MQ4 decompiler V4.0.224.1 []
Website: http://purebeam.biz
E-mail : [email protected]
*/
#import "EnigmaG12Core.dll"
int Initialize(string a0, int a1, int a2, string a3, int a4);
int GetSettings(string a0, int& a1[], int& a2[], int& a3[], int& a4[], int& a5[], int& a6[], int& a7[], int& a8[], int& a9[], int& a10[], int& a11[], int& a12[], int& a13[], int& a14[], int& a15[], int& a16[], double& a17[], double& a18[], double& a19[], double& a20[], double& a21[], double& a22[], int& a23[], int& a24[]);
void GetVersionInfo(int& a0[], int& a1[], int& a2[], int& a3[]);
#import

bool gi_76 = FALSE;
bool gi_80 = FALSE;
int gi_84 = 0;
int gi_88 = -1;
int gi_92 = -1;
int gi_96 = -1;
int gi_100 = -1;
extern double mmRisk = 0.05;
extern bool hedgingWorkaround = FALSE;
int gi_116 = 0;
int gi_120 = 0;
int gi_124 = 0;
int gi_128 = 0;
int gi_132 = 0;
int gi_136 = 0;
int gi_140 = 0;
int gi_144 = 0;
int gi_148 = 0;
int gi_152 = 0;
int gi_156 = 0;
int gi_160 = 0;
int gi_164 = 0;
int gi_168 = 0;
int gi_172 = 0;
int gi_176 = 0;
double gd_180 = 0.0;
double gd_188 = 0.0;
double gd_196 = 0.0;
double gd_204 = 0.0;
double gd_212 = 0.0;
double gd_220 = 0.0;
int gi_228 = 0;
double gda_232[5];
int gi_236 = 0;
int gia_240[6] = {0, 0, 20, 40, 60, 80};
int gi_244 = 0;
int g_cmd_248 = -1;
int gi_unused_252 = -1;
bool gi_256 = FALSE;
bool gi_260 = FALSE;
double g_ihigh_264 = 0.0;
double g_ilow_272 = 200.0;
double g_price_280 = 0.0;
double g_price_288 = 200.0;
int gi_296 = 0;
int gi_300 = 0;
bool gi_304 = TRUE;
bool gi_308 = TRUE;
double g_ihigh_312 = 0.0;
double g_ilow_320 = 200.0;
int g_datetime_328 = 0;
int g_datetime_332 = 0;
bool gi_336 = TRUE;
bool gi_340 = TRUE;
bool gi_344 = FALSE;
bool gi_348 = FALSE;
int gi_352 = 0;
double gd_356 = 0.0;
bool gi_364 = FALSE;
int g_hour_368 = -1;

bool isDayBlacklisted(int ai_unused_0) {
return (FALSE);
}

void validateInputParameters() {
if (gi_116 < 0 || gi_116 > 24 || gi_120 < 0 || gi_120 > 24 || gi_124 < 0 || gi_124 > 24) {
gi_256 = FALSE;
return;
}
int li_0 = 60 * gi_116;
int li_4 = 60 * gi_120;
if (li_4 < li_0) {
gi_256 = FALSE;
return;
}
if (MathAbs(gi_136) > 50.0 || MathAbs(gi_132) > 50.0) gi_256 = FALSE;
if (gi_140 != 1 && gi_140 != 2 && gi_140 != 3) gi_256 = FALSE;
if (MathAbs(gi_144) > 50.0 || MathAbs(gi_148) > 50.0 || MathAbs(gi_152) > 50.0 || MathAbs(gi_156) > 50.0 || MathAbs(gi_160) > 50.0 || MathAbs(gi_164) > 50.0) gi_256 = FALSE;
if (gi_168 != 1) gi_256 = FALSE;
if (MathAbs(gi_172) > 150.0) gi_256 = FALSE;
gi_256 = TRUE;
}

void analyzeYesterday() {
analyzeYesterdayHourly();
}

void analyzeToday() {
double l_ihigh_0;
double l_ilow_8;
int l_datetime_16 = iTime(Symbol(), PERIOD_D1, 0);
int li_20 = 0;
int l_datetime_24 = iTime(Symbol(), PERIOD_H1, li_20);
g_ihigh_312 = 0.0;
g_ilow_320 = 300.0;
while (l_datetime_24 >= l_datetime_16) {
l_ihigh_0 = iHigh(Symbol(), PERIOD_H1, li_20);
l_ilow_8 = iLow(Symbol(), PERIOD_H1, li_20);
if (l_ihigh_0 > g_ihigh_312) g_ihigh_312 = l_ihigh_0;
if (l_ilow_8 < g_ilow_320) g_ilow_320 = l_ilow_8;
li_20++;
l_datetime_24 = iTime(Symbol(), PERIOD_H1, li_20);
}
}

void analyzeYesterdayHourly() {
double l_ihigh_0;
double l_ilow_8;
bool li_16 = FALSE;
if (TimeHour(TimeCurrent()) >= 24 - gi_84 && TimeDayOfWeek(TimeCurrent()) != 0) li_16 = TRUE;
int l_datetime_20 = iTime(Symbol(), PERIOD_D1, 0);
int li_24 = l_datetime_20 - 3600 * gi_84;
if (li_16) li_24 += 86400;
int l_datetime_28 = iTime(Symbol(), PERIOD_D1, 1);
int li_32 = l_datetime_28 - 3600 * gi_84;
if (li_16) li_32 += 86400;
if (StringFind(AccountCompany(), "Alpari") == -1) {
if (TimeDayOfWeek(li_24) == 0 || TimeDayOfWeek(li_24) == 1) {
if (TimeDayOfWeek(li_32) == 0 || TimeDayOfWeek(li_32) == 6) {
l_datetime_28 = iTime(Symbol(), PERIOD_D1, 2);
li_32 = l_datetime_28 - 3600 * gi_84;
if (li_16) li_32 += 86400;
}
}
}
g_ihigh_264 = 0.0;
g_ilow_272 = 300.0;
int li_36 = gi_84 + 73;
int l_datetime_40 = 0;
while (true) {
l_datetime_40 = iTime(Symbol(), PERIOD_H1, li_36);
if (l_datetime_40 >= li_32) break;
li_36--;
if (li_36 > 0) continue;
break;
}
int li_44 = l_datetime_40 + 3600 * gi_116;
int li_48 = l_datetime_40 + 3600 * gi_120;
if (li_36 > 0) {
}
int li_52 = 0;
int li_56 = 0;
while (true) {
l_datetime_40 = iTime(Symbol(), PERIOD_H1, li_36);
if (l_datetime_40 >= li_24) break;
l_ihigh_0 = iHigh(Symbol(), PERIOD_H1, li_36);
l_ilow_8 = iLow(Symbol(), PERIOD_H1, li_36);
if (l_ihigh_0 >= g_ihigh_264) {
g_ihigh_264 = l_ihigh_0;
li_52 = l_datetime_40;
}
if (l_ilow_8 <= g_ilow_272) {
g_ilow_272 = l_ilow_8;
li_56 = l_datetime_40;
}
li_36--;
}
double ld_60 = 0.0001;
if (StringFind(Symbol(), "JPY") != -1) ld_60 = 0.01;
g_ihigh_264 = NormalizeDouble(g_ihigh_264, 4);
g_ilow_272 = NormalizeDouble(g_ilow_272, 4);
g_price_280 = NormalizeDouble(g_ihigh_264 + gi_132 * ld_60, 4);
g_price_288 = NormalizeDouble(g_ilow_272 + gi_136 * ld_60, 4);
if (li_52 < li_44 || li_52 >= li_48) gi_304 = TRUE;
else gi_304 = FALSE;
if (li_56 < li_44 || li_56 >= li_48) gi_308 = TRUE;
else gi_308 = FALSE;
gi_296 = li_52;
gi_300 = li_56;
int li_68 = gi_296 + 3600 * gi_124;
int li_72 = gi_300 + 3600 * gi_124;
if (ObjectFind("sellRange") != 0) {
ObjectCreate("sellRange", OBJ_RECTANGLE, 0, MathMax(li_68, l_datetime_40), g_price_280, l_datetime_40 + 86400, g_price_280 + ld_60 * gia_240[gi_228]);
ObjectSet("sellRange", OBJPROP_COLOR, LightBlue);
} else {
ObjectSet("sellRange", OBJPROP_TIME1, MathMax(li_68, l_datetime_40));
ObjectSet("sellRange", OBJPROP_PRICE1, g_price_280);
ObjectSet("sellRange", OBJPROP_TIME2, l_datetime_40 + 86400);
ObjectSet("sellRange", OBJPROP_PRICE2, g_price_280 + ld_60 * gia_240[gi_228]);
ObjectSet("sellRange", OBJPROP_COLOR, LightBlue);
}
if (ObjectFind("buyRange") != 0) {
ObjectCreate("buyRange", OBJ_RECTANGLE, 0, MathMax(li_72, l_datetime_40), g_price_288, l_datetime_40 + 86400, g_price_288 - ld_60 * gia_240[gi_228]);
ObjectSet("buyRange", OBJPROP_COLOR, LightGreen);
return;
}
ObjectSet("buyRange", OBJPROP_TIME1, MathMax(li_72, l_datetime_40));
ObjectSet("buyRange", OBJPROP_PRICE1, g_price_288);
ObjectSet("buyRange", OBJPROP_TIME2, l_datetime_40 + 86400);
ObjectSet("buyRange", OBJPROP_PRICE2, g_price_288 - ld_60 * gia_240[gi_228]);
ObjectSet("buyRange", OBJPROP_COLOR, LightGreen);
}

void validateYesterdayValues() {
if (g_ilow_272 > 0.0 && g_ihigh_264 > g_ilow_272) {
gi_260 = TRUE;
return;
}
gi_260 = FALSE;
}

int isOurMagicNumber(int ai_0) {
if (ai_0 == 12121212 || ai_0 == 12121213 || ai_0 == 12121214 || ai_0 == 12121215 || ai_0 == 12121216) return (1);
return (0);
}

void initState() {
double ld_0;
double ld_8;
int li_unused_16 = 0;
int li_unused_20 = 0;
bool li_24 = FALSE;
bool li_28 = FALSE;
int l_ord_total_32 = OrdersTotal();
for (int l_pos_36 = 0; l_pos_36 < l_ord_total_32; l_pos_36++) {
if (OrderSelect(l_pos_36, SELECT_BY_POS, MODE_TRADES)) {
if (isOurMagicNumber(OrderMagicNumber()) && OrderSymbol() == Symbol()) {
if (OrderType() == OP_SELL) li_24 = TRUE;
else {
if (OrderType() == OP_BUY) li_28 = TRUE;
else {
if (OrderType() == OP_SELLLIMIT) li_unused_16 = 1;
else
if (OrderType() == OP_BUYLIMIT) li_unused_20 = 1;
}
}
}
}
}
validateInputParameters();
if (gi_256 == FALSE) {
gi_244 = 1;
return;
}
analyzeYesterday();
validateYesterdayValues();
if (gi_260) {
analyzeToday();
if (g_ihigh_312 > g_ihigh_264 || gi_304) gi_336 = FALSE;
if (g_ilow_320 < g_ilow_272 || gi_308) gi_340 = FALSE;
ld_0 = 10000.0;
if (StringFind(Symbol(), "JPY") != -1) ld_0 = 100.0;
ld_8 = MathAbs(g_ihigh_264 - g_ilow_272) * ld_0;
if (ld_8 < gi_128) {
gi_340 = FALSE;
gi_336 = FALSE;
}
if (li_24 || li_28) {
gi_244 = 4;
if (li_24) {
g_cmd_248 = TRUE;
return;
}
g_cmd_248 = FALSE;
return;
}
if (gi_336 || gi_340 && !isDayBlacklisted(TimeCurrent())) {
gi_244 = 3;
return;
}
closePositions();
gi_244 = 5;
return;
}
closePositions();
gi_244 = 2;
}

void closePositions() {
int l_ord_total_0;
int l_pos_4;
bool li_8 = FALSE;
int l_count_12 = 0;
for (l_count_12 = 0; l_count_12 < 30; l_count_12++) {
if (IsTradeContextBusy()) Sleep(1000);
else {
li_8 = TRUE;
break;
}
}
if (li_8) {
l_ord_total_0 = OrdersTotal();
l_count_12 = 0;
l_pos_4 = 0;
for (l_count_12 = 0; l_count_12 < l_ord_total_0; l_count_12++) {
if (OrderSelect(l_pos_4, SELECT_BY_POS)) {
if (OrderSymbol() == Symbol() && isOurMagicNumber(OrderMagicNumber())) {
if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 0);
else {
if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 0);
else {
if (OrderType() == OP_BUYLIMIT || OrderType() == OP_SELLLIMIT) OrderDelete(OrderTicket());
else l_pos_4++;
}
}
} else l_pos_4++;
} else l_pos_4++;
}
}
}

void deleteAllPending(int a_cmd_0) {
int l_ord_total_4 = OrdersTotal();
int l_count_8 = 0;
int l_pos_12 = 0;
for (l_count_8 = 0; l_count_8 < l_ord_total_4; l_count_8++) {
if (OrderSelect(l_pos_12, SELECT_BY_POS)) {
if (OrderType() == a_cmd_0 && OrderSymbol() == Symbol() && isOurMagicNumber(OrderMagicNumber()) && OrderMagicNumber() != 12121212) OrderDelete(OrderTicket());
else l_pos_12++;
}
}
}

void computeOrderVolumes() {
int li_0;
double ld_4;
double ld_12;
double ld_20;
double ld_28;
double ld_36;
double ld_44;
if (gi_176 == 1) {
gda_232[0] = NormalizeDouble(gd_180, 1);
gda_232[1] = NormalizeDouble(gd_188, 1);
gda_232[2] = NormalizeDouble(gd_196, 1);
gda_232[3] = NormalizeDouble(gd_204, 1);
gda_232[4] = NormalizeDouble(gd_212, 1);
return;
}
if (gi_176 == 2) {
li_0 = 0;
if (gi_228 >= 1) li_0 += gi_172;
if (gi_228 >= 2) li_0 += gi_172 - 20;
if (gi_228 >= 3) li_0 += gi_172 - 40;
if (gi_228 >= 4) li_0 += gi_172 - 60;
if (gi_228 >= 5) li_0 += gi_172 - 80;
ld_4 = mmRisk * AccountBalance();
ld_12 = 0.0;
if (MarketInfo(Symbol(), MODE_MINLOT) < 0.1) ld_12 = NormalizeDouble(ld_4 / (li_0 * MarketInfo(Symbol(), MODE_LOTSIZE) / 100000.0) / 10.0, 2);
else ld_12 = NormalizeDouble(ld_4 / (li_0 * MarketInfo(Symbol(), MODE_LOTSIZE) / 100000.0) / 10.0, 1);
ld_12 = MathMax(ld_12, MarketInfo(Symbol(), MODE_MINLOT));
gda_232[0] = ld_12;
gda_232[1] = ld_12;
gda_232[2] = ld_12;
gda_232[3] = ld_12;
gda_232[4] = ld_12;
Print("mmMode: 2, orderSize: " + ld_12);
return;
}
if (gi_176 == 3) {
li_0 = 0;
if (gi_228 >= 1) li_0 += gi_172;
if (gi_228 >= 2) li_0 += gi_172 - 20;
if (gi_228 >= 3) li_0 += gi_172 - 40;
if (gi_228 >= 4) li_0 += gi_172 - 60;
if (gi_228 >= 5) li_0 += gi_172 - 80;
ld_4 = mmRisk * AccountBalance();
gd_220 = 10.0 * gd_220;
ld_20 = 0.0;
ld_20 = ld_4;
Print("mmRisk: " + ld_4);
ld_28 = 0.0;
for (int li_52 = 1; li_52 < gi_228; li_52++) ld_28 += li_52 * (gia_240[li_52 + 1]);
ld_28 *= gd_220;
Print("f2: " + ld_28);
ld_20 += ld_28;
ld_36 = 0.0;
for (li_52 = 1; li_52 < gi_228; li_52++) ld_36 += li_52;
ld_36 *= gi_172 * gd_220;
Print("f3: " + ld_36);
ld_20 -= ld_36;
ld_44 = 0.0;
for (li_52 = 1; li_52 <= gi_228; li_52++) ld_44 += gia_240[li_52];
Print("f4: " + ld_44);
ld_20 /= (gi_172 * gi_228 - ld_44);
ld_20 = NormalizeDouble(ld_20 / 10.0, 1);
Print("X: " + ld_20);
gd_220 /= 10.0;
gda_232[0] = ld_20;
for (li_52 = 1; li_52 < gi_228; li_52++) gda_232[li_52] = ld_20 + li_52 * gd_220;
} else {
if (gi_176 == 4) {
li_0 = 0;
if (gi_228 >= 1) li_0 += gi_172;
if (gi_228 >= 2) li_0 += gi_172 - 20;
if (gi_228 >= 3) li_0 += gi_172 - 40;
if (gi_228 >= 4) li_0 += gi_172 - 60;
if (gi_228 >= 5) li_0 += gi_172 - 80;
ld_4 = mmRisk * AccountBalance();
ld_20 = 0.0;
ld_20 = ld_4;
Print("mmRisk: " + ld_4);
ld_28 = 0.0;
for (li_52 = 1; li_52 <= gi_228; li_52++) ld_28 += MathPow(gd_220, li_52 - 1);
ld_28 *= gi_172;
Print("f2: " + ld_28);
ld_36 = 0.0;
for (li_52 = 1; li_52 < gi_228; li_52++) ld_36 += (gia_240[li_52 + 1]) * MathPow(gd_220, li_52);
Print("f3: " + ld_36);
ld_20 /= (ld_28 - ld_36);
ld_20 = NormalizeDouble(ld_20 / 10.0, 1);
Print("X: " + ld_20);
gda_232[0] = ld_20;
for (li_52 = 1; li_52 < gi_228; li_52++) gda_232[li_52] = NormalizeDouble(ld_20 * MathPow(gd_220, li_52), 1);
}
}
}

void updateOrders() {
bool li_0 = FALSE;
bool li_4 = FALSE;
bool li_8 = FALSE;
bool li_12 = FALSE;
double l_price_16 = 0.0;
double l_price_24 = 0.0;
double ld_32 = 1.0;
int l_ord_total_40 = OrdersTotal();
int l_pos_44 = 0;
for (l_pos_44 = 0; l_pos_44 < l_ord_total_40; l_pos_44++) {
if (OrderSelect(l_pos_44, SELECT_BY_POS)) {
if (OrderSymbol() == Symbol() && OrderMagicNumber() == 12121212) {
if (OrderType() == OP_BUYLIMIT) {
if (gi_340 && TimeCurrent() >= gi_300 + 3600 * gi_124) {
ld_32 = 0.0001;
if (StringFind(Symbol(), "JPY") != -1) ld_32 = 0.01;
li_8 = TRUE;
if (MathAbs(OrderOpenPrice() - g_price_288) >= ld_32) {
l_price_16 = g_price_288 - gi_172 * ld_32;
if (gi_140 == 1 || gi_140 == 3) l_price_24 = g_price_288 + gi_144 * ld_32;
else l_price_24 = g_price_288 + gi_148 * ld_32;
if (OrderModify(OrderTicket(), g_price_288, l_price_16, l_price_24, 0)) li_12 = TRUE;
}
} else {
OrderDelete(OrderTicket());
li_8 = FALSE;
}
} else {
if (OrderType() == OP_SELLLIMIT && gi_336) {
if (gi_336 && TimeCurrent() >= gi_296 + 3600 * gi_124) {
ld_32 = 0.0001;
if (StringFind(Symbol(), "JPY") != -1) ld_32 = 0.01;
li_0 = TRUE;
if (MathAbs(OrderOpenPrice() - g_price_280) >= ld_32) {
l_price_16 = g_price_280 + gi_172 * ld_32;
if (gi_140 == 1 || gi_140 == 3) l_price_24 = g_price_280 - gi_144 * ld_32;
else l_price_24 = g_price_280 - gi_148 * ld_32;
if (OrderModify(OrderTicket(), g_price_280, l_price_16, l_price_24, 0)) li_4 = TRUE;
}
} else {
OrderDelete(OrderTicket());
li_0 = FALSE;
}
}
}
}
}
}
if (li_12 || !(gi_340 && TimeCurrent() >= gi_300 + 3600 * gi_124)) deleteAllPending(OP_BUYLIMIT);
if (li_4 || !(gi_336 && TimeCurrent() >= gi_296 + 3600 * gi_124)) deleteAllPending(OP_SELLLIMIT);
ld_32 = 0.0001;
if (StringFind(Symbol(), "JPY") != -1) ld_32 = 0.01;
bool li_48 = FALSE;
bool li_52 = TRUE;
bool li_56 = TRUE;
if (!li_0 && gi_336 && TimeCurrent() >= gi_296 + 3600 * gi_124) {
computeOrderVolumes();
li_48 = TRUE;
l_price_16 = g_price_280 + gi_172 * ld_32;
if (gi_140 == 1 || gi_140 == 3) l_price_24 = g_price_280 - gi_144 * ld_32;
else l_price_24 = g_price_280 - gi_148 * ld_32;
if (g_price_280 - MarketInfo(Symbol(), MODE_BID) < 10.0 * ld_32) li_52 = FALSE;
if (li_52) {
if (OrderSend(Symbol(), OP_SELLLIMIT, gda_232[0], g_price_280, 0, l_price_16, l_price_24, "EnigmaG12Sell", 12121212) < 0) {
Print("OrderSend failed with error: ", GetLastError());
Print("Parameters: " + 3 + "," + gda_232[0] + "," + g_price_280 + ",0," + l_price_16 + "," + l_price_24 + "EnigmaG12Sell," + 12121212);
li_52 = FALSE;
}
}
}
if (li_4 || !li_0 && gi_336 && TimeCurrent() >= gi_296 + 3600 * gi_124) {
if (!li_48) {
computeOrderVolumes();
li_48 = TRUE;
}
l_price_16 = g_price_280 + gi_172 * ld_32;
if (gi_140 == 1 || gi_140 == 3) l_price_24 = g_price_280 - gi_144 * ld_32;
else l_price_24 = g_price_280 - gi_148 * ld_32;
if (li_52 && gi_228 >= 2)
if (OrderSend(Symbol(), OP_SELLLIMIT, gda_232[1], g_price_280 + gia_240[2] * ld_32, 0, l_price_16, l_price_24, "EnigmaG12Sell", 12121213) < 0) li_52 = FALSE;
if (li_52 && gi_228 >= 3)
if (OrderSend(Symbol(), OP_SELLLIMIT, gda_232[2], g_price_280 + gia_240[3] * ld_32, 0, l_price_16, l_price_24, "EnigmaG12Sell", 12121214) < 0) li_52 = FALSE;
if (li_52 && gi_228 >= 4)
if (OrderSend(Symbol(), OP_SELLLIMIT, gda_232[3], g_price_280 + gia_240[4] * ld_32, 0, l_price_16, l_price_24, "EnigmaG12Sell", 12121215) < 0) li_52 = FALSE;
if (li_52 && gi_228 >= 5)
if (OrderSend(Symbol(), OP_SELLLIMIT, gda_232[4], g_price_280 + gia_240[5] * ld_32, 0, l_price_16, l_price_24, "EnigmaG12Sell", 12121216) < 0) li_52 = FALSE;
}
if (!li_8 && gi_340 && TimeCurrent() >= gi_300 + 3600 * gi_124) {
if (!li_48) {
computeOrderVolumes();
li_48 = TRUE;
}
l_price_16 = g_price_288 - gi_172 * ld_32;
if (gi_140 == 1 || gi_140 == 3) l_price_24 = g_price_288 + gi_144 * ld_32;
else l_price_24 = g_price_288 + gi_148 * ld_32;
if (MarketInfo(Symbol(), MODE_ASK) - g_price_288 < 10.0 * ld_32) li_56 = FALSE;
if (li_56) {
if (OrderSend(Symbol(), OP_BUYLIMIT, gda_232[0], g_price_288, 0, l_price_16, l_price_24, "EnigmaG12Buy", 12121212) < 0) {
Print("OrderSend failed with error: ", GetLastError());
Print("Parameters: " + 2 + "," + gda_232[0] + "," + g_price_288 + ",0," + l_price_16 + "," + l_price_24 + "EnigmaG12Buy," + 12121212);
li_56 = FALSE;
}
}
}
if (li_12 || !li_8 && gi_340 && TimeCurrent() >= gi_300 + 3600 * gi_124) {
if (!li_48) {
computeOrderVolumes();
li_48 = TRUE;
}
l_price_16 = g_price_288 - gi_172 * ld_32;
if (gi_140 == 1 || gi_140 == 3) l_price_24 = g_price_288 + gi_144 * ld_32;
else l_price_24 = g_price_288 + gi_148 * ld_32;
if (li_56 && gi_228 >= 2)
if (OrderSend(Symbol(), OP_BUYLIMIT, gda_232[1], g_price_288 - gia_240[2] * ld_32, 0, l_price_16, l_price_24, "EnigmaG12Buy", 12121213) < 0) li_56 = FALSE;
if (li_56 && gi_228 >= 3)
if (OrderSend(Symbol(), OP_BUYLIMIT, gda_232[2], g_price_288 - gia_240[3] * ld_32, 0, l_price_16, l_price_24, "EnigmaG12Buy", 12121214) < 0) li_56 = FALSE;
if (li_56 && gi_228 >= 4)
if (OrderSend(Symbol(), OP_BUYLIMIT, gda_232[3], g_price_288 - gia_240[4] * ld_32, 0, l_price_16, l_price_24, "EnigmaG12Buy", 12121215) < 0) li_56 = FALSE;
if (li_56 && gi_228 >= 5)
if (OrderSend(Symbol(), OP_BUYLIMIT, gda_232[4], g_price_288 - gia_240[5] * ld_32, 0, l_price_16, l_price_24, "EnigmaG12Buy", 12121216) < 0) li_56 = FALSE;
}
}

void updateOrderTPs(int ai_0) {
double ld_4;
double ld_12;
double l_ord_open_price_20;
double ld_28;
int li_36;
int l_ord_total_40 = OrdersTotal();
int l_pos_44 = 0;
double l_price_48 = 0.0;
double ld_56 = 0.0001;
if (StringFind(Symbol(), "JPY") != -1) ld_56 = 0.01;
if (ai_0 == 1) {
for (l_pos_44 = 0; l_pos_44 < l_ord_total_40; l_pos_44++) {
if (OrderSelect(l_pos_44, SELECT_BY_POS)) {
if (OrderSymbol() == Symbol() && OrderMagicNumber() == 12121212) {
if (g_cmd_248 == OP_BUY && OrderType() == OP_BUY) {
if (gi_140 == 1) l_price_48 = OrderOpenPrice() + gi_144 * ld_56;
else {
if (gi_140 == 2) l_price_48 = OrderOpenPrice() + gi_148 * ld_56;
else
if (gi_140 == 3) l_price_48 = OrderOpenPrice() + gi_144 * ld_56;
}
Print("updateOrderTPs OrderModify");
OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), l_price_48, OrderExpiration());
gd_356 = OrderOpenPrice();
return;
}
if (g_cmd_248 == OP_SELL && OrderType() == OP_SELL) {
if (gi_140 == 1) l_price_48 = OrderOpenPrice() - gi_144 * ld_56;
else {
if (gi_140 == 2) l_price_48 = OrderOpenPrice() - gi_148 * ld_56;
else
if (gi_140 == 3) l_price_48 = OrderOpenPrice() - gi_144 * ld_56;
}
Print("updateOrderTPs OrderModify");
OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), l_price_48, OrderExpiration());
gd_356 = OrderOpenPrice();
return;
}
}
}
}
} else {
ld_4 = 0;
ld_12 = 0.0;
gd_356 = 0.0;
for (l_pos_44 = 0; l_pos_44 < l_ord_total_40; l_pos_44++) {
if (OrderSelect(l_pos_44, SELECT_BY_POS)) {
if (OrderSymbol() == Symbol() && isOurMagicNumber(OrderMagicNumber())) {
if (g_cmd_248 == OP_BUY && OrderType() == OP_BUY) {
gd_356 += OrderOpenPrice() * OrderLots();
ld_12 += OrderLots();
ld_4++;
} else {
if (g_cmd_248 == OP_SELL && OrderType() == OP_SELL) {
gd_356 += OrderOpenPrice() * OrderLots();
ld_12 += OrderLots();
ld_4++;
}
}
}
}
}
gd_356 = NormalizeDouble(gd_356 / ld_12, 4);
Print("avg price: " + gd_356);
l_ord_open_price_20 = 0.0;
if (gi_140 == 3) {
for (l_pos_44 = 0; l_pos_44 < l_ord_total_40; l_pos_44++) {
if (OrderSelect(l_pos_44, SELECT_BY_POS)) {
if (OrderSymbol() == Symbol() && OrderMagicNumber() == 12121212 && OrderType() == g_cmd_248) {
if (g_cmd_248 == OP_BUY && OrderType() == OP_BUY) {
l_ord_open_price_20 = OrderOpenPrice();
break;
}
if (g_cmd_248 == OP_SELL && OrderType() == OP_SELL) {
l_ord_open_price_20 = OrderOpenPrice();
break;
}
}
}
}
}
for (l_pos_44 = 0; l_pos_44 < l_ord_total_40; l_pos_44++) {
if (OrderSelect(l_pos_44, SELECT_BY_POS)) {
if (OrderSymbol() == Symbol() && isOurMagicNumber(OrderMagicNumber())) {
ld_28 = gi_148;
if (OrderMagicNumber() == 12121212) ld_28 = gi_148;
else {
if (OrderMagicNumber() == 12121213) ld_28 = gi_152;
else {
if (OrderMagicNumber() == 12121214) ld_28 = gi_156;
else {
if (OrderMagicNumber() == 12121215) ld_28 = gi_160;
else
if (OrderMagicNumber() == 12121216) ld_28 = gi_164;
}
}
}
li_36 = -1;
if (g_cmd_248 == OP_BUY && OrderType() == OP_BUY) {
li_36 = 0;
if (gi_140 == 1) l_price_48 = gd_356 + gi_144 * ld_56;
else {
if (gi_140 == 2) l_price_48 = OrderOpenPrice() + ld_28 * ld_56;
else
if (gi_140 == 3) l_price_48 = l_ord_open_price_20 + gi_144 * ld_56;
}
} else {
if (g_cmd_248 == OP_SELL && OrderType() == OP_SELL) {
li_36 = 1;
if (gi_140 == 1) l_price_48 = gd_356 - gi_144 * ld_56;
else {
if (gi_140 == 2) l_price_48 = OrderOpenPrice() - ld_28 * ld_56;
else
if (gi_140 == 3) l_price_48 = l_ord_open_price_20 - gi_144 * ld_56;
}
} else {
li_36 = -1;
l_price_48 = OrderTakeProfit();
continue;
}
}
if (li_36 != -1) {
Print("updateOrderTPs OrderModify");
OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), l_price_48, OrderExpiration());
}
}
}
}
}
}

int getOpenPosition() {
int l_ord_total_0 = OrdersTotal();
int l_pos_4 = 0;
for (l_pos_4 = 0; l_pos_4 < l_ord_total_0; l_pos_4++) {
if (OrderSelect(l_pos_4, SELECT_BY_POS)) {
if (OrderSymbol() == Symbol() && OrderMagicNumber() == 12121212) {
if (OrderType() == OP_BUY) return (0);
if (OrderType() == OP_SELL) return (1);
}
}
}
return (-1);
}

int getPositionCount() {
int l_count_0 = 0;
int l_ord_total_4 = OrdersTotal();
int l_pos_8 = 0;
for (l_pos_8 = 0; l_pos_8 < l_ord_total_4; l_pos_8++) {
if (OrderSelect(l_pos_8, SELECT_BY_POS)) {
if (OrderSymbol() == Symbol() && isOurMagicNumber(OrderMagicNumber())) {
if (g_cmd_248 == OP_BUY && OrderType() == OP_BUY) l_count_0++;
else
if (g_cmd_248 == OP_SELL && OrderType() == OP_SELL) l_count_0++;
}
}
}
return (l_count_0);
}

int isWeekStart() {
if (TimeDayOfWeek(TimeCurrent()) == 0 || (TimeDayOfWeek(TimeCurrent()) == 1 && TimeHour(TimeCurrent()) <= 10)) return (1);
return (0);
}

int isOtherEAInTrade() {
int l_ord_total_0 = OrdersTotal();
int l_pos_4 = 0;
for (l_pos_4 = 0; l_pos_4 < l_ord_total_0; l_pos_4++) {
if (OrderSelect(l_pos_4, SELECT_BY_POS)) {
if (OrderSymbol() != Symbol() && isOurMagicNumber(OrderMagicNumber()))
if (OrderType() == OP_BUY || OrderType() == OP_SELL) return (1);
}
}
return (0);
}

void updateState() {
double ld_0;
int li_8;
bool li_12;
double ld_16;
int li_24;
int li_28;
int li_32;
bool li_36 = FALSE;
if (g_datetime_328 != 0 && TimeDayOfYear(g_datetime_332 + 3600 * gi_84) > TimeDayOfYear(g_datetime_328 + 3600 * gi_84) || (TimeDayOfYear(g_datetime_332 + 3600 * gi_84) == 1 &&
TimeDayOfYear(g_datetime_328 + 3600 * gi_84) >= 365)) {
li_36 = TRUE;
gi_340 = TRUE;
gi_336 = TRUE;
findFridayData();
}
if (g_hour_368 != -1 && TimeDayOfWeek(TimeCurrent()) == 5 && TimeHour(TimeCurrent()) >= g_hour_368 - 1) {
Print("Closing positions due to Friday market close.");
closePositions();
gi_244 = 5;
}
double ld_40 = -1.0;
if (li_36) {
analyzeYesterday();
validateYesterdayValues();
ld_0 = 10000.0;
if (StringFind(Symbol(), "JPY") != -1) ld_0 = 100.0;
ld_40 = MathAbs(g_ihigh_264 - g_ilow_272) * ld_0;
}
if (gi_244 == 3) {
if (!gi_340 && !gi_336 && !gi_348 && !gi_344) {
closePositions();
gi_244 = 5;
return;
}
li_8 = getOpenPosition();
if (li_8 != -1) {
g_cmd_248 = li_8;
gi_244 = 4;
return;
}
li_12 = isOtherEAInTrade();
if (li_12) {
Print("Blocked due to another instance trading.");
closePositions();
gi_244 = 6;
return;
}
if (li_36 || gi_364) {
if (gi_364) gi_364 = FALSE;
if (gi_260 == FALSE) {
gi_244 = 2;
return;
}
if (ld_40 < gi_128) {
gi_336 = FALSE;
gi_340 = FALSE;
closePositions();
gi_244 = 5;
return;
}
if (gi_304) gi_336 = FALSE;
else
if (!isDayBlacklisted(g_datetime_332)) gi_336 = TRUE;
if (gi_308) gi_340 = FALSE;
else
if (!isDayBlacklisted(g_datetime_332)) gi_340 = TRUE;
}
if (gi_336 && isWeekStart()) {
gi_336 = FALSE;
gi_344 = TRUE;
} else {
if (!isWeekStart() && gi_344) {
gi_336 = TRUE;
gi_344 = FALSE;
}
}
if (gi_340 && isWeekStart()) {
gi_340 = FALSE;
gi_348 = TRUE;
} else {
if (!isWeekStart() && gi_348) {
gi_340 = TRUE;
gi_348 = FALSE;
}
}
if (MarketInfo(Symbol(), MODE_BID) > g_ihigh_264 && gi_336 || gi_344 && TimeCurrent() < gi_296 + 3600 * gi_124) {
gi_336 = FALSE;
gi_344 = FALSE;
} else {
if (MarketInfo(Symbol(), MODE_BID) > g_ihigh_264 && gi_336 || gi_344 && getOpenPosition() == -1) {
gi_336 = FALSE;
gi_344 = FALSE;
}
}
if (MarketInfo(Symbol(), MODE_ASK) < g_ilow_272 && gi_340 || gi_348 && TimeCurrent() < gi_300 + 3600 * gi_124) {
gi_340 = FALSE;
gi_348 = FALSE;
} else {
if (MarketInfo(Symbol(), MODE_ASK) < g_ilow_272 && gi_340 || gi_348 && getOpenPosition() == -1) {
gi_340 = FALSE;
gi_348 = FALSE;
}
}
ld_0 = 10000.0;
if (StringFind(Symbol(), "JPY") != -1) ld_0 = 100.0;
if (hedgingWorkaround) {
ld_16 = (MarketInfo(Symbol(), MODE_ASK) - (g_ihigh_264 + g_ilow_272) / 2.0) * ld_0;
if (MathAbs(ld_16) < 10.0) closePositions();
else {
if (ld_16 >= 10.0) {
li_24 = gi_340;
gi_340 = FALSE;
updateOrders();
gi_340 = li_24;
} else {
li_28 = gi_336;
gi_336 = FALSE;
updateOrders();
gi_336 = li_28;
}
}
} else updateOrders();
}
if (gi_244 == 5) {
if (li_36 || gi_364) {
closePositions();
if (gi_364) gi_364 = FALSE;
if (gi_304) gi_336 = FALSE;
else
if (!isDayBlacklisted(g_datetime_332)) gi_336 = TRUE;
if (gi_308) gi_340 = FALSE;
else
if (!isDayBlacklisted(g_datetime_332)) gi_340 = TRUE;
if (ld_40 < gi_128) {
gi_336 = FALSE;
gi_340 = FALSE;
gi_244 = 5;
} else gi_244 = 3;
} else
if (g_cmd_248 != -1) closePositions();
} else {
if (gi_244 == 4) {
if (getOpenPosition() == -1) {
if (g_cmd_248 == OP_BUY) gi_340 = FALSE;
else
if (g_cmd_248 == OP_SELL) gi_336 = FALSE;
if (gi_340 || gi_336) gi_244 = 3;
else gi_244 = 5;
} else {
li_32 = getPositionCount();
if (li_32 != gi_352) {
updateOrderTPs(li_32);
gi_352 = li_32;
if (gi_352 > gi_236) gi_236 = gi_352;
}
}
if (li_36) {
if (isDayBlacklisted(g_datetime_332)) gi_244 = 5;
else gi_364 = TRUE;
}
}
if (gi_244 == 6) {
if (li_36) gi_364 = TRUE;
if (!isOtherEAInTrade()) {
Print("Resuming from blocked state.");
gi_244 = 3;
}
}
}
}

void findFridayData() {
int li_0 = 0;
if (TimeDayOfWeek(TimeCurrent()) == 5) li_0 += 25;
for (int l_datetime_4 = iTime(Symbol(), PERIOD_H1, li_0); TimeDayOfWeek(l_datetime_4) != 5; l_datetime_4 = iTime(Symbol(), PERIOD_H1, li_0)) li_0++;
g_hour_368 = TimeHour(l_datetime_4);
}

void init() {
int lia_0[1];
int lia_4[1];
int lia_8[1];
int lia_12[1];
int lia_16[1];
int lia_20[1];
int lia_24[1];
int lia_28[1];
int lia_32[1];
int lia_36[1];
int lia_40[1];
int lia_44[1];
int lia_48[1];
int lia_52[1];
int lia_56[1];
int lia_60[1];
double lda_64[1];
double lda_68[1];
double lda_72[1];
double lda_76[1];
double lda_80[1];
double lda_84[1];
int lia_88[1];
int lia_92[1];
int lia_96[1];
int lia_100[1];
int lia_104[1];
int lia_108[1];
int li_112 = Initialize(AccountName(), StringLen(AccountName()), AccountNumber(), AccountCompany(), StringLen(AccountCompany()));
li_112 = 1;
if (li_112 == 1) gi_76 = TRUE;
else gi_76 = FALSE;
if (gi_76) Print("Account authorized.");
else Print("Unauthorized account!");
li_112 = GetSettings(Symbol(), lia_0, lia_4, lia_8, lia_12, lia_16, lia_20, lia_24, lia_28, lia_32, lia_36, lia_40, lia_44, lia_48, lia_52, lia_56, lia_60, lda_64, lda_68, lda_72, lda_76, lda_80, lda_84, lia_88, lia_92);
if (li_112 == 1) {
gi_116 = lia_0[0];
gi_120 = lia_4[0];
gi_124 = lia_8[0];
gi_128 = lia_12[0];
gi_132 = lia_16[0];
gi_136 = lia_20[0];
gi_140 = lia_24[0];
gi_144 = lia_28[0];
gi_148 = lia_32[0];
gi_152 = lia_36[0];
gi_156 = lia_40[0];
gi_160 = lia_44[0];
gi_164 = lia_48[0];
gi_168 = lia_52[0];
gi_172 = lia_56[0];
gi_176 = lia_60[0];
gd_180 = lda_64[0];
gd_188 = lda_68[0];
gd_196 = lda_72[0];
gd_204 = lda_76[0];
gd_212 = lda_80[0];
gd_220 = lda_84[0];
gi_228 = lia_88[0];
gi_84 = lia_92[0];
gi_80 = TRUE;
} else gi_80 = FALSE;
GetVersionInfo(lia_96, lia_100, lia_104, lia_108);
gi_88 = lia_96[0];
gi_92 = lia_100[0];
gi_96 = lia_104[0];
gi_100 = lia_108[0];
validateInputParameters();
initState();
findFridayData();
}

void deinit() {
if (ObjectFind("sellRange") == 0) ObjectDelete("sellRange");
if (ObjectFind("buyRange") == 0) ObjectDelete("buyRange");
}

string stateToString() {
string ls_unused_0;
switch (gi_244) {
case 0:
return ("Unknown");
case 2:
return ("Could not find tradeable range");
case 3:
return ("Waiting to enter trade");
case 4:
switch (gi_352) {
case 1:
return ("1 position open, price " + DoubleToStr(gd_356, 5));
case 2:
return ("2 positions open at average price " + DoubleToStr(gd_356, 5));
case 3:
return ("3 positions open at average price " + DoubleToStr(gd_356, 5));
case 4:
return ("4 positions open at average price " + DoubleToStr(gd_356, 5));
case 5:
return ("5 positions open at average price " + DoubleToStr(gd_356, 5));
}
return ("Error");
case 6:
return ("Other Enigma G-12 instance in trade.");
case 5:
return ("No trading until next day");
}
return ("n/a");
}

string MonthToStr(int ai_0) {
if (ai_0 == 1) return ("Jan");
if (ai_0 == 2) return ("Feb");
if (ai_0 == 3) return ("Mar");
if (ai_0 == 4) return ("Apr");
if (ai_0 == 5) return ("May");
if (ai_0 == 6) return ("Jun");
if (ai_0 == 7) return ("Jul");
if (ai_0 == 8) return ("Aug");
if (ai_0 == 9) return ("Sep");
if (ai_0 == 10) return ("Oct");
if (ai_0 == 11) return ("Nov");
if (ai_0 == 12) return ("Dec");
return ("Error");
}

void updateComments() {
string ls_0 = "Enigma G-12 ";
if (gi_88 == 1) ls_0 = ls_0 + "Basic ";
else {
if (gi_88 == 2) ls_0 = ls_0 + "Pro ";
else {
if (gi_88 == 3) ls_0 = ls_0 + "Ultimate ";
else {
if (gi_88 == 10) ls_0 = ls_0 + "Basic [Demo Account] ";
else {
if (gi_88 == 20) ls_0 = ls_0 + "Pro [Demo Account] ";
else
if (gi_88 == 30) ls_0 = ls_0 + "Ultimate [Demo Account] ";
}
}
}
}
ls_0 = ls_0 + "v.1.1 (C) 2010 www.quantumdollars.com"
+ "\n";
if (gi_92 == 0 && gi_96 == 0 && gi_100 == 0) ls_0 = ls_0 + "Expiration: Never\n";
else {
ls_0 = ls_0 + "Expiration: " + MonthToStr(gi_96) + "/" + gi_92 + "/" + gi_100
+ "\n";
}
if (gi_80) {
ls_0 = ls_0 + "Instrument: " + Symbol()
+ "\n";
} else ls_0 = ls_0 + "Instrument: UNAUTHORIZED\n";
ls_0 = ls_0 + "State: " + stateToString()
+ "\n";
ls_0 = ls_0 + "Short positions:";
if (gi_336) ls_0 = ls_0 + " [ALLOWED]\n";
else ls_0 = ls_0 + " [NOT ALLOWED]\n";
ls_0 = ls_0 + "Long Positions:";
if (gi_340) ls_0 = ls_0 + " [ALLOWED]\n";
else ls_0 = ls_0 + " [NOT ALLOWED]\n";
double ld_8 = 10000.0;
if (StringFind(Symbol(), "JPY") != -1) ld_8 = 100.0;
double ld_16 = MathAbs(g_ihigh_264 - g_ilow_272) * ld_8;
if (!gi_76) ls_0 = ls_0 + "UNAUTHORIZED ACCOUNT\n";
Comment(ls_0);
}

void start() {
g_datetime_332 = TimeCurrent();
updateState();
updateComments();
g_datetime_328 = g_datetime_332;
if (gi_244 != 1) {
}
}

相关资源

暂无评论

暂无评论...