Passing script to function() in EA to run it every new bar

 

Hi all,

I use a script to to calculate the liquidity volume on chart and draw trend line on chart based on price, time and volume.

Script itself work fine when drop it into chart, i have included this script in EA as a Function and call the function on every new bar.

On the first run of this function in EA, the trend lines are well drawed on chart, all is ok.

But after this first run and when a new bars emerge i see that the function is working but not draw the new lines, it just keep the trend lines from the first run.

I use the ObjectsDeleteAll function before call the custom function but it keep recalculate the first trend lines. If i run the script manually on the same chart it draw new trend lines.

Anyone have an idea of the problem ? I think i miss to call some function so it recalculate according to the new rates, but can't find any solution. 

Any help will be much appreciated

Thanks

void OnTimer(){
 
   mysymbol.Refresh();                 
   mysymbol.RefreshRates();                           
   int CandleNumber = Bars(_Symbol,PERIOD_M1);
   CheckForNewCandle(CandleNumber); 
   
   if(NewCandle){
      //DelObjects();
      //Liquidity();
      }
}

//////////
void DelObjects(){

   ObjectsDeleteAll(0,-1,-1);
   ChartRedraw(0);
}

//////////
void Liquidity(const long chart_id=0,const datetime lastbar_time=0){   

.........
}
 
huwa :

Hi all,

I use a script to to calculate the liquidity volume on chart and draw trend line on chart based on price, time and volume.

Script itself work fine when drop it into chart, i have included this script in EA as a Function and call the function on every new bar.

On the first run of this function in EA, the trend lines are well drawed on chart, all is ok.

But after this first run and when a new bars emerge i see that the function is working but not draw the new lines, it just keep the trend lines from the first run.

I use the ObjectsDeleteAll function before call the custom function but it keep recalculate the first trend lines. If i run the script manually on the same chart it draw new trend lines.

Anyone have an idea of the problem ? I think i miss to call some function so it recalculate according to the new rates, but can't find any solution. 

Any help will be much appreciated

Thanks

If the graphic was created earlier, you must use the 'move object' command. See example OBJ_VLINE, function 'VLineMove'

Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Types / OBJ_VLINE
Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Types / OBJ_VLINE
  • www.mql5.com
//| Create the vertical line                                         |               time=0,                          width=1,            //
 
Vladimir Karputov:

If the graphic was created earlier, you must use the 'move object' command. See example OBJ_VLINE, function 'VLineMove'

Thanks for your answer Vladimir, but what i don't understand is that before run new calculs (Void Liquidity) i do run "ObjectsDeleteAll" witch must delete all the trend lines (and actually does it) before draw new trend line.

So in this case this is not a ObjectMove that i need, but still with that the Trends are calculated from the first calculous and not updated.

Thanks for your time

Reason: