Recursive symbol checking
Recursive symbol checking
Loading saved threads...
Dylan Williams · External communityPost link
External question — Stack Overflow Stack Exchange
Author: Dylan Williams
Original post: https://stackoverflow.com/questions/69920815
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
I am getting an error that I am having problems fixing as recursion hasn't "sunk in" yet.
It is supposed to go through an array of symbols already placed by the Class OrderManager Object and check if the symbol passed in is already there or not, if it is not there it should allow the trade, otherwise it will block it (multiple orders on the same currency compounds risk)
[Error] '}' - not all control paths return a value.
I believe it is because of the retest portion not having a return value but again I'm still newish to making my own recursive functions. However it may also be because my base and test cases are wrong possibly?
P.S I added (SE) comments in places to clarify language specific things since it is so close to C++.
P.P.S Due to the compiler error, I have no clue if this meets MVRC. Sorry everyone.
bool OrderManager::Check_Risk(const string symbol, uint iter = 0) {
if((iter + 1) != ArraySize(m_symbols) &&
m_trade_restrict != LEVEL_LOW) // Index is one less than Size (SE if
// m_trade_restrict is set to LOW, it
// allows all trades so just break out)
{
if(OrderSelect(OrderManager::Get(m_orders[iter]),
SELECT_BY_TICKET)) // Check the current iterator position
// order (SE OrderSelect() sets an
// external variable in the terminal,
// sort of like an environment var)
{
string t_base = SymbolInfoString(
OrderSymbol(),
SYMBOL_CURRENCY_BASE); // Test base (SE function pulls apart
// the Symbol into two strings
// representing the currency to check
// against)
string t_profit =
SymbolInfoString(OrderSymbol(), SYMBOL_CURRENCY_PROFIT);
string c_base =
SymbolInfoString(symbol, SYMBOL_CURRENCY_BASE); // Current base
// (SE does the same as above but for the passed variable instead):
string c_profit = SymbolInfoString(symbol, SYMBOL_CURRENCY_PROFIT);
// Uses ENUM_LEVELS from Helpers.mqh (SE ENUM of 5 levels: Strict,
// High, Normal, Low, None in that order):
switch(m_trade_restrict) {
case LEVEL_STRICT: {
if(t_base == c_base || t_profit == c_profit) {
return false; // Restrictions won't allow doubling
// orders on any currency
} else
return Check_Risk(symbol, iter++);
};
case LEVEL_NORMAL: {
if(symbol == OrderSymbol()) {
return false; // Restrictions won't allow doubling
// orders on that curr pair
} else
return Check_Risk(symbol, iter++);
};
default: {
// TODO: Logging Manager
// Hardcoded constant global (SE set to LEVEL_NORMAL):
ENB_Trade_Restrictions(default_level);
return Check_Risk(symbol, iter);
}
}
}
} else {
return true;
}
}
Quote
Report
Dylan Williams · External communityPost link
External answer — Stack Overflow Stack Exchange
Author: Dylan Williams
Original post: https://stackoverflow.com/a/69921012
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
So, I must just have been staring at the code for too long but the problem was the
if(OrderSelect(...))
on
ln 7
did not have a return case if the order was not properly set in the terminal. I will need to polish this but the following code removes the error.
bool OrderManager::Check_Risk(const string symbol, uint iter=0)
{
if((iter + 1) != ArraySize(m_symbols) && m_trade_restrict != LEVEL_LOW) // Index is one less than Size
{
if(OrderSelect(OrderManager::Get(m_orders[iter]), SELECT_BY_TICKET)) //Check the current iterator position order
{
string t_base = SymbolInfoString(OrderSymbol(), SYMBOL_CURRENCY_BASE); //Test base
string t_profit = SymbolInfoString(OrderSymbol(), SYMBOL_CURRENCY_PROFIT);
string c_base = SymbolInfoString(symbol, SYMBOL_CURRENCY_BASE); //Current base
string c_profit = SymbolInfoString(symbol, SYMBOL_CURRENCY_PROFIT);
switch(m_trade_restrict) // Uses ENUM_LEVELS from Helpers.mqh
{
case LEVEL_STRICT :
{
if(t_base == c_base || t_profit == c_profit)
{
return false;
}
else return Check_Risk(symbol, ++iter);
};
case LEVEL_NORMAL :
{
if(symbol == OrderSymbol())
{
return false;
}
else return Check_Risk(symbol, ++iter);
};
default: {
// TODO: Logging Messages
ENB_Trade_Restrictions(default_level); //Hardcoded constant global
return Check_Risk(symbol, iter);
}
}
}
else {return Check_Risk(symbol, ++iter);}
}
else {return true;}
}
Quote
Report
Post Reply
Quoted from Forex.com.bd-Editorial External question — Stack Overflow Stack Exchange Author: Dylan Williams Source score (net votes, not local likes): -1 Original post: https://stackoverflow.com/questions/69920815 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I am getting an error that I am having problems fixing as recursion hasn't "sunk in" yet. It is supposed to go through an array of symbols already placed by the Class OrderManager Object and check if the symbol passed in is already there or not, if it is not there it should allow the trade, otherwise it will block it (multiple orders on the same currency compounds risk) [Error] '}' - not all control paths return a value. I believe it is because of the retest portion not having a return value but again I'm still newish to making my own recursive functions. However it may also be because my base and test cases are wrong possibly? P.S I added (SE) comments in places to clarify language specific things since it is so close to C++. P.P.S Due to the compiler error, I have no clue if this meets MVRC. Sorry everyone. bool OrderManager::Check_Risk(const string symbol, uint iter = 0) { if((iter + 1) != ArraySize(m_symbols) && m_trade_restrict != LEVEL_LOW) // Index is one less than Size (SE if // m_trade_restrict is set to LOW, it // allows all trades so just break out) { if(OrderSelect(OrderManager::Get(m_orders[iter]), SELECT_BY_TICKET)) // Check the current iterator position // order (SE OrderSelect() sets an // external variable in the terminal, // sort of like an environment var) { string t_base = SymbolInfoString( OrderSymbol(), SYMBOL_CURRENCY_BASE); // Test base (SE function pulls apart // the Symbol into two strings // representing the currency to check // against) string t_profit = SymbolInfoString(OrderSymbol(), SYMBOL_CURRENCY_PROFIT); string c_base = SymbolInfoString(symbol, SYMBOL_CURRENCY_BASE); // Current base // (SE does the same as above but for the passed variable instead): string c_profit = SymbolInfoString(symbol, SYMBOL_CURRENCY_PROFIT); // Uses ENUM_LEVELS from Helpers.mqh (SE ENUM of 5 levels: Strict, // High, Normal, Low, None in that order): switch(m_trade_restrict) { case LEVEL_STRICT: { if(t_base == c_base || t_profit == c_profit) { return false; // Restrictions won't allow doubling // orders on any currency } else return Check_Risk(symbol, iter++); }; case LEVEL_NORMAL: { if(symbol == OrderSymbol()) { return false; // Restrictions won't allow doubling // orders on that curr pair } else return Check_Risk(symbol, iter++); }; default: { // TODO: Logging Manager // Hardcoded constant global (SE set to LEVEL_NORMAL): ENB_Trade_Restrictions(default_level); return Check_Risk(symbol, iter); } } } } else { return true; } }
Checking account access…