118 lines
		
	
	
	
		
			4.6 KiB
		
	
	
	
		
			MQL5
		
	
	
	
	
	
			
		
		
	
	
			118 lines
		
	
	
	
		
			4.6 KiB
		
	
	
	
		
			MQL5
		
	
	
	
	
	
//+------------------------------------------------------------------+
 | 
						|
//|                                           Average Price v3.0.mq4 |
 | 
						|
//|                                        Joca - nc32007a@gmail.com |
 | 
						|
//|                                              http://www.mql5.com |
 | 
						|
//+------------------------------------------------------------------+
 | 
						|
#property copyright "Joca"
 | 
						|
#property indicator_chart_window
 | 
						|
#include "..\\Includes\\CalculateBreakeven.mqh"
 | 
						|
#include"..\\Includes\\BreakEvenResult.mqh"
 | 
						|
                   // trade position object
 | 
						|
 | 
						|
//---
 | 
						|
 | 
						|
input bool includeBuys=false;
 | 
						|
input bool includeSells=true;
 | 
						|
input double profitTarget=0;
 | 
						|
input long magic=0;
 | 
						|
input double hedgeToBreakDownLots=0;
 | 
						|
input color font_color=clrWhite;
 | 
						|
input int font_size=12;
 | 
						|
 | 
						|
 | 
						|
//---
 | 
						|
int PipAdjust,NrOfDigits;
 | 
						|
double point;
 | 
						|
//+------------------------------------------------------------------+
 | 
						|
//|                                                                  |
 | 
						|
//+------------------------------------------------------------------+
 | 
						|
void OnInit()
 | 
						|
  {
 | 
						|
  
 | 
						|
   ObjectDelete(ChartID(),"Average_Price_Line_Sell"+Symbol());
 | 
						|
   ObjectDelete(ChartID(),"Information_Sell"+Symbol());
 | 
						|
   NrOfDigits=Digits();
 | 
						|
//---
 | 
						|
   if(NrOfDigits==5 || NrOfDigits==3) PipAdjust=10;
 | 
						|
   else
 | 
						|
      if(NrOfDigits==4 || NrOfDigits==2) PipAdjust=1;
 | 
						|
//---
 | 
						|
   point=Point()*PipAdjust;
 | 
						|
//---
 | 
						|
   
 | 
						|
//---
 | 
						|
   return;
 | 
						|
  }
 | 
						|
//+------------------------------------------------------------------+
 | 
						|
//|                                                                  |
 | 
						|
//+------------------------------------------------------------------+
 | 
						|
void OnDeinit(const int reason)
 | 
						|
  {
 | 
						|
   ObjectDelete(ChartID(),"Average_Price_Line_Sell"+Symbol());
 | 
						|
   ObjectDelete(ChartID(),"Information_Sell"+Symbol());
 | 
						|
   ObjectDelete(ChartID(),"Information_2Sell"+Symbol());
 | 
						|
  }
 | 
						|
//+------------------------------------------------------------------+
 | 
						|
//|                                                                  |
 | 
						|
//+------------------------------------------------------------------+
 | 
						|
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[])
 | 
						|
  {
 | 
						|
   
 | 
						|
//---
 | 
						|
  CalculateBreakeven breakEven;
 | 
						|
  BreakEvenInput breakEvenInput;
 | 
						|
  
 | 
						|
  breakEvenInput.Buys= includeBuys;
 | 
						|
  breakEvenInput.Sells= includeSells;
 | 
						|
  breakEvenInput.ProfitInMoney=profitTarget;
 | 
						|
  breakEvenInput.MagicNumber=magic;
 | 
						|
  breakEvenInput.HedgeToBreakDownLots=hedgeToBreakDownLots;
 | 
						|
  
 | 
						|
 BreakEvenResult breakevenResult=breakEven.GetBreakEven(breakEvenInput);
 | 
						|
//---
 | 
						|
   ObjectDelete(ChartID(),"Average_Price_Line_Sell"+Symbol());
 | 
						|
   ObjectDelete(ChartID(),"Information_Sell"+Symbol());
 | 
						|
//---
 | 
						|
   
 | 
						|
   ObjectDelete(ChartID(),"Average_Price_Line_Sell"+Symbol());
 | 
						|
   ObjectCreate(ChartID(),"Average_Price_Line_Sell"+Symbol(),OBJ_HLINE,0,0,breakevenResult.Average_Price);
 | 
						|
   ObjectSetInteger(ChartID(),"Average_Price_Line_Sell"+Symbol(),OBJPROP_WIDTH,1);
 | 
						|
//---
 | 
						|
   color cl=Blue;
 | 
						|
   if(breakevenResult.Net_Lots<0) cl=Red;
 | 
						|
   if(breakevenResult.Net_Lots==0) cl=White;
 | 
						|
//---
 | 
						|
   ObjectSetInteger(ChartID(),"Average_Price_Line_Sell"+Symbol(),OBJPROP_COLOR,cl);
 | 
						|
   ObjectCreate(ChartID(),"Information_Sell"+Symbol(),OBJ_LABEL,0,0,0);
 | 
						|
ObjectSetInteger(0,"Average_Price_Line_Sell"+Symbol(), OBJPROP_BACK,     true); 
 | 
						|
     ObjectSetInteger(0,"Information_Sell"+Symbol(), OBJPROP_BACK,     true); 
 | 
						|
   int x=0,y=0;
 | 
						|
   long result1=0;
 | 
						|
   ChartTimePriceToXY(0,0,time[rates_total-1],breakevenResult.Average_Price,x,y);
 | 
						|
   if(!ChartGetInteger(0,CHART_WIDTH_IN_PIXELS,0,result1))
 | 
						|
     {
 | 
						|
      //--- display the error message in Experts journal
 | 
						|
      Print(__FUNCTION__+", Error Code = ",GetLastError());
 | 
						|
     }
 | 
						|
//---
 | 
						|
   ObjectSetInteger(ChartID(),"Information_Sell"+Symbol(),OBJPROP_XDISTANCE,result1-150);
 | 
						|
   ObjectSetInteger(ChartID(),"Information_Sell"+Symbol(),OBJPROP_YDISTANCE,y);
 | 
						|
 ObjectSetInteger(0, "Information_Sell"+Symbol(),OBJPROP_FONTSIZE, 12);
 | 
						|
   string text = "s " +DoubleToString(breakevenResult.Net_Result,2)+" l "+NormalizeDouble(breakevenResult.Net_Lots,2)+" # "+breakevenResult.Net_Trades; ;
 | 
						|
   
 | 
						|
   ObjectSetString(ChartID(), "Information_Sell"+Symbol(), OBJPROP_TEXT, text);
 | 
						|
   ObjectSetInteger(0,"Information_Sell"+Symbol(), OBJPROP_COLOR,Red);
 | 
						|
   
 | 
						|
   
 | 
						|
   return(0);
 | 
						|
  }
 | 
						|
//+------------------------------------------------------------------+
 |