error 134 Not Enough Money What is wrong with my formula?

 

I want to risk 25% of my equity, So I want to find out how much lots I need to buy.


Equity() = $9000.

Risk = $9000*0.25 = $2250

I want to use a 20 pip stop. So I calculate Risk/stop(in pips) = $2250/20 = $112.5.


This is where I THINK my confusion is:

I have a mini-account on a 3/5 digit quoting broker so I know my tickvalue is 1. So I should profit/lose $1 per pip.

dividing $112.5/1 = 112.5 .

Now when I open an order for 112.5 mini-lots I get an error 134 Not enough money.

Where did I go wrong?

 

Usually a mini or micro lot is 0.01 standard lots. Therefore 112.5 micro lots would actually be 112.5*0.01 standard lots.

Since your broker is probably expecting you to measure your lotsize in standard lots in the lotsize parameter of the order command, you should probably be trying to open only 1.125 lots (rounded to 1.12).

 
jeemba2012:

I have a mini-account on a 3/5 digit quoting broker so I know my tickvalue is 1.

Run this little script to see what your contract values are ...

int start(){

   string str="";
   str= str + "MODE_SPREAD="    + DoubleToStr(MarketInfo(Symbol(),MODE_SPREAD),0)        +"\n";
   str= str + "MODE_TICKVALUE=" + DoubleToStr(MarketInfo(Symbol(),MODE_TICKVALUE),Digits)+"\n";
   str= str + "MODE_TICKSIZE="  + DoubleToStr(MarketInfo(Symbol(),MODE_TICKSIZE),Digits) +"\n";
   str= str + "MODE_STOPLEVEL=" + DoubleToStr(MarketInfo(Symbol(),MODE_STOPLEVEL),0)     +"\n";
   str= str + "MODE_POINT="     + DoubleToStr(MarketInfo(Symbol(),MODE_POINT),Digits)    +"\n";
   str= str + "MODE_DIGITS="    + DoubleToStr(MarketInfo(Symbol(),MODE_DIGITS),0)        +"\n";
   str= str + "MODE_MINLOT="    + DoubleToStr(MarketInfo(Symbol(),MODE_MINLOT),3)        +"\n";
   str= str + "MODE_LOTSIZE="   + DoubleToStr(MarketInfo(Symbol(),MODE_LOTSIZE),0)       +"\n";

   Comment(str);
   
   return(0);
}

My tick size is 0.00001 for example

but my tick value is 0.61829 on EURUSD

 
dabbler:

Run this little script to see what your contract values are ...

My tick value is 0.00001 for example



I meant 0.10000 and I multiplied that by 10 to get the value of 1 pip.

 
Next trick: try it with a demo account. Open 1 lot and see how much margin is used. I lot on EURUSD costs me $1319.08 on my $ demo account. The position will immediately be in loss by the spread. Right click on the the trade window and set profit | as points. You can now see profit in points for 1 lot above cost in $. Mine shows -28 points and -$28, in other words $1/point/lot.
 

New script with a few extra values ...

int start(){

   string str="";
   str= str + "MODE_DIGITS="        + DoubleToStr(MarketInfo(Symbol(),MODE_DIGITS),0)        +"\n";
   str= str + "MODE_SPREAD="        + DoubleToStr(MarketInfo(Symbol(),MODE_SPREAD),0)        +"\n";
   str= str + "MODE_STOPLEVEL="     + DoubleToStr(MarketInfo(Symbol(),MODE_STOPLEVEL),0)     +"\n";
   str= str + "MODE_TICKVALUE="     + DoubleToStr(MarketInfo(Symbol(),MODE_TICKVALUE),Digits)+"\n";
   str= str + "MODE_TICKSIZE="      + DoubleToStr(MarketInfo(Symbol(),MODE_TICKSIZE),Digits) +"\n";
   str= str + "MODE_POINT   ="      + DoubleToStr(MarketInfo(Symbol(),MODE_POINT),Digits)    +"\n";
   str= str + "MODE_MINLOT="        + DoubleToStr(MarketInfo(Symbol(),MODE_MINLOT),3)        +"\n";
   str= str + "MODE_MAXLOT="        + DoubleToStr(MarketInfo(Symbol(),MODE_MAXLOT),3)        +"\n";
   str= str + "MODE_LOTSIZE="       + DoubleToStr(MarketInfo(Symbol(),MODE_LOTSIZE),0)       +"\n";
   str= str + "MODE_MARGINREQUIRED="+ DoubleToStr(MarketInfo(Symbol(),MODE_MARGINREQUIRED),2)+"\n";
   Comment(str);
   
   return(0);
}

The point is, if your leverage is set too low you may require too much margin to support that position. This script will show you.

 
dabbler:

New script with a few extra values ...

The point is, if your leverage is set too low you may require too much margin to support that position. This script will show you.




Profit in points was -26 . when I changed it back to $, it was -$2.60

 
jeemba2012:

Profit in points was -26 . when I changed it back to $, it was -$2.60

Thank you for doing the work so I can help you :-)

The problem is your margin requirements. $162.81/lot means you need a margin of 112.5*$162.81 = $18316 to open that position. This is very unusual; we don't normally see margins being a problem because people normally have leverage set to 100, 200 or 500 to 1.

On my USD demo account (100:1 leverage) the margin required is $811.71 for NZDUSD but that is for full lots (100,000 units). Looks like your leverage is set to 50:1 for some reason. If you want to risk 25% of your account on one trade (which is about 10x more than usually recommended) you need to get your leverage up to at least 200:1

 

So the Calculation is right but my margin settings are wrong. Thank you so much for taking the time to help me. I am trying to become a good developer. I know how to code but I am still

trying to get familiar with the mechanics of broker operation and settings which has been a huge road block.

Thanks again

 
dabbler:
On my USD demo account (100:1 leverage) the margin required is $811.71 for NZDUSD but that is for full lots (100,000 units). Looks like your leverage is set to 50:1 for some reason.
Check again dabbler. All US accounts are now 50:1 on majors 20:1 on minors. Forex Leverage Limit 50:1 - Will US Traders Run Away? | Forex Crunch
 
jeemba2012:
So the Calculation is right but my margin settings are wrong.
  1. Don't assume, don't hard code numbers.
  2. Also it's not the margin required to open but the margin to remain open as market approaches your SL.
  3. See my code
Reason: