hi, I have compiled a partial close metatrader strategy in jfx, it looks ok, no errors during compilation process:
[code]#property copyright "Copyright � 2009, IBFX" #property link "https://www.IBFX.com"
extern int InstanceID = 5; extern int TicketNumber = 0; extern int PipsTarget_1 = 10; extern double CloseLotsPercentage_1 = 10.0; extern int Move_SL_1 = 1; extern int PipsTarget_2 = 25; extern double CloseLotsPercentage_2 = 25.0; extern int Move_SL_2 = 0; extern int PipsTarget_3 = 50; extern double CloseLotsPercentage_3 = 50.0; extern int Move_SL_3 = 0; extern int PipsTarget_4 = 100; extern double CloseLotsPercentage_4 = 100.0; extern int Move_SL_4 = 0; string gs_ibfx_pc__148 = "IBFX-PC-"; int g_str_len_156 = 10; int gi_160 = 1; bool gi_164 = FALSE;
int init() { gs_ibfx_pc__148 = "IBFX-PC-" + InstanceID + "-"; g_str_len_156 = StringLen(gs_ibfx_pc__148); if (MarketInfo(Symbol(), MODE_MINLOT) == 0.01) gi_160 = 2; fnGvCheck(); return (0); }
int start() { int l_ticket_4; int li_8; int l_global_var_12; int li_16; int li_unused_20; int li_24; double l_lots_28; bool l_ord_close_40; bool l_bool_44; double l_point_48;
for (int l_pos_0 = OrdersTotal() - 1; l_pos_0 >= 0; l_pos_0--) { if (OrderSelect(l_pos_0, SELECT_BY_POS, MODE_TRADES)) { l_ticket_4 = OrderTicket(); if (l_ticket_4 == TicketNumber || GlobalVariableCheck(StringConcatenate(gs_ibfx_pc__148, l_ticket_4))) { li_8 = fnGetPipProfit(OrderSymbol(), OrderOpenPrice(), OrderType()); if (!GlobalVariableCheck(StringConcatenate(gs_ibfx_pc__148, l_ticket_4))) GlobalVariableSet(StringConcatenate(gs_ibfx_pc__148, DoubleToStr(l_ticket_4, 0)), 1); l_global_var_12 = GlobalVariableGet(StringConcatenate(gs_ibfx_pc__148, DoubleToStr(l_ticket_4, 0))); li_16 = 0; li_unused_20 = 0; li_24 = 0; l_lots_28 = 0.0; switch (l_global_var_12) { case 1: li_24 = Move_SL_1; li_16 = PipsTarget_1; l_lots_28 = NormalizeDouble(OrderLots() * CloseLotsPercentage_1 / 100.0, gi_160); break; case 2: li_24 = Move_SL_2; li_16 = PipsTarget_2; l_lots_28 = NormalizeDouble(OrderLots() * CloseLotsPercentage_2 / 100.0, gi_160); break; case 3: li_24 = Move_SL_3; li_16 = PipsTarget_3; l_lots_28 = NormalizeDouble(OrderLots() * CloseLotsPercentage_3 / 100.0, gi_160); break; case 4: li_24 = Move_SL_4; li_16 = PipsTarget_4; l_lots_28 = NormalizeDouble(OrderLots() * CloseLotsPercentage_4 / 100.0, gi_160); break; default: li_24 = 0; l_lots_28 = 0.0; li_16 = 0; } if (li_8 >= li_16 && li_16 != 0) { l_ord_close_40 = FALSE; l_bool_44 = FALSE; l_point_48 = MarketInfo(OrderSymbol(), MODE_POINT); if (l_point_48 == 0.001) l_point_48 = 0.01; else if (l_point_48 == 0.00001) l_point_48 = 0.0001; switch (OrderType()) { case OP_BUY: if (li_24 > 0) { RefreshRates(); fnWait(); l_bool_44 = OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() + li_24 * l_point_48, OrderTakeProfit(), 0, CLR_NONE); } if (l_lots_28 != 0.0) { RefreshRates(); fnWait(); l_ord_close_40 = OrderClose(l_ticket_4, l_lots_28, MarketInfo(OrderSymbol(), MODE_BID), 0, CLR_NONE); } break; case OP_SELL: if (li_24 > 0) { RefreshRates(); fnWait(); l_bool_44 = OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() - li_24 * l_point_48, OrderTakeProfit(), 0, CLR_NONE); } if (l_lots_28 != 0.0) { RefreshRates(); fnWait(); l_ord_close_40 = OrderClose(l_ticket_4, l_lots_28, MarketInfo(OrderSymbol(), MODE_ASK), 0, CLR_NONE); } } if (l_ord_close_40 || l_bool_44) fnCreateNewGv(l_ticket_4, l_global_var_12); } } } } fnGvCheck(); return (0); }
void fnWait() { if (IsConnected() && IsTradeAllowed()) while (IsTradeContextBusy()) Sleep(75); }
void fnGvCheck() { string ls_4; int l_str2int_12; if (TicketNumber != 0) { for (int li_0 = GlobalVariablesTotal() - 1; li_0 >= 0; li_0--) { ls_4 = GlobalVariableName(li_0); if (StringFind(ls_4, gs_ibfx_pc__148, -1) != -1) { l_str2int_12 = StrToInteger(StringSubstr(ls_4, g_str_len_156, -1)); if (OrderSelect(l_str2int_12, SELECT_BY_TICKET, MODE_TRADES)) if (OrderCloseTime() != 0) GlobalVariableDel(ls_4); } } } }
int fnGetPipProfit(string a_symbol_0, double ad_8, int ai_16) { bool li_ret_20 = FALSE; RefreshRates(); double l_ask_24 = MarketInfo(a_symbol_0, MODE_ASK); double l_bid_32 = MarketInfo(a_symbol_0, MODE_BID); double l_point_40 = MarketInfo(a_symbol_0, MODE_POINT); if (l_point_40 == 0.001) l_point_40 = 0.01; else if (l_point_40 == 0.00001) l_point_40 = 0.0001; switch (ai_16) { case 0: li_ret_20 = MathCeil((l_bid_32 - ad_8) / l_point_40); break; case 1: li_ret_20 = MathCeil((ad_8 - l_ask_24) / l_point_40); break; default: li_ret_20 = FALSE; } return (li_ret_20); }
void fnCreateNewGv(int ai_0, int ai_4) { string l_str_concat_8 = StringConcatenate("from #", ai_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 (OrderComment() == l_str_concat_8 || OrderTicket() == ai_0) GlobalVariableSet(StringConcatenate(gs_ibfx_pc__148, OrderTicket()), ai_4 + 1); } }[/code
could anyone explain how to use "instance id" and "ticket number" ? can the strategy be modified, in order to apply to all orders? already opened or to be opened?
thank you ,
|