pipvaluecalculatorv1_02

Author: Open Source 2015, by Stuart Browne (Filter)
pipvaluecalculatorv1_02

This tool is designed as a practical utility for traders using the MetaTrader platform to understand the exact monetary value of price movements. Its primary purpose is to translate abstract market fluctuations into real-world figures based on your specific account details and the asset you are trading.

Core Functionality

The script automatically calculates how much money your account will gain or lose for every "pip" or "point" the price moves. This is essential for accurate risk management, as different currency pairs, commodities, and assets have varying values depending on their specific market dynamics.

How the Logic Works

To provide these calculations, the script performs the following steps:

  • Account Identification: It identifies your base deposit currency (e.g., USD, EUR) so that all results are shown in the currency you actually use.
  • Broker Adjustment: The logic detects whether your broker uses 3-digit or 5-digit pricing (common in modern forex markets). It automatically adjusts its internal math to ensure that "pips" are calculated correctly regardless of how many decimal places your broker displays.
  • Dynamic Calculation: The script looks at three specific variables:
    1. The Lot Size you have selected.
    2. The Tick Value (the raw value of the smallest price change).
    3. The Tick Size (the actual size of that smallest move).
  • Real-Time Conversion: By combining these variables, it produces two distinct values:
    • Point Value: The monetary value of the smallest possible price increment.
    • Pip Value: The monetary value of a standard pip.

User Experience

Instead of requiring you to perform manual math, the script handles all the conversions instantly. It displays a clean summary directly on your trading chart, showing:

  • Your active deposit currency.
  • The lot size being used for the calculation.
  • A clear breakdown of exactly how much money is at stake per point and per pip for the current symbol.

This allows you to quickly see the financial impact of a trade before you enter it, helping you manage your risk with precision.

6 Views
0 Downloads
0 Favorites
pipvaluecalculatorv1_02
//+------------------------------------------------------------------+
//|                                           PipValueCalculator.mq4 |
//|                           Copyright 2015, Stuart Browne (Filter) |
//|                             https://www.mql5.com/en/users/filter |
//+------------------------------------------------------------------+

// Version History
// ---------------
// V1.01 - corrected formula for calculating points and pips
// V1.02 - further refinement to calculation for clarity

#property copyright    "Open Source 2015, by Stuart Browne (Filter)"
#property link         "https://www.mql5.com/en/users/filter"
#property version      "1.02"
#property description  "Provided free of charge and free of copyright to the MQL community by Filter\n"
#property description  "A very simple calculator for you to calculate the value of 1 point and 1 pip in your"
#property description  "base (deposit) currency.\n"
#property description  "Either use the calculator 'as is' for a handy tool or adapt the main formula for use"
#property description  "in your own EA money management strategies."
#property strict
#property indicator_chart_window

extern double LotSize=1;   // Lot Size
double point;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

int OnInit()
  {
// Broker digits
   point=Point;
   if((Digits==3) || (Digits==5))
     {
      point*=10;
     }

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator de-init function                         |
//+------------------------------------------------------------------+  

void OnDeinit(const int reason)
  {
   Comment("");   // Cleanup

   Print(__FUNCTION__,"_UninitReason = ",getUninitReasonText(_UninitReason));
   return;
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   string CommentString="";
   string DepositCurrency=AccountInfoString(ACCOUNT_CURRENCY);
   
   double PipValue=(((MarketInfo(Symbol(),MODE_TICKVALUE)*point)/MarketInfo(Symbol(),MODE_TICKSIZE))*LotSize);
   double PointValue=PipValue/10;

   CommentString+="\n" + "Your deposit currency: " + DepositCurrency + "\n";
   CommentString+="Lot size requested: " + DoubleToStr(LotSize,2) + "\n";
   CommentString+="-----------------------------------------------------------------\n";
   CommentString+="Value of one point (" + Symbol() + "):  $" + DepositCurrency + " " + DoubleToStr(PointValue,3) + "\n";
   CommentString+="Value of one pip    (" + Symbol() + ") : $" + DepositCurrency + " " + DoubleToStr(PipValue,3) + "\n";
   CommentString+="-----------------------------------------------------------------\n";

   Comment(CommentString);

//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| Custom functions                                                 |
//+------------------------------------------------------------------+

string getUninitReasonText(int reasonCode) // Return reason for De-init function 
  {
   string text="";

   switch(reasonCode)
     {
      case REASON_ACCOUNT:
         text="Account was changed";break;
      case REASON_CHARTCHANGE:
         text="Symbol or timeframe was changed";break;
      case REASON_CHARTCLOSE:
         text="Chart was closed";break;
      case REASON_PARAMETERS:
         text="Input-parameter was changed";break;
      case REASON_RECOMPILE:
         text="Program "+__FILE__+" was recompiled";break;
      case REASON_REMOVE:
         text="Program "+__FILE__+" was removed from chart";break;
      case REASON_TEMPLATE:
         text="New template was applied to chart";break;
      default:text="Another reason";
     }

   return text;
  }
//+------------------------------------------------------------------+

Comments