النتائج 1 إلى 15 من 17
الموضوع: استفسار بسيط برمجي
- 18-11-2013, 01:12 PM #1
استفسار بسيط برمجي
عندي كد التالي و اريد ان يتم استخدام المضاعفات بعد اغلاق الصفقه على الربحو و ليس المضاعفات بعد الاغلاق على الخساره
كود PHP:else {
if(hisacc(l_symbol_28)>0&&use_multi_after_lose==true) {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;}
ياريت تغيير لي الكد كلمطلوب بارك الله فيك
كد الاعلى هو قبل التغيير تماما
- 18-11-2013, 10:06 PM #2
فين المبرمجين؟
- 18-11-2013, 11:31 PM #3
تغيير العلامة لايكفي لابد من فهم باقي الشروط المختزلة في الكود
if(hisacc(l_symbol_28)>0
- 19-11-2013, 12:07 AM #4
تفضل باقي الشروط:
كود PHP:extern bool use_multi_after_lose=false;
}
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++;
}
}
}
l_symbol_28 = StringConcatenate(AddSymbolPrefix, l_symbol_28, AddSymbolSuffix);آخر تعديل بواسطة amazing ، 19-11-2013 الساعة 12:15 AM
- 19-11-2013, 12:56 AM #5
رد:استفسار بسيط برمجي
الكود الذي ارفقت يوجد فيه الشرط
كود PHP:hisacc(l_symbol_28)
اذا كنت تحتاج لكود مضاعفة في حالة الخسارة او كود مضاعفة في حالة الربح سأرفقه لك .
- 19-11-2013, 01:07 AM #6
رد:استفسار بسيط برمجي
اخي جميل تم ارفاق الكد و قيمة المخزونات بارك الله
extern int MagicNumber=12345;
int g_count_312 = 0;
int gi_unused_316 = 0;
int g_datetime_320 = 0;
int gi_324 = 0;
static double acc=0;
static double lastlot=0;
int WaitForTradeContext() {
for (int l_count_0 = 0; l_count_0 < 300 && !IsTradeAllowed(); l_count_0++) Sleep(100);
if (l_count_0 > 0) Print("Waited for trade context for ", NormalizeDouble(l_count_0 / 10, 1), " seconds");
if (l_count_0 == 300) {
gs_unused_76 = "Trade is not allowed";
return (0);
}
return (1);
}
void CloseBySpread(int spread)
{
for(int i=OrdersTotal();i>=0;i--){
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol()&&OrderMagicNumber()==Ma gicNumber){
if(OrderType()==OP_BUY){
if(OrderTakeProfit()-Bid<=spread)OrderClose(OrderTicket(),OrderLots(),B id,3);
}
if(OrderType()==OP_SELL){
if(Ask-OrderTakeProfit()<=spread)OrderClose(OrderTicket() ,OrderLots(),Ask,3);
}
}
}
}
int CloseOrder(int a_ticket_0) {
color l_color_4;
double l_price_8;
Print("Trying to close order ", a_ticket_0);
if (!WaitForTradeContext()) return (0);
if (!OrderSelect(a_ticket_0, SELECT_BY_TICKET, MODE_TRADES)) {
Print("Can not locate order info");
return (0);
}
GetMarketInfo(OrderSymbol());
if (OrderType() == OP_BUY) {
l_color_4 = Yellow;
l_price_8 = g_bid_84;
} else {
l_color_4 = Red;
l_price_8 = g_ask_92;
}
if (OrderClose(a_ticket_0, OrderLots(), l_price_8, 5, l_color_4)) {
Print("Successful");
return (1);
}
string l_text_16 = ErrorDescription(GetLastError());
Print("Failed: ", l_text_16);
string l_str_concat_24 = StringConcatenate("Text", TimeCurrent(), MathRand());
ObjectCreate(l_str_concat_24, OBJ_TEXT, 0, TimeCurrent(), Bid);
ObjectSetText(l_str_concat_24, l_text_16, 8, "Arial", White);
return (0);
}
//+------------------------------------------------------------------+
//| FUNCTION DEFINITIONS deinitialization function |
//+------------------------------------------------------------------+
void GetMarketInfo(string a_symbol_0) {
g_point_100 = MarketInfo(a_symbol_0, MODE_POINT);
g_digits_108 = MarketInfo(a_symbol_0, MODE_DIGITS);
g_bid_84 = MarketInfo(a_symbol_0, MODE_BID);
g_ask_92 = MarketInfo(a_symbol_0, MODE_ASK);
g_tickvalue_116 = MarketInfo(a_symbol_0, MODE_TICKVALUE);
g_lotstep_124 = MarketInfo(a_symbol_0, MODE_LOTSTEP);
g_minlot_132 = MarketInfo(a_symbol_0, MODE_MINLOT);
}
int SplitString(string as_0, string as_8, string &asa_16[], int ai_20 = 0) {
int li_24;
int li_28;
int li_32;
if (StringFind(as_0, as_8) < 0) {
ArrayResize(asa_16, 1);
asa_16[0] = as_0;
} else {
li_24 = 0;
li_28 = 0;
li_32 = 0;
while (li_28 > -1) {
li_32++;
li_28 = StringFind(as_0, as_8, li_24);
ArrayResize(asa_16, li_32);
if (li_28 > -1) {
if (li_28 - li_24 > 0) asa_16[li_32 - 1] = StringSubstr(as_0, li_24, li_28 - li_24);
} else asa_16[li_32 - 1] = StringSubstr(as_0, li_24, 0);
li_24 = li_28 + 1;
}
}
if (ai_20 == 0 || ai_20 == ArraySize(asa_16)) return (1);
Print("ERROR - size of parsed string not expected.", 1);
return (0);
}
//////////////////////////////////////////////////
int init() {
Print("I am initialized!");
g_count_312 = 0;
g_datetime_320 = TimeLocal();
return (0);
}
int deinit() {
return (0);
}
bool IsFiveDecBroker() {
return (g_digits_108 == 3.0 || g_digits_108 == 5.0);
}
void DeleteFile() {
FileDelete("CurrentTask.dat");
g_count_312 = 0;
}
void CheckTries() {
if (g_count_312 >= NumberOfTries) {
DeleteFile();
Print("Well, I tried to execute this order ", NumberOfTries, " times but... So I deleted it.");
}
}
void CheckTries2() {
if (g_count_312 >= NumberOfTries) {
DeleteFile();
Print("Well, I tried to execute this order 2 times but... So I deleted it.");
}
}
//////////////////////////////////////////////////
void _PlaySound(string as_0) {
if (as_0 != "") PlaySound(as_0);
}
string GetReversedOpType(string as_0) {
string ls_ret_8;
if (as_0 == "BUY") ls_ret_8 = "SELL";
else {
if (as_0 == "SELL") ls_ret_8 = "BUY";
else {
if (as_0 == "BUY_STOP") ls_ret_8 = "SELL_LIMIT";
else {
if (as_0 == "BUY_LIMIT") ls_ret_8 = "SELL_STOP";
else {
if (as_0 == "SELL_STOP") ls_ret_8 = "BUY_LIMIT";
else {
if (as_0 == "SELL_LIMIT") ls_ret_8 = "BUY_STOP";
else ls_ret_8 = as_0;
}
}
}
}
}
return (ls_ret_8);
}double GetNormalizedLotSize(double ad_0, int ai_8) { double ld_ret_12 = NormalizeDouble(ad_0, ai_8);
Print("LotSize should have", ai_8, "digits, so changing to", ld_ret_12);
return (ld_ret_12);
}
//////////////////////////////////////////////////
double NormalizeLotSize(double ad_0, string as_unused_8) {
double ld_ret_16 = ad_0;
switch (g_lotstep_124) {
case 0.0:
ld_ret_16 = GetNormalizedLotSize(ad_0, 0);
break;
case 0.1:
ld_ret_16 = GetNormalizedLotSize(ad_0, 1);
break;
case 0.01:
ld_ret_16 = GetNormalizedLotSize(ad_0, 2);
break;
case 0.001:
ld_ret_16 = GetNormalizedLotSize(ad_0, 3);
}
return (ld_ret_16);
}
//////////////////////////////////////////////////
double GetLotSize(double ad_0, string as_8) {
double ld_ret_16;
if (UseFixedLot) ld_ret_16 = LotSize;
else {
ld_ret_16 = NormalizeLotSize(LotMultiplier * ad_0, as_8);
if (ld_ret_16 + gi_324 < g_minlot_132) {
ld_ret_16 = g_minlot_132;
Print("Lot must be more or equal: ", g_minlot_132, " changed to ", ld_ret_16);
}
}
return (ld_ret_16);
}
int IsNewOrderType(string as_0) {
return (IsPendingOrderType(as_0) || IsMarketOrderType(as_0));
}
bool IsMarketOrderType(string as_0) {
return (as_0 == "SELL" || as_0 == "BUY");
}
bool IsPendingOrderType(string as_0) {
return (as_0 == "SELL_LIMIT" || as_0 == "SELL_STOP" || as_0 == "BUY_LIMIT" || as_0 == "BUY_STOP");
}
void DoErrorSpecificAction(int ai_0) {
switch (ai_0) {
case 135:
RefreshRates();
return;
case 136:
RefreshRates();
return;
return;
}
}
//////////////////////////////////////////////////
void ProcessError() {
int l_error_0 = GetLastError();
DoErrorSpecificAction(l_error_0);
Print("Got error #", l_error_0, " (", ErrorDescription(l_error_0), ")");
}
int IsCommentAllowed(string as_0) {
string lsa_8[];
string ls_24;
if (StringLen(AllowedComments) == 0) return (1);
SplitString(AllowedComments, ";", lsa_8);
int l_arr_size_12 = ArraySize(lsa_8);
bool li_ret_16 = FALSE;
for (int l_index_20 = 0; l_index_20 < l_arr_size_12; l_index_20++) {
if (as_0 == lsa_8[l_index_20]) {
li_ret_16 = TRUE;
break;
}
}
if (as_0 == "") ls_24 = "<unknown system>";
else ls_24 = as_0;
if (!li_ret_16) Print("Skipping order for ", ls_24);
else Print("Processing order for ", ls_24);
return (li_ret_16);
}
int IsOrderExpired(int ai_0) {
double addedhour;
if(DayOfWeek()==1&&ai_0<iTime(Symbol(),1440,0))add edhour=(iTime(Symbol(),1440,0)-ai_0)/60/60;
if (TimeCurrent() - ai_0 > 3600 * (ExpirationHours+addedhour)) {
Print("Order expired. Time difference: ", NormalizeDouble((TimeCurrent() - ai_0) / 60 / 60, 2), " hours");
return (1);
}
return (0);
}
int ShouldBeOpenedManually(string as_0, string as_8) {
if (ManualOpenOrders && IsNewOrderType(as_0)) {
Print("Manual order open mode");
Alert("New order: ", as_0, ", ", as_8);
return (1);
}
return (0);
}
int IsPendingExecution(string as_0) {
if (as_0 == "EXECUTED SELL" && !ProcessPendingSellExecution || as_0 == "EXECUTED BUY" && !ProcessPendingBuyExecution) {
Print("Pending order was executed");
return (1);
}
return (0);
}
int ShouldProcessTask(string as_0, int ai_8, string as_12, string as_20) {
if (as_0 != "DELETE" && as_0 != "MODIFY")
if (!IsCommentAllowed(as_12) || IsOrderExpired(ai_8) || ShouldBeOpenedManually(as_0, as_20) || IsPendingExecution(as_0)) return (0);
return (1);
}
string StringReplace(string as_0, string as_8, int ai_16) {
int li_20 = 0;
for (string ls_ret_24 = as_0; li_20 != -1; ls_ret_24 = StringSetChar(ls_ret_24, li_20, ai_16)) li_20 = StringFind(ls_ret_24, as_8, li_20);
return (ls_ret_24);
}
//////////////////////////////////////////////////
double GetLotMultiplierForSystem(string as_0) {
string lsa_8[];
string ls_20;
string ls_28;
string ls_36;
int li_44;
SplitString(SystemSpecificLotMultiplier, ";", 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, "; Lot Multiplier: ", ls_36);
if (as_0 == ls_28) return (StrToDouble(ls_36));
}
return (1.0);
}
int ReadTaskFile(int &ai_0, string &as_4, string &as_12, string &as_20, double &ad_28, double &ad_36, double &ad_44, double &ad_52, int &ai_60) {
int l_file_64 = FileOpen("CurrentTask.dat", FILE_CSV, ';');
if (l_file_64 >= 1) {
ai_0 = FileReadNumber(l_file_64);
as_4 = FileReadString(l_file_64);
as_12 = FileReadString(l_file_64);
ad_28 = FileReadNumber(l_file_64);
ad_36 = FileReadNumber(l_file_64);
ad_44 = FileReadNumber(l_file_64);
ad_52 = FileReadNumber(l_file_64);
ai_60 = FileReadNumber(l_file_64);
as_20 = FileReadString(l_file_64);
FileClose(l_file_64);
}
return (l_file_64);
}//////////////////////////////////////////////////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...");
}
///////////////////////////////////////////////double CalculateRelativeTakeProfit(double ad_0, string as_8, double ad_16) { if (IsLong(as_8)) return (AddPipsToPrice(ad_16, ad_0));
return (AddPipsToPrice(-ad_16, ad_0));
}
double CalculateRelativeStopLoss(double ad_0, string as_8, double ad_16) {
if (IsLong(as_8)) return (AddPipsToPrice(-ad_16, ad_0));
return (AddPipsToPrice(ad_16, ad_0));
}
double GetOpTypePrice(double ad_0, string as_8) {
if (IsMarketOrderType(as_8)) return (GetMarketPriceByOrderType(as_8));
return (ad_0);
}
double GetRelativeStopLoss(double ad_0, string as_8, double ad_16) {
return (CalculateRelativeStopLoss(GetOpTypePrice(ad_0, as_8), as_8, ad_16));
}
double GetRelativeTakeProfit(double ad_0, string as_8, double ad_16) {
if (IsMarketOrderType(as_8)) return (CalculateRelativeTakeProfit(GetMarketPriceByOrder Type(as_8), as_8, ad_16));
if (IsPendingOrderType(as_8)) return (CalculateRelativeTakeProfit(ad_0, as_8, ad_16));
return (0.0);
}
double AddPipsToPrice(int ai_0, double ad_4) {
double ld_12 = ai_0 * g_point_100;
return (ad_4 + ld_12);
}
bool IsLong(string as_0) {
return (as_0 == "BUY" || as_0 == "BUY_LIMIT" || as_0 == "BUY_STOP");
}
//--------------------------Edite-------------------
double hisacc(string sim)
{
int i,hstTotal=OrdersHistoryTotal();
double pro,lot;
for(i=0;i<hstTotal;i++)
{
//---- check selection result
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==fals e)
{
Print("Access to history failed with error (",GetLastError(),")");
break;
}
// some work with order
if(OrderSymbol()==sim&&OrderMagicNumber()==MagicNu mber)
{
pro=OrderProfit();
lot=OrderLots();
}
}
if(pro<0) return(lot);
else return(0);
}
bool LotsOK(double lots){
for(int i=0;i<=OrdersTotal();i++){
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol()&&OrderMagicNumber()==Ma gicNumber){
if(OrderLots()==lots)return(false);
}
}
return(true);
}
bool LotsOKClosed(double lots){
for(int i=OrdersHistoryTotal();i>=0;i--){
OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
if(OrderSymbol()==Symbol()&&OrderMagicNumber()==Ma gicNumber){
if(OrderLots()==lots)return(false);
}
}
return(true);
}
//---------------------------------------------------
//+------------------------------------------------------------------+
//| FUNCTION DEFINITIONS Start function |
//+------------------------------------------------------------------+
int start() {
while (!IsStopped()) {
if (TimeLocal() - g_datetime_320 > 900) {
Print("I am working...");
g_datetime_320 = TimeLocal();
}
ProcessTasks(SourceDir, RegKey);
while (TaskExists(SourceDir) == 1) {
ProcessTask();
if (TaskExists(SourceDir) == 1) return (0);
ProcessTasks(SourceDir, RegKey);
}
if (TimeDelaySec < 0.001) return (0);
Sleep(MathRound(1000.0 * TimeDelaySec));
}
return (0);
}
int NewBalance()
{
double deposite= AccountBalance()- AccountProfit();
return (AccountBalance()/deposite);
}
int orderscnt(){
int cnt=0;
for(int i =0;i<=OrdersTotal();i++){
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol() &&OrderMagicNumber()== MagicNumber){
cnt++;
}
}
return(cnt);
}
آخر تعديل بواسطة amazing ، 19-11-2013 الساعة 01:14 AM
- 19-11-2013, 01:18 AM #7
رد:استفسار بسيط برمجي
ليه ماترفق الملف بصيفة mq4 بدل الزحمة .
- 19-11-2013, 01:37 AM #8
رد:استفسار بسيط برمجي
اسف حاولت عشرات المرات لرفع الملف و لكن هناك خطاء بيظهر عندي لا ادري هل المشكله من المنتدى ام من النت بتاعي
آخر تعديل بواسطة amazing ، 19-11-2013 الساعة 01:40 AM
- 19-11-2013, 01:41 AM #9
رد:استفسار بسيط برمجي
ياريت التعديل على الكد مباشرتا
كود PHP:bool TaskExists(string a0); int ProcessTasks(string a0, string a1); bool CheckKey(string a0);#import
extern bool ECN_Broker=false;extern bool UseMultiplierLotsByBalance = false; extern int MaxOrders=1; extern double MaxSpread=100; string gs_unused_76 = "";double g_bid_84;double g_ask_92;double g_point_100;double g_digits_108;double g_tickvalue_116;double g_lotstep_124;double g_minlot_132;extern double MaxAllowedLot=100;extern double MinLot=0;extern double MaxLot=10;extern bool CloseOrdersIf_SpreadClose=false;extern bool ignoreSameLotOrders=true;extern bool IgnoreCustomLot=false;extern double LotsIgnored=0.1;extern string SourceDir = "<MT4 source folder>\\Experts\\Files";extern int PriceDifferencePips = 15;extern int ExpirationHours = 1;extern int NumberOfTries = 10;extern bool UseFixedLot = FALSE;extern double LotSize = 0.1;extern bool use_multi_after_lose=false;extern double multi_after_lose=2;extern double LotMultiplier = 1.0;extern double TimeDelaySec = 0.0;extern bool ManualOpenOrders = FALSE;extern string OpenOrderSound = "OpenOrderSound.wav";extern string CloseOrderSound = "CloseOrderSound.wav";extern string OpenPendingOrderSound = "OpenPendingOrderSound.wav";extern string ModifyOrderSound = "ModifyOrderSound.wav";extern string Copyright = "www.nano.com";extern string AddSymbolPrefix = "";extern string AddSymbolSuffix = "";extern bool ReverseMode = FALSE;extern bool Reverse_SL_TP_InReverseMode = FALSE;extern bool add_seprade_SL_TP_InReverseMode=False;extern bool UseSpreadsInReverseMode = FALSE;extern bool Ignore_SL_TP_ForMarketOrders = FALSE;extern bool ProcessPendingBuyExecution = FALSE;extern bool ProcessPendingSellExecution = FALSE;extern int StopLossPips = 0;extern int TakeProfitPips = 0;extern string AllowedComments;extern string RiskPercentages;extern string SystemSpecificLotMultiplier;extern string RegKey = "UNREGISTERED";
extern int MagicNumber=12345;
int g_count_312 = 0;int gi_unused_316 = 0;int g_datetime_320 = 0;int gi_324 = 0;static double acc=0;static double lastlot=0;int WaitForTradeContext() { for (int l_count_0 = 0; l_count_0 < 300 && !IsTradeAllowed(); l_count_0++) Sleep(100); if (l_count_0 > 0) Print("Waited for trade context for ", NormalizeDouble(l_count_0 / 10, 1), " seconds"); if (l_count_0 == 300) { gs_unused_76 = "Trade is not allowed"; return (0); } return (1);}void CloseBySpread(int spread){for(int i=OrdersTotal();i>=0;i--){OrderSelect(i,SELECT_BY_POS,MODE_TRADES);if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber){if(OrderType()==OP_BUY){if(OrderTakeProfit()-Bid<=spread)OrderClose(OrderTicket(),OrderLots(),Bid,3);}if(OrderType()==OP_SELL){if(Ask-OrderTakeProfit()<=spread)OrderClose(OrderTicket(),OrderLots(),Ask,3); } }}}
int CloseOrder(int a_ticket_0) { color l_color_4; double l_price_8; Print("Trying to close order ", a_ticket_0); if (!WaitForTradeContext()) return (0); if (!OrderSelect(a_ticket_0, SELECT_BY_TICKET, MODE_TRADES)) { Print("Can not locate order info"); return (0); } GetMarketInfo(OrderSymbol()); if (OrderType() == OP_BUY) { l_color_4 = Yellow; l_price_8 = g_bid_84; } else { l_color_4 = Red; l_price_8 = g_ask_92; } if (OrderClose(a_ticket_0, OrderLots(), l_price_8, 5, l_color_4)) { Print("Successful"); return (1); } string l_text_16 = ErrorDescription(GetLastError()); Print("Failed: ", l_text_16); string l_str_concat_24 = StringConcatenate("Text", TimeCurrent(), MathRand()); ObjectCreate(l_str_concat_24, OBJ_TEXT, 0, TimeCurrent(), Bid); ObjectSetText(l_str_concat_24, l_text_16, 8, "Arial", White); return (0);}
//+------------------------------------------------------------------+ //| FUNCTION DEFINITIONS deinitialization function | //+------------------------------------------------------------------+void GetMarketInfo(string a_symbol_0) { g_point_100 = MarketInfo(a_symbol_0, MODE_POINT); g_digits_108 = MarketInfo(a_symbol_0, MODE_DIGITS); g_bid_84 = MarketInfo(a_symbol_0, MODE_BID); g_ask_92 = MarketInfo(a_symbol_0, MODE_ASK); g_tickvalue_116 = MarketInfo(a_symbol_0, MODE_TICKVALUE); g_lotstep_124 = MarketInfo(a_symbol_0, MODE_LOTSTEP); g_minlot_132 = MarketInfo(a_symbol_0, MODE_MINLOT);}
int SplitString(string as_0, string as_8, string &asa_16[], int ai_20 = 0) { int li_24; int li_28; int li_32; if (StringFind(as_0, as_8) < 0) { ArrayResize(asa_16, 1); asa_16[0] = as_0; } else { li_24 = 0; li_28 = 0; li_32 = 0; while (li_28 > -1) { li_32++; li_28 = StringFind(as_0, as_8, li_24); ArrayResize(asa_16, li_32); if (li_28 > -1) { if (li_28 - li_24 > 0) asa_16[li_32 - 1] = StringSubstr(as_0, li_24, li_28 - li_24); } else asa_16[li_32 - 1] = StringSubstr(as_0, li_24, 0); li_24 = li_28 + 1; } } if (ai_20 == 0 || ai_20 == ArraySize(asa_16)) return (1); Print("ERROR - size of parsed string not expected.", 1); return (0);}//////////////////////////////////////////////////int init() { Print("I am initialized!"); g_count_312 = 0; g_datetime_320 = TimeLocal(); return (0);}
int deinit() { return (0);}
bool IsFiveDecBroker() { return (g_digits_108 == 3.0 || g_digits_108 == 5.0);}
void DeleteFile() { FileDelete("CurrentTask.dat"); g_count_312 = 0;}
void CheckTries() { if (g_count_312 >= NumberOfTries) { DeleteFile(); Print("Well, I tried to execute this order ", NumberOfTries, " times but... So I deleted it."); }}
void CheckTries2() { if (g_count_312 >= NumberOfTries) { DeleteFile(); Print("Well, I tried to execute this order 2 times but... So I deleted it."); }}
//////////////////////////////////////////////////void _PlaySound(string as_0) { if (as_0 != "") PlaySound(as_0);}
string GetReversedOpType(string as_0) { string ls_ret_8; if (as_0 == "BUY") ls_ret_8 = "SELL"; else { if (as_0 == "SELL") ls_ret_8 = "BUY"; else { if (as_0 == "BUY_STOP") ls_ret_8 = "SELL_LIMIT"; else { if (as_0 == "BUY_LIMIT") ls_ret_8 = "SELL_STOP"; else { if (as_0 == "SELL_STOP") ls_ret_8 = "BUY_LIMIT"; else { if (as_0 == "SELL_LIMIT") ls_ret_8 = "BUY_STOP"; else ls_ret_8 = as_0; } } } } } return (ls_ret_8);}
double GetNormalizedLotSize(double ad_0, int ai_8) { double ld_ret_12 = NormalizeDouble(ad_0, ai_8); Print("LotSize should have", ai_8, "digits, so changing to", ld_ret_12); return (ld_ret_12);}//////////////////////////////////////////////////double NormalizeLotSize(double ad_0, string as_unused_8) { double ld_ret_16 = ad_0; switch (g_lotstep_124) { case 0.0: ld_ret_16 = GetNormalizedLotSize(ad_0, 0); break; case 0.1: ld_ret_16 = GetNormalizedLotSize(ad_0, 1); break; case 0.01: ld_ret_16 = GetNormalizedLotSize(ad_0, 2); break; case 0.001: ld_ret_16 = GetNormalizedLotSize(ad_0, 3); } return (ld_ret_16);}//////////////////////////////////////////////////double GetLotSize(double ad_0, string as_8) { double ld_ret_16; if (UseFixedLot) ld_ret_16 = LotSize; else { ld_ret_16 = NormalizeLotSize(LotMultiplier * ad_0, as_8); if (ld_ret_16 + gi_324 < g_minlot_132) { ld_ret_16 = g_minlot_132; Print("Lot must be more or equal: ", g_minlot_132, " changed to ", ld_ret_16); } } return (ld_ret_16);}
int IsNewOrderType(string as_0) { return (IsPendingOrderType(as_0) || IsMarketOrderType(as_0));}
bool IsMarketOrderType(string as_0) { return (as_0 == "SELL" || as_0 == "BUY");}
bool IsPendingOrderType(string as_0) { return (as_0 == "SELL_LIMIT" || as_0 == "SELL_STOP" || as_0 == "BUY_LIMIT" || as_0 == "BUY_STOP");}
void DoErrorSpecificAction(int ai_0) { switch (ai_0) { case 135: RefreshRates(); return; case 136: RefreshRates(); return; return; }}//////////////////////////////////////////////////void ProcessError() { int l_error_0 = GetLastError(); DoErrorSpecificAction(l_error_0); Print("Got error #", l_error_0, " (", ErrorDescription(l_error_0), ")");}
int IsCommentAllowed(string as_0) { string lsa_8[]; string ls_24; if (StringLen(AllowedComments) == 0) return (1); SplitString(AllowedComments, ";", lsa_8); int l_arr_size_12 = ArraySize(lsa_8); bool li_ret_16 = FALSE; for (int l_index_20 = 0; l_index_20 < l_arr_size_12; l_index_20++) { if (as_0 == lsa_8[l_index_20]) { li_ret_16 = TRUE; break; } } if (as_0 == "") ls_24 = "<unknown system>"; else ls_24 = as_0; if (!li_ret_16) Print("Skipping order for ", ls_24); else Print("Processing order for ", ls_24); return (li_ret_16);}
int IsOrderExpired(int ai_0) { double addedhour; if(DayOfWeek()==1&&ai_0<iTime(Symbol(),1440,0))addedhour=(iTime(Symbol(),1440,0)-ai_0)/60/60; if (TimeCurrent() - ai_0 > 3600 * (ExpirationHours+addedhour)) { Print("Order expired. Time difference: ", NormalizeDouble((TimeCurrent() - ai_0) / 60 / 60, 2), " hours"); return (1); } return (0);}
int ShouldBeOpenedManually(string as_0, string as_8) { if (ManualOpenOrders && IsNewOrderType(as_0)) { Print("Manual order open mode"); Alert("New order: ", as_0, ", ", as_8); return (1); } return (0);}
int IsPendingExecution(string as_0) { if (as_0 == "EXECUTED SELL" && !ProcessPendingSellExecution || as_0 == "EXECUTED BUY" && !ProcessPendingBuyExecution) { Print("Pending order was executed"); return (1); } return (0);}
int ShouldProcessTask(string as_0, int ai_8, string as_12, string as_20) { if (as_0 != "DELETE" && as_0 != "MODIFY") if (!IsCommentAllowed(as_12) || IsOrderExpired(ai_8) || ShouldBeOpenedManually(as_0, as_20) || IsPendingExecution(as_0)) return (0); return (1);}
string StringReplace(string as_0, string as_8, int ai_16) { int li_20 = 0; for (string ls_ret_24 = as_0; li_20 != -1; ls_ret_24 = StringSetChar(ls_ret_24, li_20, ai_16)) li_20 = StringFind(ls_ret_24, as_8, li_20); return (ls_ret_24);}//////////////////////////////////////////////////double GetLotMultiplierForSystem(string as_0) { string lsa_8[]; string ls_20; string ls_28; string ls_36; int li_44; SplitString(SystemSpecificLotMultiplier, ";", 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, "; Lot Multiplier: ", ls_36); if (as_0 == ls_28) return (StrToDouble(ls_36)); } return (1.0);}
int ReadTaskFile(int &ai_0, string &as_4, string &as_12, string &as_20, double &ad_28, double &ad_36, double &ad_44, double &ad_52, int &ai_60) { int l_file_64 = FileOpen("CurrentTask.dat", FILE_CSV, ';'); if (l_file_64 >= 1) { ai_0 = FileReadNumber(l_file_64); as_4 = FileReadString(l_file_64); as_12 = FileReadString(l_file_64); ad_28 = FileReadNumber(l_file_64); ad_36 = FileReadNumber(l_file_64); ad_44 = FileReadNumber(l_file_64); ad_52 = FileReadNumber(l_file_64); ai_60 = FileReadNumber(l_file_64); as_20 = FileReadString(l_file_64); FileClose(l_file_64); } return (l_file_64);}//////////////////////////////////////////////////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_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;} 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!=LotsIgnored&&orderscnt()<MaxOrders&&l_lots_84*MN<=MaxAllowedLot&&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_point_100); modifyticket=OrderModify(l_ticket_16,OrderOpenPrice(),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!=LotsIgnored&&orderscnt()<MaxOrders&&l_lots_84*MN<=MaxAllowedLot&&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_point_100); modifyticket=OrderModify(l_ticket_16,OrderOpenPrice(),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!=LotsIgnored&&orderscnt()<MaxOrders&&l_lots_84*MN<=MaxAllowedLot&&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_point_100); TP=MathMax(TP,l_price_52+(MarketInfo(Symbol(),MODE_STOPLEVEL)+triedN)*g_point_100); modifyticket=OrderModify(l_ticket_16,OrderOpenPrice(),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!=LotsIgnored&&orderscnt()<MaxOrders&&l_lots_84*MN<=MaxAllowedLot&&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_point_100); TP=MathMax(TP,l_price_52+(MarketInfo(Symbol(),MODE_STOPLEVEL)+triedN)*g_point_100); modifyticket=OrderModify(l_ticket_16,OrderOpenPrice(),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==true) {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!=LotsIgnored&&orderscnt()<MaxOrders&&l_lots_84*MN<=MaxAllowedLot&&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_STOPLEVEL)+triedN)*g_point_100); TP=MathMin(TP,g_bid_84-(MarketInfo(Symbol(),MODE_STOPLEVEL)+triedN)*g_point_100); modifyticket=OrderModify(l_ticket_16,OrderOpenPrice(),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==true) { 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!=LotsIgnored&&orderscnt()<MaxOrders&&l_lots_84*MN<=MaxAllowedLot&&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_point_100); TP=MathMax(TP,g_ask_92+(MarketInfo(Symbol(),MODE_STOPLEVEL)+triedN)*g_point_100); modifyticket=OrderModify(l_ticket_16,OrderOpenPrice(),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...");}//////////////////////////////////////////////////double CalculateRelativeTakeProfit(double ad_0, string as_8, double ad_16) { if (IsLong(as_8)) return (AddPipsToPrice(ad_16, ad_0)); return (AddPipsToPrice(-ad_16, ad_0));}
double CalculateRelativeStopLoss(double ad_0, string as_8, double ad_16) { if (IsLong(as_8)) return (AddPipsToPrice(-ad_16, ad_0)); return (AddPipsToPrice(ad_16, ad_0));}
double GetOpTypePrice(double ad_0, string as_8) { if (IsMarketOrderType(as_8)) return (GetMarketPriceByOrderType(as_8)); return (ad_0);}
double GetRelativeStopLoss(double ad_0, string as_8, double ad_16) { return (CalculateRelativeStopLoss(GetOpTypePrice(ad_0, as_8), as_8, ad_16));}
double GetRelativeTakeProfit(double ad_0, string as_8, double ad_16) { if (IsMarketOrderType(as_8)) return (CalculateRelativeTakeProfit(GetMarketPriceByOrderType(as_8), as_8, ad_16)); if (IsPendingOrderType(as_8)) return (CalculateRelativeTakeProfit(ad_0, as_8, ad_16)); return (0.0);}
double AddPipsToPrice(int ai_0, double ad_4) { double ld_12 = ai_0 * g_point_100; return (ad_4 + ld_12);}
bool IsLong(string as_0) { return (as_0 == "BUY" || as_0 == "BUY_LIMIT" || as_0 == "BUY_STOP");}
//--------------------------Edite-------------------double hisacc(string sim){ int i,hstTotal=OrdersHistoryTotal(); double pro,lot; for(i=0;i<hstTotal;i++) { //---- check selection result if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) { Print("Access to history failed with error (",GetLastError(),")"); break; } // some work with order if(OrderSymbol()==sim&&OrderMagicNumber()==MagicNumber) { pro=OrderProfit(); lot=OrderLots(); } }if(pro<0) return(lot);else return(0);}bool LotsOK(double lots){for(int i=0;i<=OrdersTotal();i++){OrderSelect(i,SELECT_BY_POS,MODE_TRADES);if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber){if(OrderLots()==lots)return(false); } }return(true);}bool LotsOKClosed(double lots){for(int i=OrdersHistoryTotal();i>=0;i--){OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber){if(OrderLots()==lots)return(false); } }return(true);}//--------------------------------------------------- //+------------------------------------------------------------------+ //| FUNCTION DEFINITIONS Start function | //+------------------------------------------------------------------+int start() { while (!IsStopped()) { if (TimeLocal() - g_datetime_320 > 900) { Print("I am working..."); g_datetime_320 = TimeLocal(); } ProcessTasks(SourceDir, RegKey); while (TaskExists(SourceDir) == 1) { ProcessTask(); if (TaskExists(SourceDir) == 1) return (0); ProcessTasks(SourceDir, RegKey); } if (TimeDelaySec < 0.001) return (0); Sleep(MathRound(1000.0 * TimeDelaySec)); } return (0);}
int NewBalance() { double deposite= AccountBalance()- AccountProfit(); return (AccountBalance()/deposite); }
int orderscnt(){ int cnt=0; for(int i =0;i<=OrdersTotal();i++){ OrderSelect(i,SELECT_BY_POS,MODE_TRADES); if(OrderSymbol()==Symbol() &&OrderMagicNumber()== MagicNumber){ cnt++; } } return(cnt); }
- 19-11-2013, 01:42 AM #10
رد:استفسار بسيط برمجي
الظاهر نسيت ترفق الملف
عموما لاحظت في الكود فراغ بداخل نفس الكلمة مثلا Ma gicNumber و tr ue وغيرها كثير وهذا بسبب كسر كود محمي ، وأستغرب اصلا انه يكون شغال .
- 19-11-2013, 01:49 AM #11
رد:استفسار بسيط برمجي
الكود مكسور وهذه الرسالة وعند عمل Compiler تأتي هذه الرسالة
2;228;;;using of decompiled source code is prohibited
- 19-11-2013, 02:06 AM #12
استاذ جميل حضرتك بتعمل كومبايلر على نسخة 509 لميتاتريدر و لكن انا اعمل على النسخه رقم 419 و هو يعمل زي الفل
انا عاوز فقط تعديل بسيط و هو في طريقة المضاعفات يعني المضاعفات تتم بعد اغلاق الصفقه على الربح و لكن الطريقه الموجوده حاليا هي المضاعفت تتم بعد اغلاق الصفقه على الخساره ياريت تعدل عليه و ترفق الكد و انا سوف اضيفه في الاكسبيرت و اعمل له كومبايلر ان لم تستطيع
- 19-11-2013, 02:11 AM #13
رد:استفسار بسيط برمجي
استاذ جميل انا جزعت من كثرة محاولتي لارفاق الملف على المنتدى فيظهر خطاء عندي ياريت ترسل لي ايميلك لارسل لك الكد و تعدل لي الكد بارك الله فيك
ايضا ارجوا ان ترفق لي الكد المضاعات في حالة الربحآخر تعديل بواسطة amazing ، 19-11-2013 الساعة 02:21 AM
- 19-11-2013, 02:17 AM #14
رد:استفسار بسيط برمجي
تفضل تم التعديل .
- 19-11-2013, 02:30 AM #15
هناك خطاء
using of decompiled source code is prohibited
متابع