//////////////////////////////////////////////////double GetRiskPercent(string as_0) {
string lsa_8[];
string ls_20;
string ls_28;
string ls_36;
int li_44;
if (StringLen(RiskPercentages) == 0) return (-1);
SplitString(RiskPercentages, ";", lsa_8);
int l_arr_size_12 = ArraySize(lsa_8);
for (int l_index_16 = 0; l_index_16 < l_arr_size_12; l_index_16++) {
ls_36 = "1.0";
ls_20 = lsa_8[l_index_16];
li_44 = StringFind(ls_20, ":");
if (li_44 == -1) ls_28 = ls_20;
else {
ls_28 = StringSubstr(ls_20, 0, li_44);
ls_36 = StringSubstr(ls_20, li_44 + 1);
ls_36 = StringReplace(ls_36, ",", '.');
}
Print("System Name: ", ls_28, "; Risk Percentage: ", ls_36);
if (as_0 == ls_28) return (StrToDouble(ls_36));
}
return (-1);
}
//////////////////////////////////////////////////
void SetFixedSLTP(int a_ticket_0, string as_4, string as_12, double ad_20, double ad_28) {
double l_price_36;
double l_price_44;
if (Ignore_SL_TP_ForMarketOrders) {
GetMarketInfo(as_12);
l_price_36 = GetRelativeStopLoss(0, as_4, ad_20);
l_price_44 = GetRelativeTakeProfit(0, as_4, ad_28);
OrderModify(a_ticket_0, GetMarketPriceByOrderType(as_4), l_price_36, l_price_44, 0);
}
}
//////////////////////////////////////////////////
double GetMarketPriceByOrderType(string as_0) {
if (as_0 == "BUY") return (g_ask_92);
if (as_0 == "SELL") return (g_bid_84);
int li_8 = 0;
Print("Exception: Can\'t get price. Not market order type.");
return (1 / li_8);
}
void ProcessTask() {
int l_magic_12;
int l_ticket_16;
string ls_20;
string l_symbol_28;
string l_str_concat_36;
string ls_44;
double l_price_52;
double l_price_60;
double l_price_68;
double ld_76;
double l_lots_84;
int li_92;
double ld_104;
double ld_112;
double ld_120;
double ld_128;
double ld_136;
double ld_144;
double ld_152;
double ld_160;
double ld_168;
double ld_176;
double SL,TP;
bool modifyticket;
int triedN;
//////////////////////////////////////////////////
string ls_96 = "Please contact us at
[email protected] to get full version";
if (ReadTaskFile(l_magic_12, ls_20, l_symbol_28, ls_44, l_price_52, l_price_60, l_price_68, l_lots_84, li_92) >= 1) {
double l=l_lots_84;
Print("---");
Print("Hey, we got a task to do! Wooohooo! Let\'\'s see...");
Print("Provider ticket: ", l_magic_12, ", Type: ", ls_20, ", Currency: ", l_symbol_28, ", Entry: ", l_price_52, ", StopLoss: ", l_price_60, ", TakeProfit: ", l_price_68);
l_symbol_28 = StringConcatenate(AddSymbolPrefix, l_symbol_28, AddSymbolSuffix);
GetMarketInfo(l_symbol_28);
l_price_52 = NormalizeDouble(l_price_52, g_digits_108);
l_price_60 = NormalizeDouble(l_price_60, g_digits_108);
l_price_68 = NormalizeDouble(l_price_68, g_digits_108);
ld_76 = g_ask_92 - g_bid_84;
ld_104 = PriceDifferencePips;
ld_112 = StopLossPips;
ld_120 = TakeProfitPips;
if (IsFiveDecBroker()) {
ld_104 = 10.0 * ld_104;
ld_112 = 10.0 * ld_112;
ld_120 = 10.0 * ld_120;
}
if(CloseOrdersIf_SpreadClose)CloseBySpread(ld_76);
if (ls_20 == "EXECUTED BUY" && ProcessPendingBuyExecution) ls_20 = "BUY";
else
if (ls_20 == "EXECUTED SELL" && ProcessPendingSellExecution) ls_20 = "SELL";
if (ReverseMode) {
if (UseSpreadsInReverseMode) {
if (ls_20 == "BUY_LIMIT" || ls_20 == "BUY_STOP") l_price_52 -= ld_76;
else
if (ls_20 == "SELL_LIMIT" || ls_20 == "SELL_STOP") l_price_52 += ld_76;
}
ls_20 = GetReversedOpType(ls_20);
if (IsNewOrderType(ls_20) || ls_20 == "MODIFY") {
if (Reverse_SL_TP_InReverseMode) {
//------------edit-------------
if(GetReversedOpType(ls_20)=="SELL"&&add_seprade_S L_TP_InReverseMode==true){ld_128 = l_price_60; if(l_price_68!=0)l_price_60 = l_price_68+ld_76; if(ld_128!=0)l_price_68 = ld_128+ld_76;}
if(GetReversedOpType(ls_20)=="BUY"&&add_seprade_SL _TP_InReverseMode==true){ld_128 = l_price_60; if(l_price_68!=0)l_price_60 = l_price_68-ld_76; if(ld_128!=0)l_price_68 = ld_128-ld_76;}
//----------end edit----------
if(add_seprade_SL_TP_InReverseMode==false)
{
ld_128 = l_price_60;
l_price_60 = l_price_68;
l_price_68 = ld_128;
}
} else {
l_price_60 = 0;
l_price_68 = 0;
}
}
}
if (ld_112 != 0.0) l_price_60 = GetRelativeStopLoss(l_price_52, ls_20, ld_112);
if (ld_120 != 0.0) l_price_68 = GetRelativeTakeProfit(l_price_52, ls_20, ld_120);
if (IsMarketOrderType(ls_20) && Ignore_SL_TP_ForMarketOrders) {
l_price_60 = 0;
l_price_68 = 0;
}
Print("StopLoss = ", l_price_60, " TakeProfit = ", l_price_68);
l_str_concat_36 = StringConcatenate(l_symbol_28, ", Entry: ", l_price_52, ", StopLoss: ", l_price_60, ", TakeProfit: ", l_price_68, " Comment: ", ls_44);
Print("Parsing...");
if (!ShouldProcessTask(ls_20, li_92, ls_44, l_str_concat_36)) DeleteFile();
else {
if (g_point_100 == 0.0) {
ProcessError();
g_count_312++;
CheckTries();
} else {
Print("Currency: ", l_symbol_28, "; Bid = ", g_bid_84, "; Ask = ", g_ask_92, "; Point = ", g_point_100, "; Spread = ", ld_76);
ld_136 = GetRiskPercent(ls_44);
//-----------------------------------------------------------------------
if (ld_136 != -1.0 && ls_20 != "MODIFY" && ls_20 != "DELETE") {
ld_152 = g_point_100;
if (IsFiveDecBroker()) {
ld_152 = 10.0 * ld_152;
ld_144 = AccountEquity() * (ld_136 / 10.0) / 100.0;
} else ld_144 = AccountEquity() * (ld_136 / 100.0);
ld_160 = GetOpTypePrice(l_price_52, ls_20);
ld_168 = MathAbs(ld_160 - l_price_60) / ld_152;
ld_176 = ld_168 * g_tickvalue_116;
if (ld_176 == 0.0) l_lots_84 = GetLotSize(l_lots_84, l_symbol_28);
else l_lots_84 = GetLotSize(ld_144 / ld_176, l_symbol_28);
Print("pipValue = ", g_tickvalue_116, "; dblPoints = ", ld_152, "; riskValue = ", ld_144, "; sellDeltaStop = ", ld_168, "; stopValue = ", ld_176, "; minLotSize = ", g_lotstep_124);
} else l_lots_84 = GetLotSize(l_lots_84 * GetLotMultiplierForSystem(ls_44), l_symbol_28);
Print("Lot Size = ", l_lots_84);
int MN;
if(UseMultiplierLotsByBalance)MN=NewBalance();
else MN=1;
//--------------------------------------------------------------------------
if (ls_20 == "SELL_LIMIT") {
if (l_price_52 <= g_bid_84 + ld_76) {
Print("It was SELL LIMIT order but price is higher than Entry so I change it to SELL");
Print("Price: ", g_bid_84, ", Entry: ", l_price_52);
ls_20 = "SELL";
} else {
if(ECN_Broker){SL=l_price_60;TP=l_price_68;l_price _60=0;l_price_68=0;}
if(l>MinLot&&l<MaxLot&&(LotsOK(l)&&LotsOKClosed(l) )||!ignoreSameLotOrders&&!IgnoreCustomLot||l!=Lots Ignored&&orderscnt()<MaxOrders&&l_lots_84*MN<=MaxA llowedLot&&ld_76<MaxSpread*g_point_100){
l_ticket_16 = OrderSend(l_symbol_28, OP_SELLLIMIT, l_lots_84*MN, l_price_52, 3, NormalizeDouble(l_price_60, g_digits_108), NormalizeDouble(l_price_68, g_digits_108), DoubleToStr(l_magic_12, 0), MagicNumber);
if(SL!=0||TP!=0&&ECN_Broker&&l_ticket_16>0){
while(!modifyticket&&triedN<NumberOfTries){
SL=MathMax(SL,l_price_52+(MarketInfo(Symbol(),MODE _STOPLEVEL)+triedN)*g_point_100);
TP=MathMin(TP,l_price_52-(MarketInfo(Symbol(),MODE_STOPLEVEL)+triedN)*g_poi nt_100);
modifyticket=OrderModify(l_ticket_16,OrderOpenPric e(),SL,TP,0);triedN++;
}
}
}
else l_ticket_16=1;
if (l_ticket_16 == -1) {
Print("Sorry, can not execute order, I will try later...");
ProcessError();
g_count_312++;
CheckTries();
return;
}
Print("Hey man, I did it! We did it! Woohooo! Order was executed.");
Alert("Sell limit order was executed: ", l_str_concat_36);
_PlaySound(OpenPendingOrderSound);
DeleteFile();
return;
}
}
if (ls_20 == "SELL_STOP") {
if (l_price_52 >= g_bid_84 - ld_76) {
Print("It was SELL STOP order but price is lower than Entry so I change it to SELL");
Print("Price: ", g_bid_84, ", Entry: ", l_price_52);
ls_20 = "SELL";
} else {
if(ECN_Broker){SL=l_price_60;TP=l_price_68;l_price _60=0;l_price_68=0;}
if(l>MinLot&&l<MaxLot&&(LotsOK(l)&&LotsOKClosed(l) )||!ignoreSameLotOrders&&!IgnoreCustomLot||l!=Lots Ignored&&orderscnt()<MaxOrders&&l_lots_84*MN<=MaxA llowedLot&&ld_76<MaxSpread*g_point_100){
l_ticket_16 = OrderSend(l_symbol_28, OP_SELLSTOP, l_lots_84*MN, l_price_52, 3, NormalizeDouble(l_price_60, g_digits_108), NormalizeDouble(l_price_68, g_digits_108), DoubleToStr(l_magic_12, 0), MagicNumber);
if(SL!=0||TP!=0&&ECN_Broker&&l_ticket_16>0){
while(!modifyticket&&triedN<NumberOfTries){
SL=MathMax(SL,l_price_52+(MarketInfo(Symbol(),MODE _STOPLEVEL)+triedN)*g_point_100);
TP=MathMin(TP,l_price_52-(MarketInfo(Symbol(),MODE_STOPLEVEL)+triedN)*g_poi nt_100);
modifyticket=OrderModify(l_ticket_16,OrderOpenPric e(),SL,TP,0);triedN++;
}
}
}
else l_ticket_16=1;
if (l_ticket_16 == -1) {
Print("Sorry, can not execute order, I will try later...");
ProcessError();
g_count_312++;
CheckTries();
return;
}
Print("Hey man, I did it! We did it! Woohooo! Order was executed.");
Alert("Sell stop order was executed: ", l_str_concat_36);
_PlaySound(OpenPendingOrderSound);
DeleteFile();
return;
}
}
if (ls_20 == "BUY_LIMIT") {
if (l_price_52 >= g_ask_92 - ld_76) {
Print("It was BUY LIMIT order but price is lower than Entry so I change it to BUY");
Print("Price: ", g_ask_92, ", Entry: ", l_price_52);
ls_20 = "BUY";
} else {
if(ECN_Broker){SL=l_price_60;TP=l_price_68;l_price _60=0;l_price_68=0;}
if(l>MinLot&&l<MaxLot&&(LotsOK(l)&&LotsOKClosed(l) )||!ignoreSameLotOrders&&!IgnoreCustomLot||l!=Lots Ignored&&orderscnt()<MaxOrders&&l_lots_84*MN<=MaxA llowedLot&&ld_76<MaxSpread*g_point_100){
l_ticket_16 = OrderSend(l_symbol_28, OP_BUYLIMIT, l_lots_84*MN, l_price_52, 3, NormalizeDouble(l_price_60, g_digits_108), NormalizeDouble(l_price_68, g_digits_108), DoubleToStr(l_magic_12, 0), MagicNumber);
if(SL!=0||TP!=0&&ECN_Broker&&l_ticket_16>0){
while(!modifyticket&&triedN<NumberOfTries){
SL=MathMin(SL,l_price_52-(MarketInfo(Symbol(),MODE_STOPLEVEL)+triedN)*g_poi nt_100);
TP=MathMax(TP,l_price_52+(MarketInfo(Symbol(),MODE _STOPLEVEL)+triedN)*g_point_100);
modifyticket=OrderModify(l_ticket_16,OrderOpenPric e(),SL,TP,0);triedN++;
}
}
}
else l_ticket_16=1;
if (l_ticket_16 == -1) {
Print("Sorry, can not execute order, I will try later...");
ProcessError();
g_count_312++;
CheckTries();
return;
}
Print("Hey man, I did it! We did it! Woohooo! Order is executed.");
Alert("Buy limit order was executed: ", l_str_concat_36);
_PlaySound(OpenPendingOrderSound);
DeleteFile();
return;
}
}
if (ls_20 == "BUY_STOP") {
if (l_price_52 <= g_ask_92 + ld_76) {
Print("It was BUY STOP order but price is higher than Entry so I change it to BUY");
Print("Price: ", g_ask_92, ", Entry: ", l_price_52);
ls_20 = "BUY";
} else {
if(ECN_Broker){SL=l_price_60;TP=l_price_68;l_price _60=0;l_price_68=0;}
if(l>MinLot&&l<MaxLot&&(LotsOK(l)&&LotsOKClosed(l) )||!ignoreSameLotOrders&&!IgnoreCustomLot||l!=Lots Ignored&&orderscnt()<MaxOrders&&l_lots_84*MN<=MaxA llowedLot&&ld_76<MaxSpread*g_point_100){
l_ticket_16 = OrderSend(l_symbol_28, OP_BUYSTOP, l_lots_84*MN, l_price_52, 3, NormalizeDouble(l_price_60, g_digits_108), NormalizeDouble(l_price_68, g_digits_108), DoubleToStr(l_magic_12, 0), MagicNumber);
if(SL!=0||TP!=0&&ECN_Broker&&l_ticket_16>0){
while(!modifyticket&&triedN<NumberOfTries){
SL=MathMin(SL,l_price_52-(MarketInfo(Symbol(),MODE_STOPLEVEL)+triedN)*g_poi nt_100);
TP=MathMax(TP,l_price_52+(MarketInfo(Symbol(),MODE _STOPLEVEL)+triedN)*g_point_100);
modifyticket=OrderModify(l_ticket_16,OrderOpenPric e(),SL,TP,0);triedN++;
}
}
}
else l_ticket_16=1;
if (l_ticket_16 == -1) {
Print("Sorry, can not execute order, I will try later...");
ProcessError();
g_count_312++;
CheckTries();
return;
}
Print("Hey man, I did it! We did it! Woohooo! Order was executed.");
DeleteFile();
return;
}
}
if (ls_20 == "SELL") {
if (MathAbs(l_price_52 - g_bid_84) / g_point_100 >= ld_104) {
Print("Sorry, but price is too far from requested entry point (price: ", DoubleToStr(g_bid_84, g_digits_108), ", entry: ", DoubleToStr(l_price_52, g_digits_108), ")");
DeleteFile();
} else {
if(hisacc(l_symbol_28)>0&&use_multi_after_lose==tr ue) {double mlot=hisacc(l_symbol_28)*multi_after_lose; l_lots_84=mlot;}
if(ECN_Broker){SL=l_price_60;TP=l_price_68;l_price _60=0;l_price_68=0;}
if(l>MinLot&&l<MaxLot&&(LotsOK(l)&&LotsOKClosed(l) )||!ignoreSameLotOrders&&!IgnoreCustomLot||l!=Lots Ignored&&orderscnt()<MaxOrders&&l_lots_84*MN<=MaxA llowedLot&&ld_76<MaxSpread*g_point_100) {
l_ticket_16 = OrderSend(l_symbol_28, OP_SELL, l_lots_84*MN, g_bid_84, 3, NormalizeDouble(l_price_60, g_digits_108), NormalizeDouble(l_price_68, g_digits_108), DoubleToStr(l_magic_12, 0), MagicNumber);
if(SL!=0||TP!=0&&ECN_Broker&&l_ticket_16>0){
while(!modifyticket&&triedN<NumberOfTries){
SL=MathMax(SL,g_bid_84+(MarketInfo(Symbol(),MODE_S TOPLEVEL)+triedN)*g_point_100);
TP=MathMin(TP,g_bid_84-(MarketInfo(Symbol(),MODE_STOPLEVEL)+triedN)*g_poi nt_100);
modifyticket=OrderModify(l_ticket_16,OrderOpenPric e(),SL,TP,0);triedN++;
}
}
}
else l_ticket_16=1;
if (l_ticket_16 == -1) {
Print("Sorry, can not execute order, I will try later...");
ProcessError();
g_count_312++;
CheckTries();
} else {
Print("Hey man, I did it! We did it! Woohooo! Order was executed.");
DeleteFile();
SetFixedSLTP(l_ticket_16, ls_20, l_symbol_28, ld_112, ld_120);
}
}
} else {
if (ls_20 == "BUY") {
if (MathAbs(l_price_52 - g_ask_92) / g_point_100 >= ld_104) {
Print("Sorry, but price is too far from requested entry point (price: ", DoubleToStr(g_ask_92, g_digits_108), ", entry: ", DoubleToStr(l_price_52, g_digits_108), ")");
DeleteFile();
} else {
if(hisacc(l_symbol_28)>0&&use_multi_after_lose==tr ue) { mlot=hisacc(l_symbol_28)*multi_after_lose; l_lots_84=mlot;}
if(ECN_Broker){SL=l_price_60;TP=l_price_68;l_price _60=0;l_price_68=0;}
if(l>MinLot&&l<MaxLot&&(LotsOK(l)&&LotsOKClosed(l) )||!ignoreSameLotOrders&&!IgnoreCustomLot||l!=Lots Ignored&&orderscnt()<MaxOrders&&l_lots_84*MN<=MaxA llowedLot&&ld_76<MaxSpread*g_point_100){
l_ticket_16 = OrderSend(l_symbol_28, OP_BUY, l_lots_84*MN, g_ask_92, 3, NormalizeDouble(l_price_60, g_digits_108), NormalizeDouble(l_price_68, g_digits_108), DoubleToStr(l_magic_12, 0), MagicNumber);
if(SL!=0||TP!=0&&ECN_Broker&&l_ticket_16>0){
while(!modifyticket&&triedN<NumberOfTries){
SL=MathMin(SL,g_ask_92-(MarketInfo(Symbol(),MODE_STOPLEVEL)+triedN)*g_poi nt_100);
TP=MathMax(TP,g_ask_92+(MarketInfo(Symbol(),MODE_S TOPLEVEL)+triedN)*g_point_100);
modifyticket=OrderModify(l_ticket_16,OrderOpenPric e(),SL,TP,0);triedN++;
}
}
}
else l_ticket_16=1;
if (l_ticket_16 == -1) {
Print("Sorry, can not execute order, I will try later...");
ProcessError();
g_count_312++;
CheckTries();
} else {
Print("Hey man, I did it! We did it! Woohooo! Order was executed.");
lastlot=l_lots_84;
DeleteFile();
SetFixedSLTP(l_ticket_16, ls_20, l_symbol_28, ld_112, ld_120);
}
}
} else {
if (ls_20 == "DELETE") {
Print("Delete, huh? Well I will try to find an order to delete...");
for (int l_pos_4 = 0; l_pos_4 < OrdersTotal(); l_pos_4++) {
if (OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES)) {
if (StrToInteger(OrderComment()) == l_magic_12) {
if (OrderType() == OP_SELL || OrderType() == OP_BUY) {
if (CloseOrder(OrderTicket()) == 1) {
Print("Hey man, I closed it, really.");
DeleteFile();
return;
}
Print("Sorry, can not close this order, will try later");
ProcessError();
g_count_312++;
CheckTries();
return;
}
if (OrderDelete(OrderTicket()) == 1) {
Print("Hey man, I deleted it, really.");
DeleteFile();
return;
}
Print("Sorry, can not delete this order, will try later");
ProcessError();
g_count_312++;
CheckTries();
return;
}
}
}
Print("Did not find any order to delete");
Print("Orders number: ", OrdersTotal());
for (l_pos_4 = 0; l_pos_4 < OrdersTotal(); l_pos_4++)
if (OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES)) Print(OrderSymbol(), ", ", OrderComment());
g_count_312++;
CheckTries2();
} else {
if (ls_20 == "MODIFY") {
Print("Modify huh? Well I will try to find some order to modify...");
for (l_pos_4 = 0; l_pos_4 < OrdersTotal(); l_pos_4++) {
if (OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES)) {
if (StrToInteger(OrderComment()) == l_magic_12) {
if (OrderModify(OrderTicket(), l_price_52, l_price_60, l_price_68, OrderExpiration()) == TRUE) {
Print("Hey man, I changed it, really.");
DeleteFile();
return;
}
Print("Sorry, can not modify this order, will try later");
ProcessError();
g_count_312++;
CheckTries();
return;
}
}
}
Print("Did not find any order to modify");
Print("Orders number: ", OrdersTotal());
for (l_pos_4 = 0; l_pos_4 < OrdersTotal(); l_pos_4++)
if (OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES)) Print(OrderSymbol(), ", ", OrderComment());
g_count_312++;
CheckTries2();
}
}
}
}
}
}
} else Print("No new task...");
}
///////////////////////////////////////////////