These numbers are frozen (screenshot). They are not moving while the trade is being opened.

 
int OnInit()
  {
//--- indicator buffers mapping
  Comment( StringFormat( "Equity = %.2f; Balance = %.2f; Free Margin = %.2f", AccountInfoDouble( ACCOUNT_EQUITY ), AccountInfoDouble( ACCOUNT_BALANCE ), AccountInfoDouble (ACCOUNT_MARGIN_FREE) ) );

//---
   return(INIT_SUCCEEDED);
  }
How to fix it?
Files:
 
IgorFX Trading:
How to fix it?

You should not be getting info about the account in OnInit as it may not be loaded yet.

OnInit is only called once when the EA initiates so it will not be updated. So set your comment in OnTick

 
Keith Watford #:

You should not be getting info about the account in OnInit as it may not be loaded yet.

OnInit is only called once when the EA initiates so it will not be updated. So set your comment in OnTick

void OnTick()
{

Comment( StringFormat( "Equity = %.2f; Balance = %.2f; Free Margin = %.2f", AccountInfoDouble( ACCOUNT_EQUITY ), AccountInfoDouble( ACCOUNT_BALANCE ), AccountInfoDouble (ACCOUNT_MARGIN_FREE) ) );

} // Right? It doesn't work.
 
IgorFX Trading #: Right? It doesn't work.

It does work, provided it is an Expert Advisor (EA) and not an Indicator (you did not specify which one you are coding).

If it is an Indicator then you have to use OnCalculate() instead of OnTick().

Also, if you don't have any trade activity going on, then obviously those values will not change.

 
Fernando Carreiro #:

It does work, provided it is an Expert Advisor (EA) and not an Indicator (you did not specify which you are coding).

Also, if you don't have any trade activity going on, then obviously those values will not change.

Got it. Yeah, it was an indicator.

 

Given that you are having so much difficulty with MQL4, I suggest reading and following the lessons in the following book. It is how I started with MQL4.

EDIT: But make sure to get the latest edition with MQL4+ code.

Forum on trading, automated trading systems and testing trading strategies

Something Interesting to Read

Sergey Golubev, 2017.09.16 05:40

Expert Advisor Programming for MetaTrader 4


This book will teach you the following concepts:

  • The basic of the MLQ4 language, including variables and data types, operations, conditional and loop operators, functions, classes and objects, event handlers and more.
  • Place, modify and close market and pending orders.
  • Add a stop loss and/or take profit price to an individual order, or to multiple orders.
  • Close orders individually or by order type.
  • Get a total of all currently opened orders.
  • Work with OHLC bar data and locate basic candlestick patterns.
  • Find the highest high and lowest low of recent bars.
  • Work with MetaTrader’s built-in indicators, as well as custom indicators.
  • Add a trailing stop or break even stop feature to an expert advisor.
  • Use money management and lot size verification techniques.
  • Add a flexible trading timer to an expert advisor.
  • Construct several types of trading systems, including trend, counter-trend and breakout systems.
  • Add alert, emails, sounds and other notifications.
  • Add and manipulate chart objects.
  • Read and write to CSV files.
  • Construct basic indicators, scripts and libraries.
  • Learn how to effective debug your programs, and use the Strategy Tester to test your strategies.

All of the source code in this book is available for download, including an expert advisor framework that allows you to build robust and fully-featured expert advisors with minimal effort.


 
IgorFX Trading #: Got it. Yeah, it was an indicator.
Then use OnCalculate() instead of OnTick().
 
Fernando Carreiro #:

Given that you are having so much difficulty with MQL4, I suggest reading and following the lessons in the following book. It is how I started with MQL4.

EDIT: But make sure to get the latest edition with MQL4+ code.


Fernando, under each of my posts under which you answer, you mention my level of programming knowledge and that I should do this or that. I know what I need to do. Just answer my question, please, and thank you very much!

I've read this book recently. 


And that I realized that it is not about reading words, but about practice. It's a slow road, I'm done with this book. I chose the path of learning for myself by collecting and filtering information.  You may not understand, but the main thing is that I understand. Accordingly, one of the ways to learn programming is to ask questions, is it bad? The book will not answer all my questions, what idea of ​​an adviser will come into my head, I will implement it by collecting information on the MQL5 website and others. It's a billion times faster. I am grateful to this book all the same, I borrowed some functions from there anyway. 

Files:
 
IgorFX Trading #: Fernando, under each of my posts under which you answer, you mention my level of programming knowledge and that I should do this or that. I know what I need to do. Just answer my question, please, and thank you very much!
Very well! I will leave you to your own path that you have chosen. I will however, not be answering any more of your questions! I will leave that to others that wish to answer you!
Reason: