Posts

MQL5: MAX TRADES , RISK BASED LOTSIZE implementation

 //+------------------------------------------------------------------+ //|                                       SachinMarketingProject.mq5 | //|                                  Copyright 2025, MetaQuotes Ltd. | //|                                             https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2025, MetaQuotes Ltd." #property link      "https://www.mql5.com" #property version   "1.00" #include <Trade\Trade.mqh> CTrade trade; input int MagicNumber=12345; input double lotsize=3; input string INFO1="Moving Average settings"; input int MA_Period=20; input ENUM_MA_METHOD ...

Python True Data Integration (2025)

  import os import logging import time from dotenv import load_dotenv from truedata import TD_live   # official TrueData client load_dotenv () # ---- helpers ---- def _to_kv_string ( obj ):     try :         items = {k: v for k , v in vars ( obj ). items () if not k . startswith ( "_" ) }     except Exception:         return repr ( obj )     # stringify safely     def s ( v ):         try :             return str ( v )         except Exception:             return repr ( v )     return " " . join ( f " { k } = { s ( items [ k ]) } " for k in sorted ( items )) def _first_pair ( values ):     # Accept shapes like [(price, qty)] or [price, qty]     try :         if isinstance ( values , list ) and values:      ...

MQL5 : Risk percentage based lotsize XAUUSD

 double calculate_lot(double ep, double sl,double contractSize)   {    double accountBal=AccountInfoDouble(ACCOUNT_BALANCE);    double riskval= accountBal* riskpercentage* 0.01;    Print("account bal: "+accountBal);    Print("riskval: "+riskval);    double diff_ep_sl=MathAbs(ep-sl);    Print("diff_ep_sl: "+diff_ep_sl);    diff_ep_sl=diff_ep_sl*contractSize;    Print("diff_ep_sl * 100: "+diff_ep_sl);    lots=riskval/diff_ep_sl;    lots= NormalizeDouble(lots, 2);    Print("lots : "+lots);    return lots;   }

MQL5 : Calculate lotsize based on risk

// devide risk percentage by  risk=RiskPer/10; ddouble CalculateLotSize(double entryPrice, double stopLossPrice, double riskPercent)   {    double tickSize       = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_SIZE);    double tickValue      = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE);    double lotStep        = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_STEP);    double minLot         = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MIN);    double maxLot         = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MAX);    double equity         = AccountInfoDouble(ACCOUNT_BALANCE);    double slPriceDiff    = MathAbs(entryPrice - stopLossPrice);    double riskAmount     = equity * riskPercent / 100.0;    if(tickSize == 0 || tickValue == 0 || sl...

MQL5 : Get current trading session

 datetime now = TimeCurrent(); // Get current broker time    MqlDateTime tm;    TimeToStruct(now, tm); // Convert datetime to structure    int currentHourBroker = tm.hour; // Extract hour    datetime utcNow = TimeGMT();    int brokerOffset = (int)((now - utcNow) / 3600);    string currentSession = "";    if(currentHourBroker >= (8 + brokerOffset) && currentHourBroker < (13 + brokerOffset))       currentSession = "London";    else       if(currentHourBroker >= (13 + brokerOffset) && currentHourBroker < (22 + brokerOffset))          currentSession = "New York";       else          if((currentHourBroker >= (22 + brokerOffset) && currentHourBroker <= 23) ||             (currentHourBroker >= 0 && currentHourBroker < (9 + brokerOff...

MQL5: Sachin Range Algo

 //+------------------------------------------------------------------+ //|                                                  Range Hedge.mq5 | //|                                  Copyright 2024, MetaQuotes Ltd. | //|                                             https://www.mql5.com | //+------------------------------------------------------------------+ #include <Trade\Trade.mqh> CTrade trade; datetime lastTradeExitTime = 0; #property copyright "Copyright 2024, MetaQuotes Ltd." #property link      "https://www.mql5.com" #property version   "1.00" bool Positional=false; input string TradeStartTime = "00:00"; input int NumberOfCandle=...

MQL5: Normalize price to nearest tick price (for stoploss and target)

 double NormalizePrice(double price)   {    double m_tick_size=SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_SIZE);    return(NormalizeDouble(MathRound(price/m_tick_size)*m_tick_size,_Digits));   }