Download MetaTrader 5

Change the symbol in a script execution

To add comments, please log in or register
Jusyer
41
Jusyer  

Hi.

I wonder if you can change the symbol in a single execution of the script. I have a script that analyzes various candles symbol of the window where I throw it, and I would like, in the same execution, change the symbol and also analyze candles of the new symbol.

All this is to not have to go putting the script in all windows, and work less well :)

Thanks, greetings.

rod178
272
rod178  
Jusyer:

Hi.

I wonder if you can change the symbol in a single execution of the script. I have a script that analyzes various candles symbol of the window where I throw it, and I would like, in the same execution, change the symbol and also analyze candles of the new symbol.

All this is to not have to go putting the script in all windows, and work less well :)

Thanks, greetings.

Yes, it is possible to run code on a Symbol(s) other than the current Chart, although without seeing your code cannot provide further advice.
Jusyer
41
Jusyer  
Thanks for responding.
The code is simple, measures a number of candles and returns how many over a certain size.
Would I have to change the core of the code? or you can put some instruction before, which change the symbol and then run the core of the code?
SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI  
No code no help. Sorry. Use SRC when posting code.
BigAl
489
BigAl  
Look at documentation on MarketInfo
Keith Watford
Moderator
9641
Keith Watford  
Jusyer:
Thanks for responding.
The code is simple, measures a number of candles and returns how many over a certain size.
Would I have to change the core of the code? or you can put some instruction before, which change the symbol and then run the core of the code?

One way of doing it would be to put the symbols in a string array

ie

string Symbs="EURUSD,GBPUSD,USDJPY"

You can change and/or add symbol names. Just separate them with a comma. The symbol names must be the same as your broker uses 

string Symbs="EURUSDm,GBPUSDm,USDJPYm,USDCHFm,EURJPYm" 

input string Symbs="EURUSD,GBPUSD,USDJPY";

  string SymbolArray[];
  int array_size; 
     
  //in onOnit
    
  ushort u_sep=StringGetCharacter(",",0);
  StringSplit(Symbs,u_sep,SymbolArray);
  array_size=ArraySize(SymbolArray);

  //In Main code

  for(int x=0;x<array_size;x++)
    {
    double last_candle_close=iClose(SymbolArray[x],PERIOD_H1,1);
    int dig=(int)MarketInfo(SymbolArray[x],MODE_DIGITS);
    string lcc=DoubleToStr(last_candle_close,dig);
    Print(SymbolArray[x]+"Last candle close="+lcc);
    //The Print is just to show that it works. 
    }
  
Jusyer
41
Jusyer  
input int Puntos = 100;
input int Velas = 7200;

void OnStart()
{
  int contador=0;
  
  for (int i=0; i<Velas; i++) 
  {
     
     if(Open[i]-Close[i]>Puntos*Point || Close[i]-Open[i]>Puntos*Point)
     {
         contador++;
         ObjectCreate(ChartID(),"flecha"+i,OBJ_VLINE,0,Time[i],High[i]);
     }
  }
  Alert(Symbol() + ": Analizadas: " + Velas + ". Tamaño: " + Puntos + ". Total: " + contador);   
}    
             
This is the code, very simple.
whroeder1
14779
whroeder1  
Jusyer: I wonder if you can change the symbol in a single execution of the script.  change the symbol and also analyze candles of the new symbol.
Not possible. If you change the chart, you get a pop up message, the script exits and it's gone.
  1. Keep the chart as is, look at other symbols (e.g. GumRai ,) change at the end if needed.
  2. Use an EA.
Jusyer
41
Jusyer  
Thanks guys.
I think with "iOpen" and "iClose" I can do. I'll try and tell you the result.
Greetings.
To add comments, please log in or register