#property copyright "Open Source"
#property link      ""
#property version   "1.0"
#property indicator_plots 0
#property indicator_chart_window

input color               BidColor  = clrRed;   // Bid color
input color               AskColor  = clrGreen; // Ask color
input ENUM_LINE_STYLE     LineStyle  = 0;       // Line Style
input int                 LineLength = 18;      // Line Length 
input bool                ShowAsk    = true;    // Show Ask?
input bool                ShowBid    = true;    // Show Bid?

string Prefix = "Bid_Ask_Line";

int OnInit(void)
{
   return INIT_SUCCEEDED;
}

void OnDeinit(const int reason)
{
   del_obj();
}

int OnCalculate(const int rates_total,       // size of input time series
                const int prev_calculated,   // number of handled bars at the previous call
                const datetime& time[],      // Time array
                const double& open[],        // Open array
                const double& high[],        // High array
                const double& low[],         // Low array
                const double& close[],       // Close array
                const long& tick_volume[],   // Tick Volume array
                const long& volume[],        // Real Volume array
                const int& spread[])         // Spread array
{
   ArraySetAsSeries(time,true);
   double Bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);
   double Ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
   datetime currentTime = time[rates_total - 1];
   string AskName = Prefix+"_Ask";
   string BidName = Prefix+"_Bid";
   if (ShowAsk && ObjectFind(0,AskName) == -1)
      ObjectCreate(0,AskName,OBJ_TREND,0,0,0);
      ObjectSetDouble(0,AskName,OBJPROP_PRICE,0,Ask);
      ObjectSetDouble(0,AskName,OBJPROP_PRICE,1,Ask);
      ObjectSetInteger(0,AskName,OBJPROP_TIME,0,time[0]-PeriodSeconds(PERIOD_CURRENT)*LineLength);
      ObjectSetInteger(0,AskName,OBJPROP_TIME,1,time[0]+PeriodSeconds(PERIOD_CURRENT)*LineLength);
      ObjectSetInteger(0,AskName,OBJPROP_COLOR,AskColor);
      ObjectSetInteger(0,AskName,OBJPROP_STYLE,LineStyle);
      ObjectSetInteger(0,AskName,OBJPROP_BACK,false);
      ObjectSetInteger(0,AskName,OBJPROP_SELECTED,false);
      ObjectSetInteger(0,AskName,OBJPROP_SELECTABLE,false);
      ObjectSetInteger(0,AskName,OBJPROP_RAY_LEFT,false);
      ObjectSetInteger(0,AskName,OBJPROP_RAY_RIGHT,false);
      
   if (ShowBid && ObjectFind(0,BidName) == -1)
      ObjectCreate(0,BidName,OBJ_TREND,0,0,0);
      ObjectSetDouble(0,BidName,OBJPROP_PRICE,0,Bid);
      ObjectSetDouble(0,BidName,OBJPROP_PRICE,1,Bid);
      ObjectSetInteger(0,BidName,OBJPROP_TIME,0,time[0]-PeriodSeconds(PERIOD_CURRENT)*LineLength);
      ObjectSetInteger(0,BidName,OBJPROP_TIME,1,time[0]+PeriodSeconds(PERIOD_CURRENT)*LineLength);
      ObjectSetInteger(0,BidName,OBJPROP_COLOR,BidColor);
      ObjectSetInteger(0,BidName,OBJPROP_STYLE,LineStyle);
      ObjectSetInteger(0,BidName,OBJPROP_BACK,false);
      ObjectSetInteger(0,BidName,OBJPROP_SELECTED,false);
      ObjectSetInteger(0,BidName,OBJPROP_SELECTABLE,false); 
      ObjectSetInteger(0,BidName,OBJPROP_RAY_LEFT,false);
      ObjectSetInteger(0,BidName,OBJPROP_RAY_RIGHT,false);
      
      ChartRedraw(0);
   return(0);
}

//+------------------------------------------------------------------+
void del_obj() 
 {
   ObjectsDeleteAll(0,Prefix);
   ChartRedraw(0);
 }
