Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@igotit-anything
Created March 22, 2023 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igotit-anything/c2a7695152f72bceac272c21b580133c to your computer and use it in GitHub Desktop.
Save igotit-anything/c2a7695152f72bceac272c21b580133c to your computer and use it in GitHub Desktop.
MT4 Commission BreakEven Points
//+------------------------------------------------------------------+
//| CCy_Commission_1.mqh |
//| igotit |
//| https://igotit.tistory.com |
//+------------------------------------------------------------------+
#property copyright "igotit"
#property link "https://igotit.tistory.com"
#property version "1.00"
#property strict
#include "cy_typedef.mqh" // for CyENUM_COMMISSION_TYPE etc.
class CCy_Commission_1
{
private:
double m_Commission_Percent;
double m_Commission_Ratio; //= m_Commission_Percent/100.
CyENUM_COMMISSION_TYPE m_em_Commission_Type;
public:
CCy_Commission_1();
~CCy_Commission_1();
void Proc_OnInit(double _commission_percent, CyENUM_COMMISSION_TYPE _em_commission_type);
int GetPoints_BreakEven(double _price_open, CyENUM_POSI_TYPE _em_posi_type);
};
CCy_Commission_1::CCy_Commission_1()
{
}
CCy_Commission_1::~CCy_Commission_1()
{
}
void CCy_Commission_1::Proc_OnInit(double _commission_percent, CyENUM_COMMISSION_TYPE _em_commission_type)
{
m_Commission_Percent = _commission_percent;
m_Commission_Ratio = m_Commission_Percent / 100. ;
m_em_Commission_Type = _em_commission_type;
}
int CCy_Commission_1::GetPoints_BreakEven(double _price_open, CyENUM_POSI_TYPE _em_posi_type)
{
int points_breakeven = 0;
double price_breakeven = 0; //
if(m_em_Commission_Type == em_CommissionType_OpenOnly)// ex. FXTM FX,Metal, NASDAQ etc,
{
if(_em_posi_type == em_PosiShort){
//EQUATION. (_price_open - price_breakeven) = _price_open*m_Commission_Ratio
price_breakeven = _price_open * ( 1. - m_Commission_Ratio) ;
points_breakeven = (_price_open - price_breakeven)/_Point;
}
else if(_em_posi_type == em_PosiLong){
//EQUATION. (price_breakeven - _price_open) = _price_open*m_Commission_Ratio
price_breakeven = _price_open * ( 1. + m_Commission_Ratio) ;
points_breakeven = (price_breakeven - _price_open)/_Point;
}
}
else if(m_em_Commission_Type == em_CommissionType_OpenCloseEach) // ex. BYBIT CryptoUSDT
{
if(_em_posi_type == em_PosiShort){
//EQUATION. (_price_open - price_breakeven) = _price_open * m_Commission_Ratio + price_breakeven * m_Commission_Ratio
// => price_breakeven*(1+m_Commission_Ratio) = _price_open*(1-m_Commission_Ratio)
// => price_breakeven = _price_open*(1-m_Commission_Ratio)/(1+m_Commission_Ratio)
price_breakeven = _price_open * ( 1. - m_Commission_Ratio)/(1.+m_Commission_Ratio) ;
points_breakeven = (_price_open - price_breakeven)/_Point;
}
else if(_em_posi_type == em_PosiLong){
//EQUATION. (price_breakeven - _price_open) = _price_open * m_Commission_Ratio + price_breakeven * m_Commission_Ratio
// => price_breakeven*(1-m_Commission_Ratio) = _price_open*(1+m_Commission_Ratio)
// => price_breakeven = _price_open*(1+m_Commission_Ratio)/(1-m_Commission_Ratio)
price_breakeven = _price_open * ( 1. + m_Commission_Ratio)/(1.-m_Commission_Ratio) ;
points_breakeven = (price_breakeven - _price_open)/_Point;
}
}
return points_breakeven;
}
@igotit-anything
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment