- You place the stop where it needs to be - where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support.
- Account Balance * percent = RISK = (OrderOpenPrice - OrderStopLoss)*DIR * OrderLots * DeltaPerlot (Note OOP-OSL includes the SPREAD)
- Do NOT use TickValue by itself - DeltaPerlot
- You must normalize lots properly and check against min and max.
- You must also check FreeMargin to avoid stop out
Hey guys,
Does anybody have a function that increases the lot size by a certain amount when the account balance increases by a certain amount. Eg. If the account is initially on $2000 I want it to trade on 0.2 and when the account balance reaches $3000 it must start trading at 0.3 etc.
Thanks!
This is what I use on a Daily basis in my real account. It works for me, I am not sure if it is what you are looking for.
I manage risk through LotSize not Stops,I use ATR for StopLevels.
Below is just a function to be added to a EA.
//+------------------------------------------------------------------+ //| RiskManagementLotSize.mq4 | //| Gypsy | //| none | //+------------------------------------------------------------------+ #property copyright "Gypsy" #property link "none" #property version "1.00" #property strict //------------------------------------------------------------------------------------------------- //Risk Management //------------------------------------------------------------------------------------------------- extern string risk="Use Risk Management to set LotSize - True or False";//Alert extern bool Use_RiskManagement_LotSize=false; extern double Risk_Percent=2;//Percentage of Account Balance to Risk extern string Risk_break="";//======================================= //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double RMLotSize() { /* //------------------------------------------------------------------------------------------------- //Risk Management //------------------------------------------------------------------------------------------------- extern string risk="Use Risk Management to set LotSize - True or False";//Alert extern bool Use_RiskManagement_LotSize=false; extern double Risk_Percent=2;//Percentage of Account Balance to Risk extern string Risk_break="";//======================================= */ //------------------------------------------------------------------------------------------------- //current account balance double acctbal=0.00; if(AccountBalance()>0){acctbal=AccountBalance();} //------------------------------------------------------------------------------------------------- //risk percentage double riskpercentage=0.00; if(Risk_Percent>0){riskpercentage=Risk_Percent/100;} //------------------------------------------------------------------------------------------------- //amount of capitol to risk based on percentage double riskcapitol=0.00; if(acctbal>0){riskcapitol=acctbal*riskpercentage;} //------------------------------------------------------------------------------------------------- //lotsize based on risk capitol double lotsize=0.00; if(riskcapitol>0){lotsize=riskcapitol*0.01;} //------------------------------------------------------------------------------------------------- //if lotsize is more than is permitted change the lotsize to the maximum permitted if(lotsize>MarketInfo(Symbol(),MODE_MAXLOT)) {lotsize=MarketInfo(Symbol(),MODE_MAXLOT);} //------------------------------------------------------------------------------------------------- //if lotsize is less than is permitted change the lotsize to the minimum permitted if(lotsize<MarketInfo(Symbol(),MODE_MINLOT)) {lotsize=MarketInfo(Symbol(),MODE_MINLOT);} //------------------------------------------------------------------------------------------------- //if there is no orders available print Account Information and LotSize available if(OrdersTotal()==0) { Print("-------------------------------------------------------------------------------------------------"); Print("LotSize based on the Capitol available...",DoubleToStr(lotsize,2)); Print("Amount of Capitol to Risk...",DoubleToStr(riskcapitol,2)); Print("Risk Percentage...",DoubleToStr(Risk_Percent,2)); Print("Account Balance...",DoubleToStr(acctbal,2)); Print("-------------------------------------------------------------------------------------------------"); } return(lotsize); }
- You place the stop where it needs to be - where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support.
- Account Balance * percent = RISK = (OrderOpenPrice - OrderStopLoss)*DIR * OrderLots * DeltaPerlot (Note OOP-OSL includes the SPREAD)
- Do NOT use TickValue by itself - DeltaPerlot
- You must normalize lots properly and check against min and max.
- You must also check FreeMargin to avoid stop out
Hey WHRoeder,
I simply would like something like this...
if(AccountBalance()>=1000 && AccountBalance()<2000) Lots=0.1; if(AccountBalance()>=2000 && AccountBalance()<3000) Lots=0.2;
etc...
Any way to do this instead of typing them all out??
Hey WHRoeder,
I simply would like something like this...
etc...
Any way to do this instead of typing them all out??
Not sure it works in MQL4 or not, but in Java they have a switch/case setup, where you set the switch to check for the enclosed (in brackets) cases, and depending on what each case test comes out as, your program will do the line(s) for that particular case. It is functionally similar to an if/elseif/else type of operation. It might be a little easier to code than your if... for every single one but past that, no other way around doing at least one for each situation you want to cover that I can see.
Not sure it works in MQL4 or not, but in Java they have a switch/case setup, where you set the switch to check for the enclosed (in brackets) cases, and depending on what each case test comes out as, your program will do the line(s) for that particular case. It is functionally similar to an if/elseif/else type of operation. It might be a little easier to code than your if... for every single one but past that, no other way around doing at least one for each situation you want to cover that I can see.
for(int inc=0; inc<=50; inc++) { if(AccountBalance()>=1000+(1000*inc) && AccountBalance()<2000+(1000*inc)) double lots=NormalizeDouble(0.01+(0.01*inc),Digits);
Please excuse this if this is completely incorrect, however, is it possible to do something like this:
Okay I can confirm this works:
for(int inc=0; inc<=1000; inc++) { if(AccountBalance()>=1000+(1000*inc) && AccountBalance()<2000+(1000*inc)) { double lots=NormalizeDouble(0.01+(0.01*inc),Digits); } }
For anyone who reads this and needs something similar. :)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hey guys,
Does anybody have a function that increases the lot size by a certain amount when the account balance increases by a certain amount. Eg. If the account is initially on $2000 I want it to trade on 0.2 and when the account balance reaches $3000 it must start trading at 0.3 etc.
Thanks!