Posts

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));   }

MQL5: Closed order detail

 void lastclosedorder()   {    uint TotalNumberOfDeal = HistoryDealsTotal();    ulong Ticket = 0;    long OrderType, DealEntry, Reason;    string MySymbol = "";    double price = 0, stoploss = 0, target = 0;    double ltp = iClose(Symbol(), PERIOD_CURRENT, 0); // Last tick price or market price // Persistent static array to store processed tickets    static ulong ProcessedTickets[];    static int ProcessedTicketsCount = 0;    HistorySelect(0, TimeCurrent()); // Select the history for the current time range    for(uint i = 0; i < TotalNumberOfDeal; i++)      {       // Get the ticket ID       if((Ticket = HistoryDealGetTicket(i)) > 0)         {          // Check if this ticket has already been processed          if(IsTicketProcessed(Ticket, ProcessedTickets, Pr...

BuySEll scalp

 //+------------------------------------------------------------------+ //|                                                 BuySellScalp.mq5 | //|                                  Copyright 2024, MetaQuotes Ltd. | //|                                             https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2024, MetaQuotes Ltd." #property link      "https://www.mql5.com" #property version   "1.00" #define REASON_SL 2 #include <Trade\Trade.mqh> CTrade trade; input string TradeStartTime = "00:00"; input string TradeStopTime = "13:25"; input bool Monday = tr...

MQL5: Create Buy and Sell arrow

 void buydraw()   {    string arrowName="BUYSIGNAL"+iTime(Symbol(),PERIOD_CURRENT,0);    ObjectCreate(Symbol(),arrowName,OBJ_ARROW_BUY,0,iTime(Symbol(),PERIOD_CURRENT,1),iHigh(Symbol(),PERIOD_CURRENT,1));    ObjectSetInteger(0, arrowName, OBJPROP_COLOR, clrLimeGreen);   } //+------------------------------------------------------------------+ //|                                                                  | //+------------------------------------------------------------------+ void selldraw()   {    string arrowName="SELLSIGNAL"+iTime(Symbol(),PERIOD_CURRENT,0);    ObjectCreate(Symbol(),arrowName,OBJ_ARROW_SELL,0,TimeCurrent(),iHigh(Symbol(),PERIOD_CURRENT,1));    ObjectSetInteger(0, arrowName, OBJPROP_COLOR, clrGold);   } //+-----------...