How CPU intensive will this be running on each tick?

Back to topics list To post a new topic, please log in or register
avatar
26
kinitex 2016.07.08 21:31
 
for(i=0; i<200; i++){ //repaint

   string barNamex = "barBodyx" + i;
   string barName2 = "barBody2" + i;
   int type = OBJ_RECTANGLE;
   int window = 0;
   datetime barTime = Time[i];
   double barHigh = iMA(NULL,0,EMA1,0,MODE_EMA,PRICE_MEDIAN,i);
   double barLow = iMA(NULL,0,EMA2,0,MODE_EMA,PRICE_MEDIAN,i);
   double barClose = Close[i];
   datetime time3=0;
   double price3=0;
   color colour = Black;

   // On every click, all objects are deleted to avoid having objects piling up on each iteration
   if(i==0){ //delete objects
      ObjectsDeleteAll();
   }// end delete objects


   
   //bar vertical repaint
   ObjectCreate(barNamex, type, window, barTime, barHigh, barTime, barHigh);
   ObjectSet(barNamex, OBJPROP_COLOR, clrRed);
   ObjectSet(barNamex, OBJPROP_STYLE, STYLE_DASH);
   ObjectSet(barNamex, OBJPROP_WIDTH, 5);
   ObjectSet(barNamex, OBJPROP_BACK, false);
   //end bar vertical repaint

   //bar vertical repaint
   ObjectCreate(barName2, type, window, barTime, barLow, barTime, barLow);
   ObjectSet(barName2, OBJPROP_COLOR, clrBlue);
   ObjectSet(barName2, OBJPROP_STYLE, STYLE_DASH);
   ObjectSet(barName2, OBJPROP_WIDTH, 5);
   ObjectSet(barName2, OBJPROP_BACK, false);
   //end bar vertical repaint

   
} //end


I am trying to find a way to draw my indicators on chart in an EA without using a template or adding them manually. Will running a loop like this for 200 or more bars every tick be too much for an EA that will be running on 10-20 pairs on an account?

avatar
1197
FMIC 2016.07.08 22:14 #
 

Yes, it will be CPU intensive and given that all the values, for "i > 0", of "Close[i]" and of "iMA(...,i)" remain the same on every tick, until a new bar is formed, then it is an absolute waist of CPU and RAM.

The only values that will change in almost every tick, will be "Close[0]" and "iMA(...,0)". All the other values, need only be checked and updated when a new bar is formed.

Also, there is no need to keep deleting and recreating the Chart Objects. Create them only ONCE and then when values CHANGE (and only when it changes), use the "ObjectMove()" function to adjust to the new position.

avatar
164
drazen64 2016.07.08 23:26 #
 
kinitex:


I am trying to find a way to draw my indicators on chart in an EA without using a template or adding them manually. Will running a loop like this for 200 or more bars every tick be too much for an EA that will be running on 10-20 pairs on an account?

You know that you are allowed to do the test? Simply open 10-20 charts, attach an EA and observe. 

It does not hurt and usually gives you answers much faster than asking on forums.

Hint: MT4 has a code profiler. If you run a test using a profiler, you'll see which part of the code is most critical.

 

Back to topics list  

To add comments, please log in or register