ProfitOnDrop

Download script
Author: Copyright � 2012 Matus German, www.MTexperts.net
ProfitOnDrop

This tool is designed to provide traders with an immediate visual calculation of potential profit or loss based on specific price points on a trading chart. It allows you to interact directly with your live market data to perform "what-if" scenarios in real-time.

How the Logic Works

Interactive Price Analysis The script functions by reacting to your actions on the chart. Instead of automatically calculating data, it waits for you to identify a specific price level. When you click and drop the tool onto the main chart window, the script captures the exact price and time at that specific coordinate.

Automated Profit Calculation Once a price point is selected, the tool instantly scans all your currently open trades. It looks specifically for positions held on the same currency pair or asset you are currently viewing. The logic then performs a comprehensive calculation:

  • For Buy Positions: It calculates how much profit would be gained (or loss incurred) if the price rose to your selected point.
  • For Sell Positions: It calculates the result based on the price dropping to your selected point.
  • Comprehensive Accounting: The calculation is not just a simple price difference; it factor in the quantity of shares/lots traded and includes swap fees to provide a more accurate financial picture.

Visual Feedback After performing the calculation, the script provides instant visual confirmation directly on your screen:

  1. Trend Line: It draws a horizontal line at your chosen price point to mark the area of interest.
  2. Financial Label: It places a text label at that exact spot showing the calculated profit or loss figure (rounded to two decimal places).
  3. Color Coding: To make the data easy to read at a glance, the tool uses a "Traffic Light" system. If the result of your selected price point would result in a profit, both the line and the text appear in Green. If the result shows a loss, they automatically change to Red.

Summary for the Trader

This script removes the need for manual math. It allows you to quickly visualize your "break-even" points or take-profit targets by simply clicking on the chart. It tells you exactly how much money is at stake at any given price level across all your active positions for that specific asset.

Orders Execution
Checks for the total of open orders
13 Views
0 Downloads
0 Favorites
ProfitOnDrop
//+------------------------------------------------------------------+
#property copyright "Copyright © 2012 Matus German, www.MTexperts.net"
//+------------------------------------------------------------------+

int start()
{

   if(WindowOnDropped()!=0)
   {
      Print("ProfitOnDrop must be applied to main chart window!");
      return(false);
   }
   
   double dropPrice=WindowPriceOnDropped();
   double dropTime=WindowTimeOnDropped();
   
   double profit=Profit(dropPrice);
   double curTime=TimeCurrent();

   ObjectCreate("POD_line"+curTime,OBJ_TREND,0,dropTime,dropPrice,curTime,dropPrice);
   ObjectSet("POD_line"+curTime,OBJPROP_RAY,false);
   
   ObjectCreate("POD_price"+curTime,OBJ_TEXT,0,dropTime,dropPrice);
   ObjectSetText("POD_price"+curTime,DoubleToStr(profit,2));
   ObjectSet("POD_price"+curTime,OBJPROP_PRICE1,dropPrice);
   ObjectSet("POD_price"+curTime,OBJPROP_FONTSIZE,12);
   
   if(profit>=0)
   {
      ObjectSet("POD_price"+curTime,OBJPROP_COLOR,Green);
      ObjectSet("POD_line"+curTime,OBJPROP_COLOR,Green);
   }
   else
   {
      ObjectSet("POD_price"+curTime,OBJPROP_COLOR,Red);
      ObjectSet("POD_line"+curTime,OBJPROP_COLOR,Red);
   }
   
   return(0);
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
double Profit(double targetPrice)
{
   double profit=0;
   int total  = OrdersTotal();
   
   for (int cnt = total-1 ; cnt >=0 ; cnt--)
   {
      OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
      if (OrderSymbol()==Symbol())
      {
         if(OrderType()==OP_BUY)
            profit+=(targetPrice-OrderOpenPrice())*MarketInfo(Symbol(),MODE_LOTSIZE)*OrderLots()+OrderSwap();
         if(OrderType()==OP_SELL) 
            profit+=(OrderOpenPrice()-targetPrice)*MarketInfo(Symbol(),MODE_LOTSIZE)*OrderLots()+OrderSwap();
      }
   }
   return(profit);        
}
//+------------------------------------------------------------------+

Comments