#property strict
string buylinename = "AvgBuyLine";
string selllinename = "AvgSellLine";
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
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[])
{
//---
ObjectCreate(0,buylinename,OBJ_HLINE,0,0,0);
ObjectSetInteger(0,buylinename,OBJPROP_COLOR,clrSkyBlue);
ObjectSetInteger(0,buylinename,OBJPROP_STYLE,STYLE_DASH);
ObjectCreate(0,selllinename,OBJ_HLINE,0,0,0);
ObjectSetInteger(0,selllinename,OBJPROP_COLOR,clrOrangeRed);
ObjectSetInteger(0,selllinename,OBJPROP_STYLE,STYLE_DASH);
//---
ObjectSetDouble(0,buylinename,OBJPROP_PRICE1,AvgOrdersPrice(OP_BUY));
ObjectSetDouble(0,selllinename,OBJPROP_PRICE1,AvgOrdersPrice(OP_SELL));
//Comment("BufferDown0 : ",, "BufferUp0 : ",bu_list[0]
// );
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double AvgOrdersPrice(int type)
{
double totalPriceLot = 0 ;
double totalLots = 0 ;
double avgPrice = 0 ;
for(int i=0; i<OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS))
{
if(OrderSymbol() == Symbol() && OrderType() == type)
{
totalPriceLot += OrderOpenPrice()*OrderLots() ;
totalLots += OrderLots() ;
}
}
}
if(totalLots >0)
{
avgPrice = totalPriceLot/totalLots;
}
return(avgPrice);
}
//+------------------------------------------------------------------+