I have an EA that trades breakouts. I run this on multiple pairs. The problem arises when two pairs with high correlation trades the same direction ( or opposite, if negative correlation ). That doubles my risk. So, I added a snippet in my EA that prevents opening a new trade if there is already an open position of a symbol that is highly correlated with the current symbol.
( this is what I tried ):
string strSymbol;
string HighCorrelationPairs[];
int OnInit() {
strSymbol = Symbol();
if ( strSymbol == "EURAUD" ) {
ArrayResize( HighCorrelationPairs, 1 );
string HighCorrelationPairs[1] = { "EURJPY" };
}
else if ( strSymbol == "EURJPY" ) {
ArrayResize( HighCorrelationPairs, 2 );
string HighCorrelationPairs[2] = { "EURAUD", "EURUSD" };
}
else if ( strSymbol == "EURUSD" ) {
ArrayResize( HighCorrelationPairs, 2 );
string HighCorrelationPairs[2] = { "EURJPY", "USDCHF" };
}
else if ( strSymbol == "GBPJPY" ) {
ArrayResize( HighCorrelationPairs, 1 );
string HighCorrelationPairs[1] = { "GBPUSD" };
}
else if ( strSymbol == "GBPUSD" ) {
ArrayResize( HighCorrelationPairs, 1 );
string HighCorrelationPairs[1] = { "GBPJPY" };
}
else if ( strSymbol == "USDCHF" ) {
ArrayResize( HighCorrelationPairs, 1 );
string HighCorrelationPairs[1] = { "EURUSD" };
}
else if ( strSymbol == "USDJPY" ) {
ArrayResize( HighCorrelationPairs, 1 );
string HighCorrelationPairs[1] = {};
}
else {
ArrayResize( HighCorrelationPairs, 1 );
string HighCorrelationPairs[1] = {};
}
}
void OnTick() { //--- Check Correlation and Number of Trades
for ( k = OrdersTotal() - 1; k >= 0; k-- ) {
if ( OrderSelect( k, SELECT_BY_POS, MODE_TRADES ) ) {
if ( OrderType() == OP_BUY
|| OrderType() == OP_SELL
) {
if ( OrderSymbol() == Symbol()
&& OrderMagicNumber() == MagicNumber
) {
return;
}
if ( TimeCurrent() - OrderOpenTime() <= 18000 ) {
for ( int i = 0;i < ArraySize( HighCorrelationPairs ); i++ ) {
if ( OrderSymbol() == HighCorrelationPairs[i] ) { return; }
}
}
}
}
}
}
Upon compiling, this is the warning/s that I got
variable 'HighCorrelationPairs' not used declaration of 'HighCorrelationPairs' hides global declaration at line 120
It's only a warning, not an error.