Rotate symbols on the same chart

 

Hello,

I wrote a code for rotate all the symbols on the same chart, but not working.

Could someone tell me what is the problem or give another working code for that?

Thank you.

int start()
  {
int symb=SymbolsTotal(true);
      for ( int i=0; i<symb; i++)
     {
     ChartSetSymbolPeriod(0,SymbolName(i,true),_Period); 
     ChartRedraw();
     Sleep(2000);
     }
   return(0);
  }
 
kovi:

Hello,


This is very nice.

But could someone give a code, which could rotate the symbols on the same chart?

I wrote one but that is not working. Could someone give another one or tell me what is the problem?

When you change symbol on the current chart all indicators and EA are restarted, script exits.

So. your script should change symbol one time and then exit.

Your script should do the following:

  • open new chart with ChartOpen() (or set open chart as topmost with ChartSetInteger())
  • get that chart Id and then use it in your script as the first argument in the ChartSetSymbolPeriod()
This way your script will keep running in the background window. 
 
kovi: Could someone tell me what is the problem
Perhaps you should read the manual.
  1. Changes the symbol and period of the specified chart. The function is asynchronous, i.e. it sends the command and does not wait for its execution completion. The command is added to chart message queue and executed only after all previous commands have been processed.
              https://docs.mql4.com/chart_operations/chartsetsymbolperiod

    You added the change symbol event to the queue. Once you exit the code, a deinit, change, init will occur for your EA. Not going to work because you don't exit.

    When you get the init, wait your 2 seconds, find the next symbol after the current one and switch to that.

  2. You should stop using the old event handlers and IndicatorCounted() and start using new event handlers.
              Event Handling Functions - Functions - Language Basics - MQL4 Reference
              How to do your lookbacks correctly - MQL4 programming forum #9-14.
 
kovi:

Do not double/triple post!

I will delete your other posts and move a reply here.

 
Keith Watford:

Do not double/triple post!

I will delete your other posts and move a reply here.

Thank you for your help. I'm new for asking help. I will not double post.
 
Drazen Penic:

When you change symbol on the current chart all indicators and EA are restarted, script exits.

So. your script should change symbol one time and then exit.


Thank you very much. I forget this.