Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1507

 
MakarFX:

Is there any way to determine the number of open charts?

Fixed it to 100.

If you need to find one thing, then return after finding it, so you don't have to keep running the loop

 
Vitaly Muzichenko:

Corrected to 100.

If you need to find one thing, then after you have found it, return, so you don't have to keep running the loop

I need to run the loop on every tick, so I made it like this

   long currChart=ChartFirst();
   double pr;
   int vdigits;
   int i=0; while(i<=CHARTS_MAX)
     {
      if(currChart<0) break;
      if(ObjectFind(currChart,ChartSymbol(currChart)+" BUY")==0) 
        { 
         pr=ObjectGetDouble(currChart,ChartSymbol(currChart)+" BUY",OBJPROP_PRICE1);
         vdigits = (int)MarketInfo(ChartSymbol(currChart),MODE_DIGITS); 
         Print(i," ",ChartSymbol(currChart)," ",DoubleToStr(pr,vdigits));
        }else{Print(i," ",ChartSymbol(currChart)," 0");}
      currChart=ChartNext(currChart);  i++;
     }
 

what if two "something-ones" are open?
why not keep racing?

 
MakarFX:

I need to run a loop on every tick

maybe think of doing something withCHARTEVENT_CUSTOM.

 
Aleksei Stepanenko:

maybe think of doing something withCHARTEVENT_CUSTOM somehow.

Not an option...need to check it without my involvement.

The code above seems to work correctly, but since I'm a weak programmer, I wanted to see the opinion of more experienced and knowledgeable people.

...long wait until Monday to test it (

 
So the programme can listen to the air instead of the cycle without your involvement too, no?
 
Aleksei Stepanenko:
So the programme can listen to the airwaves without your involvement too, no?
I don't get it...
 
I haven't looked into it, but I think you could assign an event to each graph and then wait for it in the OnChartevent... Don't know, but hopefully
 
MakarFX:

I need to run a loop on every tick, so I did it this way

You don't need to pull crap from help, write an obvious loop... you'll have to live with it later :-)

   for(long chartId=ChartNext(0);chartId>0 &&!IsStopped();chartId=ChartNext(chartId)) {

      if (ChartSymbol(chartId)=="") continue;

      DoChart(chartId);

   }

 
Aleksei Stepanenko:
I haven't studied the question, but I think you can assign an event to each chart and then wait for it in OnChartevent...

Alexei, to be honest, with my knowledge it sounds scary...

I need to keep it simple, find an object to buy-buy, find an object to sell-sell.