RiskReward Ratio

Download script
Author: Copyright � 2009, bgaiteiro
RiskReward Ratio

This tool is designed to help traders visually calculate and monitor their potential profit relative to their risk when entering a trade. It simplifies the math behind "Risk-to-Reward" ratios by automatically updating information on your trading chart based on the price levels you define.

Core Functionality

The script works by identifying two specific horizontal lines on your chart: one representing your Stop Loss (SL) and the other representing your Take Profit (TP). Once these are set, the tool performs the following actions:

  • Automatic Level Identification: The script looks for your designated price levels to determine where you intend to exit the market in both winning and losing scenarios.
  • Real-Time Ratio Calculation: It constantly monitors the current market price (the "Bid" price). It calculates the distance between your entry point and your Stop Loss (your risk) versus the distance between your entry point and your Take Profit (your potential reward).
  • Dynamic Visual Feedback: As the market moves, the tool recalculates this ratio instantly. It displays this information in two ways:
    1. A text comment directly on the chart area.
    2. A dedicated, customizable label placed in a specific corner of your screen (such as the lower left or upper right).

Key Features for the User

  • Customizable Display: You can personalize the appearance of the information, including the font size, font type, and color, ensuring the data is easy to read at a glance.
  • Positioning Flexibility: The tool allows you to choose which corner of your trading platform displays the primary ratio label, preventing it from overlapping with other important charts or indicators.
  • Clean Interface: When the indicator is removed from your chart, it automatically cleans up the visual space by deleting the labels and comments it created, leaving your workspace tidy.

Summary of Benefit

Instead of manually performing calculations every time the price moves, this script provides an instant "Risk/Reward" score. This allows you to see at a glance whether a trade setup meets your desired profitability standards—for example, identifying if you are aiming for a 1:2 or 1:3 reward for every unit of risk taken.

11 Views
0 Downloads
0 Favorites
RiskReward Ratio
//+------------------------------------------------------------------+
//|                                          Risk / Reward Ratio.mq4 |
//|                                                   Bruno Gaiteiro |
//|                                              bgaiteiro@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, bgaiteiro"
#property link      "bgaiteiro@gmail.com"

#property indicator_chart_window
//---- input parameters
extern string    SLLevel="SLPrice";
extern string    TPLevel="TPPrice";
  extern string note2 = "Default Font Color";
  extern color  FontColor = Black;
  extern string note3 = "Font Size";
  extern int    FontSize=20;
  extern string note4 = "Font Type";
  extern string FontType="Trebuchet MS";
  extern string note5 = "Display the price in what corner?";
  extern string note6 = "Upper left=0; Upper right=1";
  extern string note7 = "Lower left=2; Lower right=3";
  extern int    WhatCorner=2;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
IndicatorShortName("TSR");
   
   if (ObjectFind(SLLevel)==-1)
     {
      ObjectCreate(SLLevel,OBJ_HLINE,0,0,Close[0]);
      ObjectSet(SLLevel,OBJPROP_COLOR,Red);
     }
   if (ObjectFind(TPLevel)==-1)
     {
      ObjectCreate(TPLevel,OBJ_HLINE,0,0,Close[0]);
      ObjectSet(TPLevel,OBJPROP_COLOR,Green);
     }

   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
      ObjectDelete(SLLevel);
      ObjectDelete(TPLevel);
      ObjectDelete("RiskReward_ratio"); 
      Comment("");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   //----

   double   RiskReward_ratio=0, SL_price=0, TP_price=0;
   string   Text="";
   int i=0;

   if (ObjectFind(SLLevel)==-1) return(0);
   SL_price = ObjectGet(SLLevel, OBJPROP_PRICE1);
   if (ObjectFind(TPLevel)==-1) return(0);
   TP_price = ObjectGet(TPLevel, OBJPROP_PRICE1);
   
   RiskReward_ratio = (TP_price - Bid) / (Bid - SL_price);


   Text =   "Risk/Reward Ratio       1 : " + DoubleToStr(RiskReward_ratio,2) + "\n" ;

   Comment(Text);

   string RiskReward_ratio2 = DoubleToStr(RiskReward_ratio,2);
   ObjectCreate("RiskReward_ratio", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("RiskReward_ratio",  "1 : " + RiskReward_ratio2, FontSize, FontType, FontColor);
   ObjectSet("RiskReward_ratio", OBJPROP_CORNER, WhatCorner);
   ObjectSet("RiskReward_ratio", OBJPROP_XDISTANCE, 10);
   ObjectSet("RiskReward_ratio", OBJPROP_YDISTANCE, 10);
  
   return(0);
  }
//+------------------------------------------------------------------+

Comments