Forex Wonder
Forex Wonder

Forex Wonder

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

35 人已下载 手机查看

Forex Wonder

#property copyright “Copyright QQ:9695905”
#property link “www.hualibao.net”

extern int Magic = 20090505;
extern string Comment1 = “Money Management”;
extern double Lots = 0.1;
extern bool RiskManagementEnable = TRUE;
extern double RiskPercent = 1.0;
extern double MinLots = 0.01;
extern double MaxLots = 100.0;
extern string Comment2 = “Order Management”;
extern int StopLoss = 350;
extern int TakeProfit = 600;
extern int TrailingProfit = 0;
extern int TrailingStop = 0;
extern int TrailingStep = 0;
extern int starttime = 18;
extern int stoptime = 23;
extern string MyComment = “Dont change any of the below parameters”;
extern int X = 55;
extern int Y = 55;
extern int Z = 80;
extern int RSI_period = 40;
extern int RSI_price = 0;
extern int BB1_period = 80;
extern int BB1_deviation = 2;
extern int BB1_shift = 0;
extern int BB2_period = 25;
extern int BB2_deviation = 2;
extern int BB2_shift = 0;
extern int BB2_price = 4;
extern int StartMonth = 1;
extern int StartDay = 1;
extern int EndMonth = 12;
extern int EndDay = 15;
extern int szpar1 = 100;
extern int szpar2 = 100000;
extern double Multiplier1 = 2.0;
extern double Multiplier2 = 4.0;
extern double Multiplier3 = 8.0;
double gd_264;
int g_slippage_272 = 3;
int g_stoplevel_276;
double gda_280[400];
double g_ibands_on_arr_284;
double g_ibands_on_arr_292;
double g_ibands_on_arr_300;
double g_ibands_308;
double g_ibands_316;
int g_digits_324;
double gd_328;
int g_time_336 = 0;
double gd_340 = 0.0;
double gd_348 = 0.0;
int gia_356[1000];
int gi_360 = 0;
int gi_364 = 0;
int gi_unused_368 = 0;

int init() {
g_digits_324 = Digits;
gd_328 = GetPoints();
g_stoplevel_276 = MarketInfo(Symbol(), MODE_STOPLEVEL);
return (0);
}

int deinit() {
SemaphoreDeinit(“EXPLAINATION”);
return (0);
}

double GetPoints() {
if (Digits == 3 || Digits == 5) gd_328 = 10.0 * Point;
else gd_328 = Point;
return (gd_328);
}

int start() {
if (TrailingStop > 0) MoveTrailingStop();
if (RiskManagementEnable) CalculateMM();
int li_0 = 0;
int li_4 = 0;
int l_cmd_8 = 0;
int li_12 = -1;
int li_16 = 0;
int li_20 = -1;
gd_264 = Lots;
if (gd_264 > MaxLots) gd_264 = MaxLots;
CheckSusp();
datetime l_time_24 = Time[0];
if (g_time_336 < l_time_24) {
g_time_336 = l_time_24;
tTrace();
li_4 = CheckForActive();
if (li_4 == 0) {
ExecuteClose();
tTrace();
}
li_0 = tGetT();
if (li_0 == 0) {
CountBoll2();
li_16 = CheckCondition2();
if (li_16 == 1) {
CountRSIBoll1();
li_12 = CheckCondition1();
switch (li_12) {
case 0:
ExecuteBuy();
break;
case 1:
ExecuteSell();
}
}
} else {
CountRSIBoll1();
li_20 = CheckCondition3();
OrderSelect(tGetTicket(0), SELECT_BY_TICKET);
l_cmd_8 = OrderType();
switch (l_cmd_8) {
case OP_BUY:
if (li_20 == -10) ExecuteClose();
break;
case OP_SELL:
if (li_20 == -20) ExecuteClose();
}
}
}
return (0);
}

void CountBoll2() {
g_ibands_308 = iBands(NULL, 0, BB2_period, BB2_deviation, BB2_shift, BB2_price, MODE_UPPER, 1);
g_ibands_316 = iBands(NULL, 0, BB2_period, BB2_deviation, BB2_shift, BB2_price, MODE_LOWER, 1);
}

int CheckCondition2() {
if (High[1] < g_ibands_308 && Low[1] > g_ibands_316 && starttime <= Hour() && stoptime >= Hour()) return (1);
return (0);
}

void CountRSIBoll1() {
for (int li_0 = 0; li_0 < BB1_period + 1; li_0++) gda_280[li_0] = iRSI(NULL, 0, RSI_period, RSI_price, li_0);
ArraySetAsSeries(gda_280, TRUE);
g_ibands_on_arr_284 = iBandsOnArray(gda_280, 0, BB1_period, BB1_deviation, BB1_shift, 0, 1);
g_ibands_on_arr_292 = iBandsOnArray(gda_280, 0, BB1_period, BB1_deviation, BB1_shift, 1, 1);
g_ibands_on_arr_300 = iBandsOnArray(gda_280, 0, BB1_period, BB1_deviation, BB1_shift, 2, 1);
}

int CheckCondition1() {
if (gda_280[1] > g_ibands_on_arr_292) return (1);
if (gda_280[1] < g_ibands_on_arr_300) return (0);
return (-1);
}

int CheckCondition3() {
if (gda_280[1] > g_ibands_on_arr_284) return (-10);
if (gda_280[1] < g_ibands_on_arr_284) return (-20);
return (-1);
}

int CheckForActive() {
int l_cmd_0;
int li_8 = tGetT();
if (li_8 == 0) return (-1);
for (int l_count_4 = 0; l_count_4 < li_8; l_count_4++) {
OrderSelect(tGetTicket(l_count_4), SELECT_BY_TICKET);
l_cmd_0 = OrderType();
if (l_cmd_0 == OP_BUY || l_cmd_0 == OP_SELL) return (1);
}
return (0);
}

void ExecuteBuy() {
int l_ticket_0;
SemaphoreTake(“EXPLAINATION”);
if ((Month() > StartMonth && Month() < EndMonth) || (Month() == StartMonth && Day() >= StartDay) || (Month() == EndMonth && Day() <= EndDay)) l_ticket_0 = tOrderSend(Symbol(), OP_BUY, gd_264, Ask, g_slippage_272, Bid – StopLoss * gd_328, Bid + TakeProfit * gd_328, 0, Magic);
SemaphoreReturn(“EXPLAINATION”);
if (l_ticket_0 <= 0) {
Alert(“OrderSend Buy Error: “, GetLastError());
Print(“Ask”, Ask, “Stop Loss Error “, Bid – StopLoss * gd_328, “Take Profit Error “, Bid + TakeProfit * gd_328, “with the point”, gd_328);
return;
}
OrderSelect(l_ticket_0, SELECT_BY_TICKET);
if (X > 0) {
if (X > g_stoplevel_276) {
SemaphoreTake(“EXPLAINATION”);
if ((Month() > StartMonth && Month() < EndMonth) || (Month() == StartMonth && Day() >= StartDay) || (Month() == EndMonth && Day() <= EndDay)) l_ticket_0 = tOrderSend(Symbol(), OP_BUYLIMIT, Multiplier1 * gd_264, Ask – X * gd_328, g_slippage_272, OrderStopLoss(), OrderTakeProfit(), 0, Magic);
SemaphoreReturn(“EXPLAINATION”);
if (l_ticket_0 <= 0) Alert(“X: OrderSend Error: “, GetLastError());
} else SuspendBuy(Ask – X * gd_328);
}
if (Y > 0) {
if (Y > g_stoplevel_276) {
SemaphoreTake(“EXPLAINATION”);
if ((Month() > StartMonth && Month() < EndMonth) || (Month() == StartMonth && Day() >= StartDay) || (Month() == EndMonth && Day() <= EndDay)) l_ticket_0 = tOrderSend(Symbol(), OP_BUYLIMIT, Multiplier2 * gd_264, Ask – Y * gd_328, g_slippage_272, OrderStopLoss(), OrderTakeProfit(), 0, Magic);
SemaphoreReturn(“EXPLAINATION”);
if (l_ticket_0 <= 0) Alert(“Y: OrderSend Error: “, GetLastError());
} else Alert(“Y <= StopLevel – Unable to send Limit Order”);
}
if (Z > 0) {
if (Z > g_stoplevel_276) {
SemaphoreTake(“EXPLAINATION”);
if ((Month() > StartMonth && Month() < EndMonth) || (Month() == StartMonth && Day() >= StartDay) || (Month() == EndMonth && Day() <= EndDay)) l_ticket_0 = tOrderSend(Symbol(), OP_BUYLIMIT, Multiplier3 * gd_264, Ask – Z * gd_328, g_slippage_272, OrderStopLoss(), OrderTakeProfit(), 0, Magic);
SemaphoreReturn(“EXPLAINATION”);
if (l_ticket_0 <= 0) Alert(“Z: OrderSend Error: “, GetLastError());
} else Alert(“Z <= StopLevel – Unable to send Limit Order”);
}
}

void ExecuteSell() {
int l_ticket_0;
SemaphoreTake(“EXPLAINATION”);
if ((Month() > StartMonth && Month() < EndMonth) || (Month() == StartMonth && Day() >= StartDay) || (Month() == EndMonth && Day() <= EndDay)) l_ticket_0 = tOrderSend(Symbol(), OP_SELL, Multiplier1 * gd_264, Bid, g_slippage_272, Ask + StopLoss * gd_328, Ask – TakeProfit * gd_328, 0, Magic);
SemaphoreReturn(“EXPLAINATION”);
if (l_ticket_0 <= 0) {
Alert(“OrderSend SellError: “, GetLastError());
Print(“Stop Loss Sell Error”, Ask + StopLoss * gd_328, “Take Profit Error”, Ask – TakeProfit * gd_328, “with the point”, gd_328);
return;
}
OrderSelect(l_ticket_0, SELECT_BY_TICKET);
if (X > 0) {
if (X > g_stoplevel_276) {
SemaphoreTake(“EXPLAINATION”);
if ((Month() > StartMonth && Month() < EndMonth) || (Month() == StartMonth && Day() >= StartDay) || (Month() == EndMonth && Day() <= EndDay)) l_ticket_0 = tOrderSend(Symbol(), OP_SELLLIMIT, Multiplier2 * gd_264, Bid + X * gd_328, g_slippage_272, OrderStopLoss(), OrderTakeProfit(), 0, Magic);
SemaphoreReturn(“EXPLAINATION”);
if (l_ticket_0 <= 0) Alert(“X: OrderSend Error: “, GetLastError());
} else SuspendSell(Bid + X * gd_328);
}
if (Y > 0) {
if (Y > g_stoplevel_276) {
SemaphoreTake(“EXPLAINATION”);
if ((Month() > StartMonth && Month() < EndMonth) || (Month() == StartMonth && Day() >= StartDay) || (Month() == EndMonth && Day() <= EndDay)) l_ticket_0 = tOrderSend(Symbol(), OP_SELLLIMIT, Multiplier3 * gd_264, Bid + Y * gd_328, g_slippage_272, OrderStopLoss(), OrderTakeProfit(), 0, Magic);
SemaphoreReturn(“EXPLAINATION”);
if (l_ticket_0 <= 0) Alert(“Y: OrderSend Error: “, GetLastError());
} else Alert(“Y <= StopLevel – Unable to send Limit Order”);
}
if (Z > 0) {
if (Z > g_stoplevel_276) {
SemaphoreTake(“EXPLAINATION”);
if ((Month() > StartMonth && Month() < EndMonth) || (Month() == StartMonth && Day() >= StartDay) || (Month() == EndMonth && Day() <= EndDay)) l_ticket_0 = tOrderSend(Symbol(), OP_SELLLIMIT, gd_264, Bid + Z * gd_328, g_slippage_272, OrderStopLoss(), OrderTakeProfit(), 0, Magic);
SemaphoreReturn(“EXPLAINATION”);
if (l_ticket_0 <= 0) Alert(“Z: OrderSend Error: “, GetLastError());
} else Alert(“Z <= StopLevel – Unable to send Limit Order”);
}
}

void ExecuteClose() {
int li_0;
int l_cmd_4;
int li_12 = tGetT();
for (int l_count_8 = 0; l_count_8 < li_12; l_count_8++) {
OrderSelect(tGetTicket(l_count_8), SELECT_BY_TICKET);
l_cmd_4 = OrderType();
if (l_cmd_4 == OP_BUY) {
SemaphoreTake(“EXPLAINATION”);
li_0 = OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(Bid, g_digits_324), g_slippage_272, White);
SemaphoreReturn(“EXPLAINATION”);
if (li_0 == 0) Alert(“OrderClose Error: “, GetLastError());
} else {
if (l_cmd_4 == OP_SELL) {
SemaphoreTake(“EXPLAINATION”);
li_0 = OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(Ask, g_digits_324), g_slippage_272, White);
SemaphoreReturn(“EXPLAINATION”);
if (li_0 == 0) Alert(“OrderClose Error: “, GetLastError());
} else {
SemaphoreTake(“EXPLAINATION”);
li_0 = OrderDelete(OrderTicket());
SemaphoreReturn(“EXPLAINATION”);
if (li_0 == 0) Alert(“OrderDelete Error: “, GetLastError());
}
}
DeleteSusp();
}
}

void SuspendBuy(double ad_0) {
gd_340 = ad_0;
}

void SuspendSell(double ad_0) {
gd_348 = ad_0;
}

void DeleteSusp() {
gd_340 = 0.0;
gd_348 = 0.0;
}

void CheckSusp() {
int li_0;
if (gd_340 > 0.0 && Ask < gd_340) {
OrderSelect(tGetTicket(0), SELECT_BY_TICKET);
SemaphoreTake(“EXPLAINATION”);
if ((Month() > StartMonth && Month() < EndMonth) || (Month() == StartMonth && Day() >= StartDay) || (Month() == EndMonth && Day() <= EndDay)) li_0 = tOrderSend(Symbol(), OP_BUY, gd_264, Ask, g_slippage_272, OrderStopLoss(), OrderTakeProfit(), 0, Magic);
SemaphoreReturn(“EXPLAINATION”);
if (li_0 <= 0) Alert(“Suspend: OrderSend Error: “, GetLastError());
else gd_340 = 0.0;
}
if (gd_348 > 0.0 && Bid > gd_348) {
OrderSelect(tGetTicket(0), SELECT_BY_TICKET);
SemaphoreTake(“EXPLAINATION”);
if ((Month() > StartMonth && Month() < EndMonth) || (Month() == StartMonth && Day() >= StartDay) || (Month() == EndMonth && Day() <= EndDay)) li_0 = tOrderSend(Symbol(), OP_SELL, gd_264, Bid, g_slippage_272, OrderStopLoss(), OrderTakeProfit(), 0, Magic);
SemaphoreReturn(“EXPLAINATION”);
if (li_0 <= 0) Alert(“Suspend: OrderSend Error: “, GetLastError());
else gd_348 = 0.0;
}
}

void tAdd(int ai_0) {
gia_356[gi_360] = ai_0;
gi_360++;
}

void tRemove(int ai_0) {
for (int li_4 = ai_0; li_4 < gi_360 – 1; li_4++) gia_356[li_4] = gia_356[li_4 + 1];
gia_356[gi_360 – 1] = 0;
gi_360–;
}

void tTrace() {
for (int li_0 = gi_360 – 1; li_0 >= 0; li_0–) {
if (!OrderSelect(gia_356[li_0], SELECT_BY_TICKET)) tRemove(li_0);
else
if (OrderCloseTime() != 0) tRemove(li_0);
}
}

int tGetT() {
return (gi_360);
}

int tGetTicket(int ai_0) {
return (gia_356[ai_0]);
}

int tOrderSend(string a_symbol_0, int a_cmd_8, double a_lots_12, double ad_20, int a_slippage_28, double ad_32, double ad_40, string a_comment_48, int a_magic_56 = 0, int a_datetime_60 = 0, color a_color_64 = -1) {
int l_ticket_68 = OrderSend(a_symbol_0, a_cmd_8, a_lots_12, NormalizeDouble(ad_20, g_digits_324), a_slippage_28, NormalizeDouble(ad_32, g_digits_324), NormalizeDouble(ad_40, g_digits_324), a_comment_48, a_magic_56, a_datetime_60, a_color_64);
if (l_ticket_68 > 0) tAdd(l_ticket_68);
return (l_ticket_68);
}

void SemaphoreTake(string a_var_name_0) {
if (GlobalVariableCheck(a_var_name_0) == FALSE) GlobalVariableSet(a_var_name_0, 0);
while (true) {
if (GlobalVariableSetOnCondition(a_var_name_0, 1.0, 0.0)) {
gi_364 = TRUE;
Print(“SWITCH \””, a_var_name_0, “\” TAKEN. CURRENT VALUE: “, GlobalVariableGet(a_var_name_0));
return;
}
Print(“ATTEMPT TO CAPTURE SWITCH \””, a_var_name_0, “\” FAILED. SWITCH BUSY. WAITING 0.1 SEC. CURRENT VALUE: “, GlobalVariableGet(a_var_name_0));
Sleep(100);
}
}

void SemaphoreReturn(string a_var_name_0) {
GlobalVariableSet(a_var_name_0, 0.0);
Print(“SWITCH \””, a_var_name_0, “\” RETURNED. CURRENT VALUE: “, GlobalVariableGet(a_var_name_0));
gi_364 = FALSE;
}

void SemaphoreDeinit(string a_var_name_0) {
if (gi_364 == TRUE) GlobalVariableSet(a_var_name_0, 0.0);
}

void MoveTrailingStop() {
int l_ord_total_4 = OrdersTotal();
for (int l_pos_0 = 0; l_pos_0 < l_ord_total_4; l_pos_0++) {
OrderSelect(l_pos_0, SELECT_BY_POS, MODE_TRADES);
if (OrderType() <= OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) {
if (OrderType() == OP_BUY) {
if (!(TrailingStop > 0 && NormalizeDouble(Ask – TrailingStep * gd_328, g_digits_324) > NormalizeDouble(OrderOpenPrice() + TrailingProfit * gd_328, g_digits_324))) continue;
if (!(NormalizeDouble(OrderStopLoss(), g_digits_324) < NormalizeDouble(Bid – TrailingStop * gd_328, g_digits_324) || OrderStopLoss() == 0.0)) continue;
OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Bid – TrailingStop * gd_328, g_digits_324), OrderTakeProfit(), 0, Blue);
return;
}
if (TrailingStop > 0 && NormalizeDouble(Bid + TrailingStep * gd_328, g_digits_324) < NormalizeDouble(OrderOpenPrice() – TrailingProfit * gd_328, g_digits_324)) {
if (NormalizeDouble(OrderStopLoss(), g_digits_324) > NormalizeDouble(Ask + TrailingStop * gd_328, g_digits_324) || OrderStopLoss() == 0.0) {
OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Ask + TrailingStop * gd_328, g_digits_324), OrderTakeProfit(), 0, Red);
return;
}
}
}
}
}

void CalculateMM() {
double l_minlot_0 = MarketInfo(Symbol(), MODE_MINLOT);
double l_maxlot_8 = MarketInfo(Symbol(), MODE_MAXLOT);
Lots = AccountFreeMargin() / 100000.0 * RiskPercent;
Lots = MathMin(l_maxlot_8, MathMax(l_minlot_0, Lots));
if (l_minlot_0 < 0.1) Lots = NormalizeDouble(Lots, 2);
else {
if (l_minlot_0 < 1.0) Lots = NormalizeDouble(Lots, 1);
else Lots = NormalizeDouble(Lots, 0);
}
if (Lots < l_minlot_0) Lots = l_minlot_0;
if (Lots > l_maxlot_8) Lots = l_maxlot_8;
}

如果你对文件有了解,请帮助投票!

If you are familiar with the file, please help vote!

平均评分 0 / 5. 投票数: 0

到目前为止还没有投票!成为第一位投票人。

相关资源

暂无评论

none
暂无评论...