//+——————————————————————+
//| EA TrapProfit.mq4 |
//| bambang |
//| http://www.bahary84@yahoo.com |
//+——————————————————————+
#property copyright “bambang”
#property link “http://www.bahary84@yahoo.com”
extern string Name_Ea = “EA Cross”;
extern bool AutoAdjustLot = FALSE;//set true bila ingin lot menghitung otomatis sesuai setting risk lot
extern int Risk_Lot = 1;//MM dalam persentase
extern double Lots = 0.1;//lot awal minimal senilai 1/100000
extern int TakeProfit =0;
extern int StopLoss = 0;
extern int TP_in_Money = 40;//nilai TP senilai 1/500 dari balance (misal modal anda 500$ maka EA akan TP setiap profit 1$ secara hedging/averaging)
extern int SL_in_Money = 0;
extern int MinEQuity = 500;
extern int MaxEQuity = 1000000;//nilai maksimal Equity maksimal disarankan 101% dr Balance/profit dibatasi 1% per hari,setelah target 1% tercapai maka EA akan berhenti bekerja,setting ke angka 0 bila anda ingin EA bekerja 24 jam
extern int Step = 40;//jarak antara tiap-tiap level OP
extern int Maximal_Trade = 10;//jumlah maksimal OP
extern double Multiplier = 1.7;//hedging/averaging lot dr tiap OPextern bool TIMEFILTER = false;//set true bila ingin membatasi waktu kerja EA
extern int GMTOffset = 0;
extern int StartHour = 0;
extern int EndHour = 10;
extern bool Friday_Close = FALSE;//set true bila tidak ingin EA ini aktif di hari Jumat
extern int Hour_to_Close = 24;
extern int Magic = 123456789;
bool gi_240 = TRUE;
int gi_244 = 0;
int gi_unused_248 = 0;
int g_cmd_252 = OP_BUY;
int gi_256 = 0;
int g_slippage_260 = 3;
double g_ord_open_price_264 = 0.0;
double g_lots_272 = 0.0;
double g_lots_280 = 0.0;
bool gi_288 = TRUE;
int gi_292;
int gi_296;
int g_count_300;
int g_pos_304;
int gi_308 = 0;
int g_datetime_312 = 0;
int gi_316;
double gd_320;
double g_minlot_328;
double g_free_magrin_336;
double gd_344;
bool gi_352;
bool gi_356;
int gi_360;
int g_count_364;
int g_pos_368;
double Alert_Sound=0;int init() {
g_minlot_328 = MarketInfo(Symbol(), MODE_MINLOT);
if (g_minlot_328 / 0.01 == 1.0) gi_360 = 2;
else gi_360 = 1;
if (Digits == 5 || Digits == 3) gi_316 = 10;
else gi_316 = 1;
gd_320 = AccountBalance();
return (0);
}int deinit() {
return (0);
}int start() {
double ld_0 = NormalizeDouble(MarketInfo(Symbol(), MODE_MINLOT), gi_360);
double ld_8 = NormalizeDouble(MarketInfo(Symbol(), MODE_MAXLOT), gi_360);
g_minlot_328 = MarketInfo(Symbol(), MODE_MINLOT);
if (g_minlot_328 / 0.01 == 1.0) gi_360 = 2;
else gi_360 = 1;
g_free_magrin_336 = AccountFreeMargin();
gd_344 = NormalizeDouble(Risk_Lot * g_free_magrin_336 / 100000.0, gi_360);
if (AutoAdjustLot) g_lots_272 = gd_344;
else g_lots_272 = Lots;
if (g_lots_272 < ld_0) g_lots_272 = ld_0;
if (g_lots_272 > ld_8) g_lots_272 = ld_8;
Total();
if (g_count_364 == 0) gd_320 = AccountBalance();
g_count_300 = 0;
for (g_pos_304 = 0; g_pos_304 < OrdersTotal(); g_pos_304++) {
OrderSelect(g_pos_304, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) g_count_300++;
}
if (gi_244 > g_count_300) {
for (g_pos_304 = OrdersTotal(); g_pos_304 >= 0; g_pos_304–) {
OrderSelect(g_pos_304, SELECT_BY_POS, MODE_TRADES);
g_cmd_252 = OrderType();
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) {
if (g_cmd_252 == OP_BUY) OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), g_slippage_260, Blue);
if (g_cmd_252 == OP_SELL) OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), g_slippage_260, Red);
return (0);
}
}
}
gi_244 = g_count_300;
if (g_count_300 >= Maximal_Trade) gi_240 = FALSE;
else gi_240 = TRUE;
if (g_ord_open_price_264 == 0.0) {
for (g_pos_304 = 0; g_pos_304 < OrdersTotal(); g_pos_304++) {
OrderSelect(g_pos_304, SELECT_BY_POS, MODE_TRADES);
g_cmd_252 = OrderType();
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) {
g_ord_open_price_264 = OrderOpenPrice();
if (g_cmd_252 == OP_BUY) gi_256 = 2;
if (g_cmd_252 == OP_SELL) gi_256 = 1;
}
}
}
if (g_count_300 < 1 && gi_288 == TRUE) gi_256 = signal();
if (gi_256 == 1 && gi_240 && TimeFilter() && !gi_352 && !StopJumat()) {
if (Bid – g_ord_open_price_264 >= Step * gi_316 * Point || g_count_300 < 1) {
g_ord_open_price_264 = 0;
if (g_count_300 != 0) {
g_lots_280 = g_lots_272;
for (g_pos_304 = 1; g_pos_304 <= g_count_300; g_pos_304++) g_lots_280 = NormalizeDouble(g_lots_280 * Multiplier, gi_360);
} else g_lots_280 = g_lots_272;
OrderSend(Symbol(), OP_SELL, g_lots_280, Bid, g_slippage_260, 0, 0, “”, Magic, 0, Red);
return (0);
}
}
if (gi_256 == 2 && gi_240 && TimeFilter() && !gi_352 && !StopJumat()) {
if (g_ord_open_price_264 – Ask >= Step * gi_316 * Point || g_count_300 < 1) {
g_ord_open_price_264 = 0;
if (g_count_300 != 0) {
g_lots_280 = g_lots_272;
for (g_pos_304 = 1; g_pos_304 <= g_count_300; g_pos_304++) g_lots_280 = NormalizeDouble(g_lots_280 * Multiplier, gi_360);
} else g_lots_280 = g_lots_272;
OrderSend(Symbol(), OP_BUY, g_lots_280, Ask, g_slippage_260, 0, 0, “”, Magic, 0, Blue);
return (0);
}
}
getOpenOrders();
if (SL_in_Money != 0) StopLossTarget();
if (TP_in_Money != 0) StopTargetProfit();
if (MaxEQuity != 0) TargetProfitEquity();
if (MinEQuity != 0) StopLossEquity();
if (Friday_Close == TRUE) CloseHariJumat();
Monitor(“EA”,”EA mboh iki…”, 11, 3, 10, Green, 0);
return (0);
}int signal() {
gi_256 = 3;
double MA_PARABOLIC=iCustom(NULL,0,”MA_Parabolic_Alert_2″,24,MODE_SMMA,PRICE_CLOSE,0.02,0.08, 0);
double MA_PARABOLIC1=iCustom(NULL,0,”MA_Parabolic_Alert_2″,24,MODE_SMMA,PRICE_CLOSE,0.02,0.08, 1);
if (MA_PARABOLIC < Close[0] ) gi_256 = 2;
if (MA_PARABOLIC > Close[0]) gi_256 =1;if (gi_244 == 1) {
if (gi_256 == 1) gi_256 = 2;
else
if (gi_256 == 2) gi_256 = 1;
}
return (gi_256);
}int TimeFilter() {
gi_296 = EndHour + GMTOffset;
gi_292 = StartHour + GMTOffset;
if (StartHour + GMTOffset < 0) gi_292 = StartHour + GMTOffset + 24;
if (EndHour + GMTOffset < 0) gi_296 = EndHour + GMTOffset + 24;
if (StartHour + GMTOffset > 24) gi_292 = StartHour + GMTOffset – 24;
if (EndHour + GMTOffset > 24) gi_296 = EndHour + GMTOffset – 24;
if (TIMEFILTER == FALSE) return (1);
if (gi_292 < gi_296) {
if (Hour() >= gi_292 && Hour() < gi_296) return (1);
return (0);
}
if (gi_292 > gi_296) {
if (Hour() >= gi_292 || Hour() < gi_296) return (1);
return (0);
}
return (0);
}double getPipValue(double ad_0, int ai_8) {
double ld_ret_12;
RefreshRates();
if (ai_8 == 1) ld_ret_12 = NormalizeDouble(ad_0, Digits) – NormalizeDouble(Ask, Digits);
else ld_ret_12 = NormalizeDouble(Bid, Digits) – NormalizeDouble(ad_0, Digits);
ld_ret_12 /= Point;
return (ld_ret_12);
}void getOpenOrders() {
double ld_8;
int l_ord_total_0 = OrdersTotal();
for (int l_pos_4 = 0; l_pos_4 < l_ord_total_0; l_pos_4++) {
OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES);
if (OrderType() == OP_BUY || OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) {
ld_8 = getPipValue(OrderOpenPrice(), OrderType());
if (TakeProfit != 0) takeProfit(ld_8, OrderTicket());
if (StopLoss != 0) killTrade(ld_8, OrderTicket());
}
}
}void takeProfit(int ai_0, int a_ticket_4) {
int li_unused_8;
if (OrderSelect(a_ticket_4, SELECT_BY_TICKET) == TRUE) {
li_unused_8 = MarketInfo(Symbol(), MODE_SPREAD);
if (ai_0 >= TakeProfit * gi_316) {
if (OrderType() == OP_SELL) OrderClose(a_ticket_4, OrderLots(), Ask, g_slippage_260, Red);
if (OrderType() == OP_BUY) OrderClose(a_ticket_4, OrderLots(), Bid, g_slippage_260, Blue);
}
}
}void killTrade(int ai_0, int a_ticket_4) {
if (OrderSelect(a_ticket_4, SELECT_BY_TICKET) == TRUE) {
if (ai_0 <= (-StopLoss) * gi_316) {
if (OrderType() == OP_SELL && OrderMagicNumber() == Magic && OrderSymbol() == Symbol()) OrderClose(a_ticket_4, OrderLots(), Ask, g_slippage_260, Red);
if (OrderType() == OP_BUY && OrderMagicNumber() == Magic && OrderSymbol() == Symbol()) OrderClose(a_ticket_4, OrderLots(), Bid, g_slippage_260, Blue);
}
}
}void StopLossTarget() {
if (gd_320 – AccountEquity() >= SL_in_Money) {
for (g_pos_368 = 0; g_pos_368 < OrdersTotal(); g_pos_368++) {
OrderSelect(g_pos_368, SELECT_BY_POS, MODE_TRADES);
if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, g_slippage_260, Red);
if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, g_slippage_260, Blue);
}
}
}void StopTargetProfit() {
if (AccountEquity() – gd_320 >= TP_in_Money) {
for (g_pos_368 = 0; g_pos_368 < OrdersTotal(); g_pos_368++) {
OrderSelect(g_pos_368, SELECT_BY_POS, MODE_TRADES);
if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, g_slippage_260, Red);
if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, g_slippage_260, Blue);
}
}
}void Total() {
g_count_364 = 0;
for (g_pos_304 = 0; g_pos_304 < OrdersTotal(); g_pos_304++) {
OrderSelect(g_pos_304, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) g_count_364++;
}
}void CloseHariJumat() {
if (StopJumat()) {
for (g_pos_368 = 0; g_pos_368 < OrdersTotal(); g_pos_368++) {
OrderSelect(g_pos_368, SELECT_BY_POS, MODE_TRADES);
if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, g_slippage_260, Red);
if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, g_slippage_260, Blue);
}
}
}bool StopJumat() {
if (DayOfWeek() == 5 && Hour() >= Hour_to_Close) return (TRUE);
return (FALSE);
}void TargetProfitEquity() {
if (AccountEquity() >= MaxEQuity) {
for (int l_pos_0 = 0; l_pos_0 < OrdersTotal(); l_pos_0++) {
OrderSelect(l_pos_0, SELECT_BY_POS, MODE_TRADES);
if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, g_slippage_260, Red);
if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, g_slippage_260, Blue);
}
gi_352 = TRUE;
if (!gi_356) {
gi_356 = TRUE;
Alert(“Target Equity Tercapai, set ulang EA”);
}
}
}void StopLossEquity() {
if (AccountEquity() <= MinEQuity) {
for (g_pos_368 = 0; g_pos_368 < OrdersTotal(); g_pos_368++) {
OrderSelect(g_pos_368, SELECT_BY_POS, MODE_TRADES);
if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, g_slippage_260, Red);
if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, g_slippage_260, Blue);
}
gi_352 = TRUE;
if (!gi_356) {
gi_356 = TRUE;
Alert(“Max Loss Kena, set ulang EA”);
}
}
}void Monitor(string a_name_0, string a_text_8, int a_fontsize_16, int a_x_20, int a_y_24, color a_color_28, int a_corner_32) {
ObjectCreate(a_name_0, OBJ_LABEL, 0, 0, 0, 0, 0);
ObjectSet(a_name_0, OBJPROP_CORNER, a_corner_32);
ObjectSet(a_name_0, OBJPROP_XDISTANCE, a_x_20);
ObjectSet(a_name_0, OBJPROP_YDISTANCE, a_y_24);
ObjectSetText(a_name_0, a_text_8, a_fontsize_16, “Tahoma”, a_color_28);
}
暂无评论...