Money management Custom code

 
How can I create a switch that can make me change from fixed size lot to position sizing based on account balance or %risk. Please I need some help . 
 

Money Management


The forum

  1. MM (money management) calculation, indicators, discussion, tools: calculate your lot size and so on. Original thread with several versions.
  2. MoneyManagement EA is on this thread: it shows you market information and money management on the chart. 
  3. Forex Money Management, Part 1 - good small thread
  4. Useful money management expert - the thread with the EA 
  5. Stop Your Mind From Causing You to Take Profits Too Soon - the post with the educational video 
  6. Money Management: How to Determine an Initial Stop Level - the post with the educational video 
  7. Why Most Traders Lose Money and The Solution - the post with the educational video

The articles

  1. Statistical Verification of the Labouchere Money Management System 
  2. Functions for Money Management in an Expert Advisor 
  3. Fallacies, Part 1: Money Management is Secondary and Not Very Important 
  4. MQL5 Wizard: How to Create a Risk and Money Management Module 
  5. Money Management Revisited 
  6. Cross-Platform Expert Advisor: Money Management 
  7. Limitless Opportunities with MetaTrader 5 and MQL5 

CodeBase

============
 
Anzoumana Dabila: How can I create a switch that can make me change from fixed size lot to position sizing based on account balance or %risk. Please I need some help . 
enum MMMode{ Fixed, Percentage };
input MMMode RiskMode       = Fixed;
input double FixedRisk      = 100;
input double PercentaceRisk = 100;
:
double moneyRisk = RiskkMode == Fixed ? FixedRisk : PercentageRisk/100 * AccountBalance();
double lots      = ComputeLots(moneyRisk, SL);

Is that so hard?

  1. In code: Risk depends on your initial stop loss, lot size, and the value of the pair.
    • 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/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the SPREAD, and DeltaPerLot is usually around $10/pip but it takes account of the exchange rates of the pair vs. your account currency.)
    • Do NOT use TickValue by itself - DeltaPerLot and verify that MODE_TICKVALUE is returning a value in your deposit currency, as promised by the documentation, or whether it is returning a value in the instrument's base currency (EUR, in this case).
                MODE_TICKVALUE is not reliable on non-fx instruments with many brokers.
    • You must normalize lots properly and check against min and max.
    • You must also check FreeMargin to avoid stop out
    Most pairs are worth about $10 per PIP. A $5 risk with a (very small) 5 PIP SL is $5/$10/5=0.1 Lots maximum.
  2. Use a EA GUI such as the one for MT4: Indicators: 'Money Manager Graphic Tool' indicator by 'takycard' Forum - Page 5
 
I got the code , I’m trying to create a true or false , where i can switch from fixed lot size to %risk . Vice versa . I’m not good at coding I use EAbuilder and there is no such function in it. Thank you!
 
Anzoumana Dabila I’m not good at coding I use EAbuilder
EA builder, fxDreema, EATree, FxPro Quant, MQL5 Wizard, etc. are all the same. You will get something quick, but then you will spend a much longer time trying to get it right, than if you learned to the language up front, and then just wrote it.
  • Since you haven't learned MQL4/5, therefor there is no common language for us to communicate.
    If we tell you what you need, you can't code it.
    If we give you the code, you don't know how to integrate it into yours.
    We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem, but we are not going to debug your hundreds of lines of code. You are essentially going to be on your own.

  • EA builder makes bad code counting up while closing multiple orders.
    EA builder makes bad code Bars is unreliable (max bars on chart) volume is unreliable (miss ticks) Always use time. New candle - MQL4 forum
    EA builder makes bad code, not adjusting for 4/5 digit brokers, TP/SL and slippage.
    EA builder makes bad code, not adjusting for ECN brokers. (pre-Build 500)
    EA builder makes bad code, not checking return codes.
    EATree uses objects on chart to save values - not persistent storage (files or GV+Flush.) No recovery (crash/power failure.)
 
Anzoumana Dabila:
I got the code , I’m trying to create a true or false , where i can switch from fixed lot size to %risk . Vice versa . I’m not good at coding I use EAbuilder and there is no such function in it. Thank you!

Your options are learn to code, hire someone, or contact the developer of the EA Builder you used.

Excellent & Free Option #1: Documentation (Learn to code)

https://www.mql5.com/en/docs


Excellent & affordable Option #2: Freelance (Hire someone)

https://www.mql5.com/en/job


Don't know. Don't care. Not our problem. Option #3: Contact the developer of the EA Builder you used.

MQL5 Reference - How to use algorithmic/automated trading language for MetaTrader 5
MQL5 Reference - How to use algorithmic/automated trading language for MetaTrader 5
  • www.mql5.com
MetaQuotes Language 5 (MQL5) is a high-level language designed for developing technical indicators, trading robots and utility applications, which automate financial trading. MQL5 has been developed by MetaQuotes Software Corp. for their trading platform. The language syntax is very close to C++ enabling programmers to develop applications in...
 
Anzoumana Dabila:
I got the code , I’m trying to create a true or false , where i can switch from fixed lot size to %risk . Vice versa . I’m not good at coding I use EAbuilder and there is no such function in it. Thank you!
Hello, did you solve it? Could you tell me how you did it? I also use EAbuilder. Thank you!!
Reason: