chuchu777: want my next position to contain either GBP or JPY. I’d want it to be USDCHF or AUDNZD.
- I assume you don't mean "either" but neither.
- What you are checking for is only symbols beginning with GBP or ending with JPY. So you will accept EURGBP.
- Since you are trying to open multiple symbols, how can you filter when CheckCurrentActiveSymbols only returns one string?
William, thanks for your reply. yes I meant neither! EURGBP is the only exception in this case and I will accept that. I am checking all pairs. The idea is
for the EA to reduce exposure to any single currency. Let's say EURUSD is currently active, when the EA is ready to open the next position it
would be AUDNZD, GBPJPY, NZDCHF or any of those combinations but not EURAUD, EURJPY etc which contains EUR.
- Please edit your (original) post and use the CODE
button (Alt-S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum
Messages Editor - Don't double post! You already had another thread open.
General rules and best pratices of the Forum. - General - MQL5 programming forum
while I kind of understand the concept of what you're saying, i am finding it hard to code it to practice. Can you help?
... int Comparison2 = StringFind(Symbol(),Comp2, 0 ); if(Comparison >= 0) { return true; } else if (Comparison2 >= 0 ) ...
Airat Safin:
Thanks, doesn't look like it's working.
As a variant of solution =>
step 1> concatenate symbols of all opened positions in one buffer string => string BufferString = "" ; int Length = StringConcatenate ( BufferString , BufferString , OpenedSymbol_1 , OpenedSymbol_2 , ... ) ; // in cycle of course or no more than 62 at once step 2> parse Symbol() string Currency_1 = StringSubstr ( Symbol() , 0 , 3 ) ; string Currency_2 = StringSubstr ( Symbol() , 3 , 3 ) ; step 3> search int Comparison = StringFind ( BufferString , Currency_1 , 0 ) ; int Comparison2 = StringFind ( BufferString , Currency_2 , 0 ) ; step 4> check if(Comparison >= 0) { return true; } else if (Comparison2 >= 0) { // Alert("Cannot place trade correlated pair"); return true; } return false;
Airat Safin:
As a variant of solution =>
Thanks, getting quite a few errors trying to code that, like object expected etc. Are you able to help?
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
if(Correlation_Enabled == false && IsCorrelated())return;
.
.
.
bool IsCorrelated()
{
string Comp = StringSubstr(CheckCurrentActiveSymbols(),0,3);
string Comp2 = StringSubstr(CheckCurrentActiveSymbols(),3,3);
int Comparison = StringFind(Symbol(),Comp,0);
int Comparison2 = StringFind(Symbol(),Comp2,3);
if(Comparison >= 0)
{
return true;
}
else if (Comparison2 >= 3)
{
// Alert("Cannot place trade correlated pair");
return true;
}
return false;
}