|
|
|
@@ -19,6 +19,10 @@
|
|
|
|
|
#define Ask SymbolInfoDouble(_symbol,SYMBOL_ASK)
|
|
|
|
|
#define Bid SymbolInfoDouble(_symbol,SYMBOL_BID)
|
|
|
|
|
|
|
|
|
|
bool suppressLogOutput = false;
|
|
|
|
|
|
|
|
|
|
void SuppressGlobalLogOutput() { suppressLogOutput = true; };
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#define _point SymbolInfoDouble(_symbol,SYMBOL_POINT)
|
|
|
|
@@ -49,6 +53,7 @@ class CTradingChecks
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
ENUM_TC_ERROR _err;
|
|
|
|
|
bool _suppressLogOutput;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
@@ -56,6 +61,7 @@ class CTradingChecks
|
|
|
|
|
~CTradingChecks();
|
|
|
|
|
|
|
|
|
|
string GetCheckErrorToString();
|
|
|
|
|
void SuppressLogOutput() { _suppressLogOutput = true; };
|
|
|
|
|
|
|
|
|
|
bool OkToOpenOrder(string _symbol,ENUM_ORDER_TYPE type, double lots, double entryPrice, double sl, double tp);
|
|
|
|
|
bool OkToModifyOrder(string _symbol,ulong ticket,double price, double sl, double tp);
|
|
|
|
@@ -67,6 +73,7 @@ class CTradingChecks
|
|
|
|
|
|
|
|
|
|
CTradingChecks::CTradingChecks(void)
|
|
|
|
|
{
|
|
|
|
|
suppressLogOutput = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CTradingChecks::~CTradingChecks(void)
|
|
|
|
@@ -226,15 +233,22 @@ bool CheckMoneyForTrade(string symb,double lots,ENUM_ORDER_TYPE type)
|
|
|
|
|
if(!OrderCalcMargin(type,symb,lots,price,margin))
|
|
|
|
|
{
|
|
|
|
|
//--- something went wrong, report and return false
|
|
|
|
|
Print("Error in ",__FUNCTION__," code=",GetLastError());
|
|
|
|
|
if(suppressLogOutput == false)
|
|
|
|
|
{
|
|
|
|
|
Print("Error in ",__FUNCTION__," code=",GetLastError());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return(false);
|
|
|
|
|
}
|
|
|
|
|
//--- if there are insufficient funds to perform the operation
|
|
|
|
|
if(margin>free_margin)
|
|
|
|
|
{
|
|
|
|
|
//--- report the error and return false
|
|
|
|
|
Print("Not enough money for ",EnumToString(type)," ",lots," ",symb," Error code=",GetLastError());
|
|
|
|
|
Print("Required margin:"+DoubleToString(margin,2)+"; free margin:"+DoubleToString(free_margin,2));
|
|
|
|
|
if(suppressLogOutput == false)
|
|
|
|
|
{
|
|
|
|
|
Print("Not enough money for ",EnumToString(type)," ",lots," ",symb," Error code=",GetLastError());
|
|
|
|
|
Print("Required margin:"+DoubleToString(margin,2)+"; free margin:"+DoubleToString(free_margin,2));
|
|
|
|
|
}
|
|
|
|
|
return(false);
|
|
|
|
|
}
|
|
|
|
|
//--- checking successful
|
|
|
|
@@ -248,7 +262,11 @@ bool CheckMoneyForTrade(string symb, double lots,int type)
|
|
|
|
|
if(free_margin<0)
|
|
|
|
|
{
|
|
|
|
|
string oper=(type==OP_BUY)? "Buy":"Sell";
|
|
|
|
|
Print("Not enough money for ", oper," ",lots, " ", symb, " Error code=",GetLastError());
|
|
|
|
|
if(suppressLogOutput == false)
|
|
|
|
|
{
|
|
|
|
|
Print("Not enough money for ", oper," ",lots, " ", symb, " Error code=",GetLastError());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return(false);
|
|
|
|
|
}
|
|
|
|
|
//--- checking successful
|
|
|
|
@@ -290,8 +308,11 @@ double PositionVolume(string symbol)
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//--- report a failure to select position
|
|
|
|
|
Print(__FUNCTION__," Failed to perform PositionSelect() for symbol ",
|
|
|
|
|
if(suppressLogOutput == false)
|
|
|
|
|
{
|
|
|
|
|
Print(__FUNCTION__," Failed to perform PositionSelect() for symbol ",
|
|
|
|
|
symbol," Error ",GetLastError());
|
|
|
|
|
}
|
|
|
|
|
return(-1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -359,8 +380,11 @@ bool CheckStopLoss_Takeprofit(string _symbol, ENUM_ORDER_TYPE type,double price,
|
|
|
|
|
int stops_level=(int)SymbolInfoInteger(_symbol,SYMBOL_TRADE_STOPS_LEVEL);
|
|
|
|
|
if(stops_level!=0)
|
|
|
|
|
{
|
|
|
|
|
PrintFormat("SYMBOL_TRADE_STOPS_LEVEL=%d: StopLoss and TakeProfit must"+
|
|
|
|
|
if(suppressLogOutput == false)
|
|
|
|
|
{
|
|
|
|
|
PrintFormat("SYMBOL_TRADE_STOPS_LEVEL=%d: StopLoss and TakeProfit must"+
|
|
|
|
|
" not be nearer than %d points from the closing price",stops_level,stops_level);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//---
|
|
|
|
|
bool SL_check=false,TP_check=false;
|
|
|
|
@@ -372,13 +396,13 @@ bool CheckStopLoss_Takeprofit(string _symbol, ENUM_ORDER_TYPE type,double price,
|
|
|
|
|
{
|
|
|
|
|
//--- check the StopLoss
|
|
|
|
|
SL_check= (SL==0) ? true : (Bid-SL>stops_level*_point);
|
|
|
|
|
if(!SL_check)
|
|
|
|
|
if(!SL_check && suppressLogOutput == false)
|
|
|
|
|
PrintFormat("For order %s StopLoss=%.5f must be less than %.5f"+
|
|
|
|
|
" (Bid=%.5f - SYMBOL_TRADE_STOPS_LEVEL=%d points)",
|
|
|
|
|
EnumToString(type),SL,Bid-stops_level*_point,Bid,stops_level);
|
|
|
|
|
//--- check the TakeProfit
|
|
|
|
|
TP_check= (TP==0) ? true : (TP-Bid>stops_level*_point);
|
|
|
|
|
if(!TP_check)
|
|
|
|
|
if(!TP_check && suppressLogOutput == false)
|
|
|
|
|
PrintFormat("For order %s TakeProfit=%.5f must be greater than %.5f"+
|
|
|
|
|
" (Bid=%.5f + SYMBOL_TRADE_STOPS_LEVEL=%d points)",
|
|
|
|
|
EnumToString(type),TP,Bid+stops_level*_point,Bid,stops_level);
|
|
|
|
@@ -390,13 +414,13 @@ bool CheckStopLoss_Takeprofit(string _symbol, ENUM_ORDER_TYPE type,double price,
|
|
|
|
|
{
|
|
|
|
|
//--- check the StopLoss
|
|
|
|
|
SL_check= (SL==0) ? true : (SL-Ask>stops_level*_point);
|
|
|
|
|
if(!SL_check)
|
|
|
|
|
if(!SL_check && suppressLogOutput == false)
|
|
|
|
|
PrintFormat("For order %s StopLoss=%.5f must be greater than %.5f"+
|
|
|
|
|
" (Ask=%.5f + SYMBOL_TRADE_STOPS_LEVEL=%d points)",
|
|
|
|
|
EnumToString(type),SL,Ask+stops_level*_point,Ask,stops_level);
|
|
|
|
|
//--- check the TakeProfit
|
|
|
|
|
TP_check= (TP==0) ? true : (Ask-TP>stops_level*_point);
|
|
|
|
|
if(!TP_check)
|
|
|
|
|
if(!TP_check && suppressLogOutput == false)
|
|
|
|
|
PrintFormat("For order %s TakeProfit=%.5f must be less than %.5f"+
|
|
|
|
|
" (Ask=%.5f - SYMBOL_TRADE_STOPS_LEVEL=%d points)",
|
|
|
|
|
EnumToString(type),TP,Ask-stops_level*_point,Ask,stops_level);
|
|
|
|
@@ -409,13 +433,13 @@ bool CheckStopLoss_Takeprofit(string _symbol, ENUM_ORDER_TYPE type,double price,
|
|
|
|
|
{
|
|
|
|
|
//--- check the StopLoss
|
|
|
|
|
SL_check= (SL==0) ? true : ((price-SL)>stops_level*_point);
|
|
|
|
|
if(!SL_check)
|
|
|
|
|
if(!SL_check && suppressLogOutput == false)
|
|
|
|
|
PrintFormat("For order %s StopLoss=%.5f must be less than %.5f"+
|
|
|
|
|
" (Open-StopLoss=%d points ==> SYMBOL_TRADE_STOPS_LEVEL=%d points)",
|
|
|
|
|
EnumToString(type),SL,price-stops_level*_point,(int)((price-SL)/_point),stops_level);
|
|
|
|
|
//--- check the TakeProfit
|
|
|
|
|
TP_check= (TP==0) ? true : ((TP-price)>stops_level*_point);
|
|
|
|
|
if(!TP_check)
|
|
|
|
|
if(!TP_check && suppressLogOutput == false)
|
|
|
|
|
PrintFormat("For order %s TakeProfit=%.5f must be greater than %.5f"+
|
|
|
|
|
" (TakeProfit-Open=%d points ==> SYMBOL_TRADE_STOPS_LEVEL=%d points)",
|
|
|
|
|
EnumToString(type),TP,price+stops_level*_point,(int)((TP-price)/_point),stops_level);
|
|
|
|
@@ -427,13 +451,13 @@ bool CheckStopLoss_Takeprofit(string _symbol, ENUM_ORDER_TYPE type,double price,
|
|
|
|
|
{
|
|
|
|
|
//--- check the StopLoss
|
|
|
|
|
SL_check= (SL==0) ? true : ((SL-price)>stops_level*_point);
|
|
|
|
|
if(!SL_check)
|
|
|
|
|
if(!SL_check && suppressLogOutput == false)
|
|
|
|
|
PrintFormat("For order %s StopLoss=%.5f must be greater than %.5f"+
|
|
|
|
|
" (StopLoss-Open=%d points ==> SYMBOL_TRADE_STOPS_LEVEL=%d points)",
|
|
|
|
|
EnumToString(type),SL,price+stops_level*_point,(int)((SL-price)/_point),stops_level);
|
|
|
|
|
//--- check the TakeProfit
|
|
|
|
|
TP_check= (TP==0) ? true : ((price-TP)>stops_level*_point);
|
|
|
|
|
if(!TP_check)
|
|
|
|
|
if(!TP_check && suppressLogOutput == false)
|
|
|
|
|
PrintFormat("For order %s TakeProfit=%.5f must be less than %.5f"+
|
|
|
|
|
" (Open-TakeProfit=%d points ==> SYMBOL_TRADE_STOPS_LEVEL=%d points)",
|
|
|
|
|
EnumToString(type),TP,price-stops_level*_point,(int)((price-TP)/_point),stops_level);
|
|
|
|
@@ -446,13 +470,13 @@ bool CheckStopLoss_Takeprofit(string _symbol, ENUM_ORDER_TYPE type,double price,
|
|
|
|
|
{
|
|
|
|
|
//--- check the StopLoss
|
|
|
|
|
SL_check= (SL==0) ? true : ((price-SL)>stops_level*_point);
|
|
|
|
|
if(!SL_check)
|
|
|
|
|
if(!SL_check && suppressLogOutput == false)
|
|
|
|
|
PrintFormat("For order %s StopLoss=%.5f must be less than %.5f"+
|
|
|
|
|
" (Open-StopLoss=%d points ==> SYMBOL_TRADE_STOPS_LEVEL=%d points)",
|
|
|
|
|
EnumToString(type),SL,price-stops_level*_point,(int)((price-SL)/_point),stops_level);
|
|
|
|
|
//--- check the TakeProfit
|
|
|
|
|
TP_check= (TP==0) ? true : ((TP-price)>stops_level*_point);
|
|
|
|
|
if(!TP_check)
|
|
|
|
|
if(!TP_check && suppressLogOutput == false)
|
|
|
|
|
PrintFormat("For order %s TakeProfit=%.5f must be greater than %.5f"+
|
|
|
|
|
" (TakeProfit-Open=%d points ==> SYMBOL_TRADE_STOPS_LEVEL=%d points)",
|
|
|
|
|
EnumToString(type),TP,price-stops_level*_point,(int)((TP-price)/_point),stops_level);
|
|
|
|
@@ -464,13 +488,13 @@ bool CheckStopLoss_Takeprofit(string _symbol, ENUM_ORDER_TYPE type,double price,
|
|
|
|
|
{
|
|
|
|
|
//--- check the StopLoss
|
|
|
|
|
SL_check= (SL==0) ? true : ((SL-price)>stops_level*_point);
|
|
|
|
|
if(!SL_check)
|
|
|
|
|
if(!SL_check && suppressLogOutput == false)
|
|
|
|
|
PrintFormat("For order %s StopLoss=%.5f must be greater than %.5f"+
|
|
|
|
|
" (StopLoss-Open=%d points ==> SYMBOL_TRADE_STOPS_LEVEL=%d points)",
|
|
|
|
|
EnumToString(type),SL,price+stops_level*_point,(int)((SL-price)/_point),stops_level);
|
|
|
|
|
//--- check the TakeProfit
|
|
|
|
|
TP_check= (TP==0) ? true : ((price-TP)>stops_level*_point);
|
|
|
|
|
if(!TP_check)
|
|
|
|
|
if(!TP_check && suppressLogOutput == false)
|
|
|
|
|
PrintFormat("For order %s TakeProfit=%.5f must be less than %.5f"+
|
|
|
|
|
" (Open-TakeProfit=%d points ==> SYMBOL_TRADE_STOPS_LEVEL=%d points)",
|
|
|
|
|
EnumToString(type),TP,price-stops_level*_point,(int)((price-TP)/_point),stops_level);
|
|
|
|
@@ -508,9 +532,14 @@ bool OrderModifyCheck(ulong ticket,double price,double sl,double tp)
|
|
|
|
|
return(true); // order can be modified
|
|
|
|
|
//--- there are no changes in the Open, StopLoss and Takeprofit levels
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//--- notify about the error
|
|
|
|
|
PrintFormat("Order #%d already has levels of Open=%.5f SL=%.5f TP=%.5f",
|
|
|
|
|
if(suppressLogOutput == false)
|
|
|
|
|
{
|
|
|
|
|
PrintFormat("Order #%d already has levels of Open=%.5f SL=%.5f TP=%.5f",
|
|
|
|
|
ticket,orderinfo.PriceOpen(),orderinfo.StopLoss(),orderinfo.TakeProfit());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//--- came to the end, no changes for the order
|
|
|
|
|
return(false); // no point in modifying
|
|
|
|
@@ -535,9 +564,14 @@ bool PositionModifyCheck(ulong ticket,double sl,double tp)
|
|
|
|
|
return(true); // position can be modified
|
|
|
|
|
//--- there are no changes in the StopLoss and Takeprofit levels
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//--- notify about the error
|
|
|
|
|
PrintFormat("Order #%d already has levels of Open=%.5f SL=%.5f TP=%.5f",
|
|
|
|
|
if(suppressLogOutput == false)
|
|
|
|
|
{
|
|
|
|
|
PrintFormat("Order #%d already has levels of Open=%.5f SL=%.5f TP=%.5f",
|
|
|
|
|
ticket,orderinfo.PriceOpen(),orderinfo.StopLoss(),orderinfo.TakeProfit());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//--- came to the end, no changes for the order
|
|
|
|
|
return(false); // no point in modifying
|
|
|
|
@@ -570,9 +604,14 @@ bool OrderModifyCheck(int ticket,double price,double sl,double tp)
|
|
|
|
|
return(true); // order can be modified
|
|
|
|
|
//--- there are no changes in the Open, StopLoss and Takeprofit levels
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//--- notify about the error
|
|
|
|
|
PrintFormat("Order #%d already has levels of Open=%.5f SL=%.5f TP=%.5f",
|
|
|
|
|
if(suppressLogOutput == false)
|
|
|
|
|
{
|
|
|
|
|
PrintFormat("Order #%d already has levels of Open=%.5f SL=%.5f TP=%.5f",
|
|
|
|
|
ticket,OrderOpenPrice(),OrderStopLoss(),OrderTakeProfit());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//--- came to the end, no changes for the order
|
|
|
|
|
return(false); // no point in modifying
|
|
|
|
@@ -590,8 +629,11 @@ bool CheckOrderForFREEZE_LEVEL(string _symbol, ulong ticket)
|
|
|
|
|
int freeze_level=(int)SymbolInfoInteger(_symbol,SYMBOL_TRADE_FREEZE_LEVEL);
|
|
|
|
|
if(freeze_level!=0)
|
|
|
|
|
{
|
|
|
|
|
PrintFormat("SYMBOL_TRADE_FREEZE_LEVEL=%d: Cannot modify order"+
|
|
|
|
|
if(suppressLogOutput == false)
|
|
|
|
|
{
|
|
|
|
|
PrintFormat("SYMBOL_TRADE_FREEZE_LEVEL=%d: Cannot modify order"+
|
|
|
|
|
" nearer than %d points from the activation price",freeze_level,freeze_level);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//--- select order for working
|
|
|
|
|
if(!OrderSelect(ticket))
|
|
|
|
@@ -614,7 +656,7 @@ bool CheckOrderForFREEZE_LEVEL(string _symbol, ulong ticket)
|
|
|
|
|
{
|
|
|
|
|
//--- check the distance from the opening price to the activation price
|
|
|
|
|
check=((Ask-price)>freeze_level*_point);
|
|
|
|
|
if(!check)
|
|
|
|
|
if(!check && suppressLogOutput == false)
|
|
|
|
|
PrintFormat("Order %s #%d cannot be modified: Ask-Open=%d points < SYMBOL_TRADE_FREEZE_LEVEL=%d points",
|
|
|
|
|
EnumToString(type),ticket,(int)((Ask-price)/_point),freeze_level);
|
|
|
|
|
return(check);
|
|
|
|
@@ -624,7 +666,7 @@ bool CheckOrderForFREEZE_LEVEL(string _symbol, ulong ticket)
|
|
|
|
|
{
|
|
|
|
|
//--- check the distance from the opening price to the activation price
|
|
|
|
|
check=((price-Bid)>freeze_level*_point);
|
|
|
|
|
if(!check)
|
|
|
|
|
if(!check && suppressLogOutput == false)
|
|
|
|
|
PrintFormat("Order %s #%d cannot be modified: Open-Bid=%d points < SYMBOL_TRADE_FREEZE_LEVEL=%d points",
|
|
|
|
|
EnumToString(type),ticket,(int)((price-Bid)/_point),freeze_level);
|
|
|
|
|
return(check);
|
|
|
|
@@ -635,7 +677,7 @@ bool CheckOrderForFREEZE_LEVEL(string _symbol, ulong ticket)
|
|
|
|
|
{
|
|
|
|
|
//--- check the distance from the opening price to the activation price
|
|
|
|
|
check=((price-Ask)>freeze_level*_point);
|
|
|
|
|
if(!check)
|
|
|
|
|
if(!check && suppressLogOutput == false)
|
|
|
|
|
PrintFormat("Order %s #%d cannot be modified: Ask-Open=%d points < SYMBOL_TRADE_FREEZE_LEVEL=%d points",
|
|
|
|
|
EnumToString(type),ticket,(int)((price-Ask)/_point),freeze_level);
|
|
|
|
|
return(check);
|
|
|
|
@@ -645,7 +687,7 @@ bool CheckOrderForFREEZE_LEVEL(string _symbol, ulong ticket)
|
|
|
|
|
{
|
|
|
|
|
//--- check the distance from the opening price to the activation price
|
|
|
|
|
check=((Bid-price)>freeze_level*_point);
|
|
|
|
|
if(!check)
|
|
|
|
|
if(!check && suppressLogOutput == false)
|
|
|
|
|
PrintFormat("Order %s #%d cannot be modified: Bid-Open=%d points < SYMBOL_TRADE_FREEZE_LEVEL=%d points",
|
|
|
|
|
EnumToString(type),ticket,(int)((Bid-price)/_point),freeze_level);
|
|
|
|
|
return(check);
|
|
|
|
@@ -663,7 +705,7 @@ bool CheckPositionForFREEZE_LEVEL(string _symbol, ulong ticket)
|
|
|
|
|
|
|
|
|
|
//--- get the SYMBOL_TRADE_FREEZE_LEVEL level
|
|
|
|
|
int freeze_level=(int)SymbolInfoInteger(_symbol,SYMBOL_TRADE_FREEZE_LEVEL);
|
|
|
|
|
if(freeze_level!=0)
|
|
|
|
|
if(freeze_level!=0 && suppressLogOutput == false)
|
|
|
|
|
{
|
|
|
|
|
PrintFormat("SYMBOL_TRADE_FREEZE_LEVEL=%d: Cannot modify order"+
|
|
|
|
|
" nearer than %d points from the activation price",freeze_level,freeze_level);
|
|
|
|
@@ -687,12 +729,12 @@ bool CheckPositionForFREEZE_LEVEL(string _symbol, ulong ticket)
|
|
|
|
|
case POSITION_TYPE_BUY:
|
|
|
|
|
{
|
|
|
|
|
SL_check=(sl == 0) ? true: (Bid-sl>freeze_level*_point);
|
|
|
|
|
if(!SL_check)
|
|
|
|
|
if(!SL_check && suppressLogOutput == false)
|
|
|
|
|
PrintFormat("Position %s #%d cannot be modified: Bid-StopLoss=%d points"+
|
|
|
|
|
" < SYMBOL_TRADE_FREEZE_LEVEL=%d points)",
|
|
|
|
|
EnumToString(pos_type),ticket,(int)((Bid-sl)/_point),freeze_level);
|
|
|
|
|
TP_check=(tp == 0) ? true: (tp-Bid>freeze_level*_point);
|
|
|
|
|
if(!TP_check)
|
|
|
|
|
if(!TP_check && suppressLogOutput == false)
|
|
|
|
|
PrintFormat("Position %s #%d cannot be modified: TakeProfit-Bid=%d points"+
|
|
|
|
|
" < SYMBOL_TRADE_FREEZE_LEVEL=%d points)",
|
|
|
|
|
EnumToString(pos_type),ticket,(int)((tp-Bid)/_point),freeze_level);
|
|
|
|
@@ -704,12 +746,12 @@ bool CheckPositionForFREEZE_LEVEL(string _symbol, ulong ticket)
|
|
|
|
|
case POSITION_TYPE_SELL:
|
|
|
|
|
{
|
|
|
|
|
SL_check=(sl == 0) ? true: (sl-Ask>freeze_level*_point);
|
|
|
|
|
if(!SL_check)
|
|
|
|
|
if(!SL_check && suppressLogOutput == false)
|
|
|
|
|
PrintFormat("Position %s cannot be modified: StopLoss-Ask=%d points"+
|
|
|
|
|
" < SYMBOL_TRADE_FREEZE_LEVEL=%d points)",
|
|
|
|
|
EnumToString(pos_type),(int)((sl-Ask)/_point),freeze_level);
|
|
|
|
|
TP_check=(tp == 0) ? true: (Ask-tp>freeze_level*_point);
|
|
|
|
|
if(!TP_check)
|
|
|
|
|
if(!TP_check && suppressLogOutput == false)
|
|
|
|
|
PrintFormat("Position %s cannot be modified: Ask-TakeProfit=%d points"+
|
|
|
|
|
" < SYMBOL_TRADE_FREEZE_LEVEL=%d points)",
|
|
|
|
|
EnumToString(pos_type),(int)((Ask-tp)/_point),freeze_level);
|
|
|
|
@@ -726,7 +768,7 @@ bool CheckOrderForFREEZE_LEVEL(string _symbol,int ticket)
|
|
|
|
|
{
|
|
|
|
|
//--- get the SYMBOL_TRADE_FREEZE_LEVEL level
|
|
|
|
|
int freeze_level=(int)SymbolInfoInteger(_symbol,SYMBOL_TRADE_FREEZE_LEVEL);
|
|
|
|
|
if(freeze_level!=0)
|
|
|
|
|
if(freeze_level!=0 && suppressLogOutput == false)
|
|
|
|
|
{
|
|
|
|
|
PrintFormat("SYMBOL_TRADE_FREEZE_LEVEL=%d: Cannot modify order"+
|
|
|
|
|
" nearer than %d points from the activation price",freeze_level,freeze_level);
|
|
|
|
@@ -752,7 +794,7 @@ bool CheckOrderForFREEZE_LEVEL(string _symbol,int ticket)
|
|
|
|
|
{
|
|
|
|
|
//--- check the distance from the opening price to the activation price
|
|
|
|
|
check=((Ask-price)>freeze_level*_point);
|
|
|
|
|
if(!check)
|
|
|
|
|
if(!check && suppressLogOutput == false)
|
|
|
|
|
PrintFormat("Order OP_BUYLIMIT #%d cannot be modified: Ask-Open=%d points < SYMBOL_TRADE_FREEZE_LEVEL=%d points",
|
|
|
|
|
ticket,(int)((Ask-price)/_point),freeze_level);
|
|
|
|
|
return(check);
|
|
|
|
@@ -762,7 +804,7 @@ bool CheckOrderForFREEZE_LEVEL(string _symbol,int ticket)
|
|
|
|
|
{
|
|
|
|
|
//--- check the distance from the opening price to the activation price
|
|
|
|
|
check=((price-Bid)>freeze_level*_point);
|
|
|
|
|
if(!check)
|
|
|
|
|
if(!check && suppressLogOutput == false)
|
|
|
|
|
PrintFormat("Order OP_SELLLIMIT #%d cannot be modified: Open-Bid=%d points < SYMBOL_TRADE_FREEZE_LEVEL=%d points",
|
|
|
|
|
ticket,(int)((price-Bid)/_point),freeze_level);
|
|
|
|
|
return(check);
|
|
|
|
@@ -773,7 +815,7 @@ bool CheckOrderForFREEZE_LEVEL(string _symbol,int ticket)
|
|
|
|
|
{
|
|
|
|
|
//--- check the distance from the opening price to the activation price
|
|
|
|
|
check=((price-Ask)>freeze_level*_point);
|
|
|
|
|
if(!check)
|
|
|
|
|
if(!check && suppressLogOutput == false)
|
|
|
|
|
PrintFormat("Order OP_BUYSTOP #%d cannot be modified: Ask-Open=%d points < SYMBOL_TRADE_FREEZE_LEVEL=%d points",
|
|
|
|
|
ticket,(int)((price-Ask)/_point),freeze_level);
|
|
|
|
|
return(check);
|
|
|
|
@@ -783,7 +825,7 @@ bool CheckOrderForFREEZE_LEVEL(string _symbol,int ticket)
|
|
|
|
|
{
|
|
|
|
|
//--- check the distance from the opening price to the activation price
|
|
|
|
|
check=((Bid-price)>freeze_level*_point);
|
|
|
|
|
if(!check)
|
|
|
|
|
if(!check && suppressLogOutput == false)
|
|
|
|
|
PrintFormat("Order OP_SELLSTOP #%d cannot be modified: Bid-Open=%d points < SYMBOL_TRADE_FREEZE_LEVEL=%d points",
|
|
|
|
|
ticket,(int)((Bid-price)/_point),freeze_level);
|
|
|
|
|
return(check);
|
|
|
|
@@ -794,12 +836,12 @@ bool CheckOrderForFREEZE_LEVEL(string _symbol,int ticket)
|
|
|
|
|
{
|
|
|
|
|
//--- check TakeProfit distance to the activation price
|
|
|
|
|
bool TP_check=(tp == 0) ? true: (tp-Bid>freeze_level*_point);
|
|
|
|
|
if(!TP_check)
|
|
|
|
|
if(!TP_check && suppressLogOutput == false)
|
|
|
|
|
PrintFormat("Order OP_BUY %d cannot be modified: TakeProfit-Bid=%d points < SYMBOL_TRADE_FREEZE_LEVEL=%d points",
|
|
|
|
|
ticket,(int)((tp-Bid)/_point),freeze_level);
|
|
|
|
|
//--- check TakeProfit distance to the activation price
|
|
|
|
|
bool SL_check=(sl == 0) ? true: (Bid-sl>freeze_level*_point);
|
|
|
|
|
if(!SL_check)
|
|
|
|
|
if(!SL_check && suppressLogOutput == false)
|
|
|
|
|
PrintFormat("Order OP_BUY %d cannot be modified: TakeProfit-Bid=%d points < SYMBOL_TRADE_FREEZE_LEVEL=%d points",
|
|
|
|
|
ticket,(int)((Bid-sl)/_point),freeze_level);
|
|
|
|
|
return(SL_check&&TP_check);
|
|
|
|
@@ -810,12 +852,12 @@ bool CheckOrderForFREEZE_LEVEL(string _symbol,int ticket)
|
|
|
|
|
{
|
|
|
|
|
//--- check TakeProfit distance to the activation price
|
|
|
|
|
bool TP_check=(tp == 0) ? true: (Ask-tp>freeze_level*_point);
|
|
|
|
|
if(!TP_check)
|
|
|
|
|
if(!TP_check && suppressLogOutput == false)
|
|
|
|
|
PrintFormat("Order OP_SELL %d cannot be modified: Ask-TakeProfit=%d points < SYMBOL_TRADE_FREEZE_LEVEL=%d points",
|
|
|
|
|
ticket,(int)((Ask-tp)/_point),freeze_level);
|
|
|
|
|
//--- check TakeProfit distance to the activation price
|
|
|
|
|
bool SL_check=(sl == 0) ? true: (sl-Ask>freeze_level*_point);
|
|
|
|
|
if(!SL_check)
|
|
|
|
|
if(!SL_check && suppressLogOutput == false)
|
|
|
|
|
PrintFormat("Order OP_BUY %d cannot be modified: TakeProfit-Bid=%d points < SYMBOL_TRADE_FREEZE_LEVEL=%d points",
|
|
|
|
|
ticket,(int)((sl-Ask)/_point),freeze_level);
|
|
|
|
|
return(SL_check&&TP_check);
|
|
|
|
@@ -847,7 +889,7 @@ bool CheckPendingOrderEntryChange(string _symbol, ulong ticket, double newEntryP
|
|
|
|
|
{
|
|
|
|
|
//--- check the distance from the opening price to the activation price
|
|
|
|
|
check= (newEntryPrice < Ask);
|
|
|
|
|
if(!check)
|
|
|
|
|
if(!check && suppressLogOutput == false)
|
|
|
|
|
PrintFormat("Order %s #%d cannot be modified",
|
|
|
|
|
EnumToString(type),ticket);
|
|
|
|
|
return(check);
|
|
|
|
@@ -857,7 +899,7 @@ bool CheckPendingOrderEntryChange(string _symbol, ulong ticket, double newEntryP
|
|
|
|
|
{
|
|
|
|
|
//--- check the distance from the opening price to the activation price
|
|
|
|
|
check=(newEntryPrice > Bid);
|
|
|
|
|
if(!check)
|
|
|
|
|
if(!check && suppressLogOutput == false)
|
|
|
|
|
PrintFormat("Order %s #%d cannot be modified",
|
|
|
|
|
EnumToString(type),ticket);
|
|
|
|
|
return(check);
|
|
|
|
@@ -868,7 +910,7 @@ bool CheckPendingOrderEntryChange(string _symbol, ulong ticket, double newEntryP
|
|
|
|
|
{
|
|
|
|
|
//--- check the distance from the opening price to the activation price
|
|
|
|
|
check=(newEntryPrice > Ask);
|
|
|
|
|
if(!check)
|
|
|
|
|
if(!check && suppressLogOutput == false)
|
|
|
|
|
PrintFormat("Order %s #%d cannot be modified",
|
|
|
|
|
EnumToString(type),ticket);
|
|
|
|
|
return(check);
|
|
|
|
@@ -878,7 +920,7 @@ bool CheckPendingOrderEntryChange(string _symbol, ulong ticket, double newEntryP
|
|
|
|
|
{
|
|
|
|
|
//--- check the distance from the opening price to the activation price
|
|
|
|
|
check=(newEntryPrice < Bid);
|
|
|
|
|
if(!check)
|
|
|
|
|
if(!check && suppressLogOutput == false)
|
|
|
|
|
PrintFormat("Order %s #%d cannot be modified",
|
|
|
|
|
EnumToString(type),ticket);
|
|
|
|
|
return(check);
|
|
|
|
|