Traded currencies filter

 

Hi there, I've been woring around this idea for some time and I still haven't found the way to make it work properly.

The idea a is quite simple, on a multicurrency advisor, let's say 28 fx pairs and 8 traded currencies filter (do not trade) those pairs with an already traded currency.

For this I tried by using a 28 pair symbol loop, an 8 pair currency loop and the stringfind to check around the currencies inside each pair, but sadly still haven't found a clever way to make it work.

Thus I've finally decided to post this coding issue in the forum for if anybody could share an example.

I think it's not necessary to post any failed attempt because unuseful.

Thank you in advance.

 
Please show your attempt if you need coding help.
 
Alain Verleyen #:
Please show your attempt if you need coding help.

This could be one from several:

      for(int q=0;q<TotalCurrencies;q++){
         string QName=Currencies[q];//Currencies.
         if(STraded||StringFind(SName,QName,0)<0){
            if(LotSize>=minLot&&Spread<=MaxSpread){
               if(BuySignal==true&&LongPos<1){ // Trade LONG.
                  if(!trade.PositionOpen(SName,ORDER_TYPE_BUY,LotSize,Ask,0,0,CustomComment)){
                     Print("PositionOpen error ",trade.ResultRetcode());
                     return;
                     }
                  }
...

The problem here is that it always find a traded one or viceversa, so it doesn't make difference if I make stringfind <0 or >=0.

 

Well, although I still got no relevant results it seems to be yet solved (by myself).

Must say that getting no answers is quite disgusting but I'll post my solution anyway for the community.


First we check into the symbols traded from a string function for traded currencies:

string QTraded(){
   string Currencies[],QTraded;
   ushort sep=StringGetCharacter(",",0);
   StringSplit(CurrencyList,sep,Currencies);
   int TotalCurrencies=ArraySize(Currencies);
   for(int s=0;s<SymbolsTotal(true);s++){
      string SName=SymbolName(s,true);
      for(int p=0;p<PositionsTotal();p++){
         ulong Ticket=PositionGetTicket(p);
         for(int q=0;q<TotalCurrencies;q++){
            string QName=Currencies[q];//Currencies.
            if(PositionGetString(POSITION_SYMBOL)==SName){
               if(StringFind(SName,QName,0)>=0){QTraded=QName;} // I call found traded currencies QTraded.
               }
            }
         }
      }
   return(QTraded);}


Then, into the symbol loop of a multicurrency advisor we just need to exclude QTraded() from the symbols which are about to open a new position:

if(StringFind(SName,QTraded(),0)<0){ // QTraded() isn't into the symbol to be traded, so the algorithm can continue checking its conditions to open a new position.
   if(LotSize>=minLot&&Spread<=MaxSpread){
      if(BuySignal==true&&LongPos<1){ // Trade LONG.
         if(!trade.PositionOpen(SName,ORDER_TYPE_BUY,LotSize,Ask,0,TP,CustomComment)){
            Print("PositionOpen error ",trade.ResultRetcode());
            return;
            }
         }


And that's all, this way we can reduce risk from trading several pairs and currencies at the same time