Showing open positions total Stop Loss and Take Profit values MT5 - MetaTrader 5 Expert - MetaTrader 5 Resources
This is an MT5 Expert Advisor that displays the total stop loss and take profit values of open positions.
This is Conor Dailey’s upgrade and modification of the previous old MT4 indicator. The website is https://www.mql5.com/en/code/23788
The expert advisor will not trade or modify any of your orders. It simply sums up all Stop Loss and Take Profit from all positions you currently hold and displays it in the lower left corner of the chart. When you modify or create a Stop Loss/Take Profit, the displayed value updates automatically.
You can attach this EA to all charts so that you can observe its values at any time.
#Property Copyright "Copyright 2021, mfx123 and Connor Daly" # Property version "1.00" #Property Description "No need to check anything below" #propertystrict # Property indicator chart window string all; double total_sl, total_tp; double prev_total_sl, prev_total_tp; string tag = "sltp" ; //+----------------------------------------------------------------------------------+ //|Expert initialization function | //+------------------------------------------------------------------+ Integer initialization () { Total_sl = GetTotalSLValue(); Total_tp = GetTotalTPValue(); ObjectCreate ( 0 , label, OBJ_LABEL , 0 , 0 , 0 ); ObjectSetInteger ( 0 ,label, OBJPROP_corner , cornerbottomleft ); ObjectSetInteger ( 0 , tag, OBJPROP_XDISTANCE , 0 ); ObjectSetInteger ( 0 , label, OBJPROP_Y distance , 50 ); object set integer ( 0 , label, OBJPROP_COLOR , clrgolden flower); Object set string ( 0 , label, OBJPROP_FONT , "Song Dynasty" ); ObjectSetInteger ( 0 , label, OBJPROP_FONTSIZE , 16 ); ObjectSetInteger ( 0 , tag, OBJPROP_HIDDEN , true ); ObjectSetInteger ( 0 , tag, OBJPROP_BACK , false ); ObjectSetInteger ( 0 , tag, OBJPROP_SELECTED , true ); ObjectSetInteger ( 0 , tag, OBJPROP_SELECTABLE , true ); ObjectSetInteger ( 0 , tag, OBJPROP_ZORDER , 0 ); displayinfo(); Return ( initialization successful ); } //+------------------------------------------------------------------+ //|Expert to initialize function | //+------------------------------------------------------------------+ Blank solution initialization ( constant integer reason) { ObjectDelete ( 0 , label); } //+------------------------------------------------------------------+ //|Expert check function | //+------------------------------------------------------------------+ Integer Get Multiplier ( String ) { integer meters = 0 ; integer digits = symbolinfointeger (s, SYMBOL_DIGITS ); if (number== 5 ) meters = 10000 ; if (number== 4 ) meters = 1000 ; if (number == 2 || number == 3 ) m = 100 ; if(number == 1 ) m = 10 ; return (meter); } //+------------------------------------------------------------------+ //| 10 ; else p = symbol information double (s , SYMBOL_POINT ); return (p); } // +------------------------------------------------------------------ + //| { Oolong position ticket = position acquisition ticket ( five ); if ( position acquisition ticket selection (position ticket )) { if ( position acquisition double ( position_SL ) ! = 0 ) { increment = ( symbol information double ( position acquisition string ( POSITION_SYMBOL ), SYMBOL_TRADE_TICK_VALUE ) / symbol information double ( position acquisition string ( POSITION_SYMBOL ), SYMBOL_TRADE_TICK_SIZE )) * GetPips2Dbl ( Position Get Double( POITION_SYMBOL )) ; sl_value = ((Math Ab(Position Get Double(POITION_PRICE_OPEN))--Position Get Double(Position_SL)) *delta) *Position Get Double(POITION_VOLUME ) ) sl_value = - ( sl_value ) ; total sl value + = sl value ; } } } return ( normalized double ( total sl value , 2 )); } //+------------------------------------------------------------------+ // | delta; for (integer v = total number of positions () - 1 ; v >= 0 ; v--) { own position ticket = position get ticket ( v); if (position by ticket selection (position ticket)) { if ( position get double ( POSITION_TP ) ! = 0 ) { increment = ( symbol information double (position get string ( POSITION_SYMBOL ), SYMBOL_TRADE_TICK_VALUE ) / symbol information double (ss="functions">Position Get String ( POSITION_SYMBOL ), SYMBOL_TRADE_TICK_SIZE )) * GetPips2Dbl ( Position Get String ( POSITION_SYMBOL )); tp_value = (( Mathematical Antibody ( Position Get Double ( POSITION_PRICE_OPEN ) -- Position Get Double ( POSITION_TP )) * Delta) * Position Get Double ( POSITION_VOLUME )) * get multiplier ( position get string ( POSITION_SYMBOL )); tp_value - = position get double ( position swap ); total tp_value += tp_value; } } } return ( normalized double (total TP value, 2 )); } //+--------------------------------------------------------------------------------+ //| + Double to String (Total_sl, 2 ) + " " + "TP: $" + Double to String (Total TP, 2 ); Object Set String ( 0 , Label, OBJPROP_TEXT , All); Chart Redraw ( 0 ); } //+--------------------------------------------------------------------------------+ //| | //+--------------------------------------------------------------------------------+ Blank Check () { Total_sl = GetTotalSLValue(); Total_tp = GetTotalTPValue(); if ((total_sl! = prev_total_sl) || (total_tp! = prev_total_tp)) { display information (); prev_total_sl =total_sl; prev_total_tp =total_tp; } } //+--------------------------------------------------------------------------------+
Attachment download
📎 display_total_stoploss_and_takeprofit_value.mq5 (5.81 KB)
Source: MQL5 #33903
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •