SL+TP-OE PIP CALC INDY
Download scriptThis script is designed to enhance your trading experience by providing a clear, visual representation of your active trades directly on the price chart. Rather than requiring you to constantly look at your trade history or account summary tabs, it calculates and displays your specific risk and reward levels in a way that is easy to read at a glance.
Core Functionality
The primary purpose of this script is to identify all open positions for the current asset you are trading and display their Stop Loss (SL) and Take Profit (TP) prices as text labels on the chart. This allows you to see exactly how many "pips" away your exit points are from your entry price while monitoring live market movements.
How it Works
- Automatic Detection: The script automatically scans all of your open trades. It filters these so that it only displays information for the specific currency pair or asset currently visible on your screen, ensuring your chart remains clean and relevant.
- Dynamic Distance Calculation: Instead of just showing the raw price (e.g., 1.2500), the script calculates the mathematical distance between your entry price and your profit/loss targets. It then converts this distance into "Pips" or "Fractional Pips," depending on your specific trading settings.
- Visual Identification: Each trade is assigned a unique label on the chart. You can choose whether to display the specific Order Ticket number next to these labels, which helps in identifying multiple positions held on the same asset.
- Customizable Display: The tool offers several aesthetic and functional options that you can adjust:
- Color Coding: You can set different colors for your Stop Loss and Take Profit labels (for example, making the Stop Loss yellow and the Take Profit blue) to make them instantly recognizable.
- Text Styling: You can adjust the size of the text and its horizontal positioning on the chart to ensure it fits perfectly with your layout.
- Precision Control: The logic detects whether your broker uses standard pips or fractional pips (points), ensuring that the distances displayed are accurate regardless of how many decimal places your broker provides.
Key Benefits
By using this script, you gain a more intuitive view of your trade management. It translates complex price data into simple, readable units, helping you monitor your risk-to-reward ratio in real-time without needing to perform any manual calculations while the market is moving.
#property copyright "Copyright @ 20011, File45 and anyone who want to add their 2 pence/cents/rupees worth"
#property indicator_chart_window
//thanks: miaden-super moderator FOREX-TSD www.forex-tsd.com for major edit after which it workedas as intended.
//http://www.forex-tsd.com/expert-advisors-metatrader-4/20171-please-fix-indicator-ea-34.html#post425056
//thanks: dabbler - MQL4/Forum http://forum.mql4.com/45267
//thanks: WHRoeder - ? as above
extern bool Show_SL = true;
extern color SL_Color = Yellow;
extern bool Show_TP = true;
extern color TP_Color = DodgerBlue;
extern int Text_Size =10;
extern int Move_Text_L_or_R =0;
extern bool Fractional_Pips = true;
extern bool Show_OrderTicket = true;
string Npips= " pips";
string Fpips= " fpips";
static string Pip_Distance="Pip+Distance";
static string text;
double pmod;
int p2p;
int dig;
int Xpips;
//---------------------------------------------------------------------
int init(){
if(Fractional_Pips==true){
pmod=Point;
p2p=1;
dig=0;
}
else{
pmod=Point*10;
p2p=10;
dig=1;
}
if(Digits==0){
pmod=Point;
p2p=1;
dig=0;
Xpips=1;
}
return(0);
}
//---------------------------------------------------------------------
int deinit(){
DeleteLabels(Pip_Distance);
return(0);
}
//---------------------------------------------------------------------
int start()
{
DeleteLabels(Pip_Distance);
int orders= OrdersTotal();
if( orders==0 ) return(0);
for (int n=0; n<orders; n++)
{
if (OrderSelect(n,SELECT_BY_POS))
if (OrderSymbol()==Symbol())
{
string name = Pip_Distance+OrderTicket()+"stop loss";
if(Show_SL==true)
CreateText(name,Time[((WindowFirstVisibleBar()-0)*Move_Text_L_or_R/100)],OrderStopLoss(),SL_Color,DoubleToStr(MathAbs((OrderStopLoss()-OrderOpenPrice())/pmod),dig));
name = Pip_Distance+OrderTicket()+"take profit";
if(Show_TP==true)
CreateText(name,Time[((WindowFirstVisibleBar()-0)*Move_Text_L_or_R/100)],OrderTakeProfit(),TP_Color,DoubleToStr(MathAbs((OrderTakeProfit()-OrderOpenPrice())/pmod),dig));
}
}
return(0);
}
//---------------------------------------------------------------------
//
//---------------------------------------------------------------------
void CreateText(string SL, datetime time1, double price, color theColor, string text)
{
if (price==0) return;
if (Fractional_Pips==true)
{
if(Xpips==1)
Npips=Npips;
else Npips=Fpips;
}
ObjectCreate(SL, OBJ_TEXT,0, time1, price);
if (Show_OrderTicket == true)
// this long gap takes the text to the right side of the screen
ObjectSetText(SL, " " + "#" + OrderTicket() + " * " + text + Npips, Text_Size, "Verdana", theColor);
else ObjectSetText(SL, " " + " " + text + Npips, Text_Size, "Verdana", theColor);
}
//---------------------------------------------------------------------
//
//---------------------------------------------------------------------
void DeleteLabels(string Pip_Distance)
{
for( int i=ObjectsTotal(); i>=0; i-- )
{
string SL=ObjectName(i); if (StringFind(SL,Pip_Distance,0) > -1 ) ObjectDelete(SL);
}
}
Comments