//+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { //--- double accountBalance = AccountBalance(); datetime timeCurrent = TimeCurrent(); string timeString = TimeToString(timeCurrent); string textValue = StringFormat("AccountBalance: %.2f - TimeCurrent: %s", accountBalance, timeString); Comment(textValue); //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+
Try this. Just nailed it into the Metaeditor.
1) Create a custom indicator with a name of your choice.
2) Put the code with the yellow background inside the OnCalculate(); function of your indicator. Compile and insert the indicator into a chart.
Now you can do this as Script as well with the OnStart(); function. This only run one time. The OnTick(); function only works in the expert advisor. Hope this get's you going.
.

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi there,
I tried to display the time and Balance, but I am seeing nothing.
void OnTick()
{
//-- The algorithm ---------------------------------------------------- 3 ---
Alert("aaaaaa",TimeToStr(TimeCurrent()),AccountBalance());
Print("Time=",TimeCurrent(),"Account balance=",AccountBalance());
Any ideas?
Herbie