cm scripts Triangles

Author: Copyright 2021, cmillion@narod.ru
Miscellaneous
Uses files from the file systemIt writes information to file
0 Views
0 Downloads
0 Favorites
cm scripts Triangles
ÿþ//+------------------------------------------------------------------+

#property copyright "Copyright 2021, cmillion@narod.ru"

#property link      "http://www.cmillion.ru"

string ver ="Triangles 1.0";

#property version     "1.0"

#property strict

#property description "!:@8?B =0E>48B 2A5 2>7<>6=K5 B@5C3>;L=8:8 20;NB=KE ?0@ 2 >17>@5 @K=:0"

#property description "The script finds all possible triangles of currency pairs in the market overview"



void OnStart()

{

   string SYMBOLS1[];

   string SYMBOLS2[];

   string SYMBOLS3[];

   int SYMBOLtotal=SymbolsTotal(true);

   int n=0;

   for(int i=0;i<SYMBOLtotal-2 && !IsStopped();i++)    

   {

      string SYMBOL1=SymbolName(i,true);

      //if (SymbolInfoInteger(SYMBOL1,SYMBOL_TRADE_CALC_MODE)!=SYMBOL_CALC_MODE_FOREX) continue;

      string SYMBOL1_BASE=SymbolInfoString(SYMBOL1,SYMBOL_CURRENCY_BASE);     

      string SYMBOL1_PROFIT=SymbolInfoString(SYMBOL1,SYMBOL_CURRENCY_PROFIT);

      if(SYMBOL1_BASE==SYMBOL1_PROFIT) continue;

      for(int j=0;j<SYMBOLtotal-1 && !IsStopped();j++)

      {

         string SYMBOL2=SymbolName(j,true);

         //if(SymbolInfoInteger(SYMBOL2,SYMBOL_TRADE_CALC_MODE)!=SYMBOL_CALC_MODE_FOREX) continue;

         string SYMBOL2_BASE=SymbolInfoString(SYMBOL2,SYMBOL_CURRENCY_BASE);

         string SYMBOL2_PROFIT=SymbolInfoString(SYMBOL2,SYMBOL_CURRENCY_PROFIT);

         if(SYMBOL2_BASE==SYMBOL2_PROFIT) continue;

         if(SYMBOL1_PROFIT!=SYMBOL2_BASE) continue;

         if(SYMBOL1_BASE==SYMBOL1_PROFIT) continue;

         

         for(int k=0;k<SYMBOLtotal && !IsStopped();k++)

         {

            string SYMBOL3=SymbolName(k,true);

            //if(SymbolInfoInteger(SYMBOL3,SYMBOL_TRADE_CALC_MODE)!=SYMBOL_CALC_MODE_FOREX) continue;

            string SYMBOL3_BASE=SymbolInfoString(SYMBOL3,SYMBOL_CURRENCY_BASE);

            string SYMBOL3_PROFIT=SymbolInfoString(SYMBOL3,SYMBOL_CURRENCY_PROFIT);

            if(SYMBOL2_BASE==SYMBOL2_PROFIT) continue;

            if(SYMBOL1_BASE!=SYMBOL3_BASE || SYMBOL2_PROFIT!=SYMBOL3_PROFIT) continue;

            if(SYMBOL3_BASE==SYMBOL3_PROFIT) continue;

            n=ArraySize(SYMBOLS1);

            ArrayResize(SYMBOLS1,n+1);

            ArrayResize(SYMBOLS2,n+1);

            ArrayResize(SYMBOLS3,n+1);

            SYMBOLS1[n]=SYMBOL1;

            SYMBOLS2[n]=SYMBOL2;

            SYMBOLS3[n]=SYMBOL3;

            break;

         }

      }

   }



   if (n>0)

   {

      int file_handle=FileOpen("Triangles.csv",FILE_READ|FILE_WRITE|FILE_CSV);

      FileWrite(file_handle,"Symbol 1","Symbol 2","Symbol 3");

      

      string txt=NULL;

      for(int i=n;i>=0;i--)

      {

         FileWrite(file_handle,SYMBOLS1[i],SYMBOLS2[i],SYMBOLS3[i]);         

         txt=StringConcatenate(txt,SYMBOLS1[i]," ",SYMBOLS2[i]," ",SYMBOLS3[i],"\n");         

      }

      FileWrite(file_handle,"");

      FileFlush(file_handle);

      if (TerminalInfoString(TERMINAL_LANGUAGE)=="Russian") 

         Comment("!:@8?B =0E>48B 2A5 20@80=BK A>G5B0=8O ?0@ 4;O B@5C3>;L=>3> 0@18B@060 87 B5E 8=AB@C<5=B>2, :>B>@K5 >B:@KBK 2 >17>@5 @K=:0\n!>25B=8: 4;O B>@3>2;8 B@5C3>;L=8:0<8 <>6=> A:0G0BL =0 A09B5 https://cmillion.ru/triangular-arbitration\nA5 =865?5@5G8A;5==K5 B@5C3>;L=8:8 70?8A0=K 2 D09; Triangles.csv\n",txt);

      else 

         Comment("The script finds all the options for combining pairs for triangular arbitrage from those tools that are open in the market overview\nThe Triangle Trading Advisor can be downloaded on the website https://cmillion.ru/en/triangular-arbitration\nPVSE the following triangles are written to the file Triangles.csv\n",txt);   

   }

}

Comments