Stop Trading when not enough money

 
Is there away to tell metatrader to "Stop Trading when not enough money" in the account? ...and to wait for ACCOUNT BALANCE to increase. Currently I get multiple warnings as I forward test "M-NOT enough money to trade". margin is insufficient to trade a lot size of 1.6". After a while my account is dissabled by my brokers server.



 
trueresource:
Is there away to tell metatrader to "Stop Trading when not enough money" in the account? ...and to wait for ACCOUNT BALANCE to increase. Currently I get multiple warnings as I forward test "M-NOT enough money to trade". margin is insufficient to trade a lot size of 1.6". After a while my account is dissabled by my brokers server.



Just code your EA to stop trading when a variable is set to false or true, for example,

bool AllowTrading = false;

or

bool StopTrading = true;

Or check the margin requirement for the trade you are about to place, if you don't have enough free margin don't place the trade . . .

There are usually plenty of ways to do most things, what is possible is dependant on your ability to think clearly, analyse your problem and come up with a solution . . .

 
RaptorUK:

Just code your EA to stop trading when a variable is set to false or true, for example,

Or check the margin requirement for the trade you are about to place, if you don't have enough free margin don't place the trade . . .

There are usually plenty of ways to do most things, what is possible is dependant on your ability to think clearly, analyse your problem and come up with a solution . . .


Thank RaptorUK

I use MOLANIS to code, therefore am restricted to syntax. I will give you a few examples of how I need to code so that maybe you can write your above solution in a method molanis will except:

EXAMPLE

MarketInfo("PairName",MODE_ASK)-MarketInfo("PairName",MODE_BID)<=6.0

or

iStdDev(Symbol(),0,12,0,MODE_EMA,PRICE_CLOSE,0)>0.0005

Hope you can help.

 
If you want to learn to code MQL4 then you need to code in MQL4 . . .
 
RaptorUK:
If you want to learn to code MQL4 then you need to code in MQL4 . . .

Yes, I agree. Im taking steps to learn. I was going to take a C++ class first. Now Im told that would be too complex for a beginer. Please advise, What do you beleive is the best way to start learning MQL
 
trueresource:

Yes, I agree. Im taking steps to learn. I was going to take a C++ class first. Now Im told that would be too complex for a beginer. Please advise, What do you beleive is the best way to start learning MQL
There are resources on this site: https://book.mql4.com// and the syntax reference: https://docs.mql4.com// and also lessons here (I think you will need to register to download the PDFs): https://www.forex-tsd.com/lessons/?pp=20&daysprune=-1
 
trueresource:
Is there away to tell metatrader to "Stop Trading when not enough money" in the account? ...and to wait for ACCOUNT BALANCE to increase. Currently I get multiple warnings as I forward test "M-NOT enough money to trade". margin is insufficient to trade a lot size of 1.6". After a while my account is dissabled by my brokers server.
Check free margin BEFORE trying to open the order. See my code
 
WHRoeder:
Check free margin BEFORE trying to open the order. See my code

Thanks. That allot of code. Is the code genneric or does it require modification? Also does it deal with all the naughty error we see in metatrader? Im am just learning to code.
 
trueresource:

Also does it deal with all the naughty error we see in metatrader?
What errors are you referring to ?
 
RaptorUK:
What errors are you referring to ?


For Example: "trade context is busy".

Also I am about to purchase the Pro version of MOLANIS, which will allow me to drop code into my ea thru meteditor. should I drop your whole code into my code or does it have to be modified? for example I dont use stop losses but notice something in your code that referenced stop losses.

Im not at a point in the learning curve to modify you code so just want to know if its a "ready made" fix for the typical problem we see such as for example "trade context is busy" and "M-NOT enough money to trade". margin is insufficient to trade a lot size of 1.6"

 

If you have 2 or more EAs on different charts all trying to trade then there is a possibility that you will get "trade context is busy" while one is placing or modifying an order . . . it's not "naughty", it's how it is and it can be handled.

You will never get sufficiently along the learning curve to use WHRoeder's code if you continue to use "tools" like Molanis.

Ask Molanis how they handle "trade context is busy" ? do a search in their Forum, it's quite revealing . . . seems they don't have a clue.

Reason: