Navigation´╝ÜHome > Content >

AskBidLine.mq4

Time: 2013-07-26 | Download file:AskBidLine.mq4

//+------------------------------------------------------------------+
//|                                                   AskBidLine.mq4 |
//|                                  Copyright 2015, Vasiliy Sokolov |
//|                                https://www.mql5.com/ru/users/c-4 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, Vasiliy Sokolov"
#property link      "https://www.mql5.com/ru/users/c-4"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_color1 clrRed
#property indicator_style1 STYLE_DOT
#property indicator_type1 DRAW_LINE
//+------------------------------------------------------------------+
//| Buffer of Ask or Bid line                                        |
//+------------------------------------------------------------------+
double ask[];
//+------------------------------------------------------------------+
//| Type of price                                                    |
//+------------------------------------------------------------------+
enum ENUM_TYPE_ASKBID
{
   TYPE_ASK,   // Ask
   TYPE_BID    // Bid
};

input ENUM_APPLIED_PRICE AppPrice = PRICE_OPEN;       // Applied Price
input ENUM_TYPE_ASKBID   TypeAskBid = TYPE_ASK;       // Type of price
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0, ask, INDICATOR_DATA);
//---
   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[])
  {
//---
   ArraySetAsSeries(ask, false);
   ArraySetAsSeries(open, false);
   ArraySetAsSeries(high, false);
   ArraySetAsSeries(close, false);
   ArraySetAsSeries(low, false);
   double spreading = 0.0;
   if(TypeAskBid == TYPE_ASK)
      spreading = NormalizeDouble(Ask-Bid, Digits());
   switch(AppPrice)
   {
      case PRICE_OPEN:
         for(int i = prev_calculated; i < rates_total; i++)
            ask[i] = open[i] + spreading;
         break;
      case PRICE_HIGH:
         for(int i = prev_calculated; i < rates_total; i++)
            ask[i] = high[i] + spreading;
         break;
      case PRICE_LOW:
         for(int i = prev_calculated; i < rates_total; i++)
            ask[i] = low[i] + spreading;
         break;
      case PRICE_CLOSE:
         for(int i = prev_calculated; i < rates_total; i++)
            ask[i] = close[i] + spreading;
         break;
      case PRICE_MEDIAN:
         for(int i = prev_calculated; i < rates_total; i++)
            ask[i] = (high[i] + open[i])/2.0 + spreading;
         break;
      case PRICE_TYPICAL:
         for(int i = prev_calculated; i < rates_total; i++)
            ask[i] = (high[i] + low[i] + close[i])/3.0 + spreading;
         break;
      case PRICE_WEIGHTED:
         for(int i = prev_calculated; i < rates_total; i++)
            ask[i] = (open[i] + high[i] + low[i] + close[i])/4.0 + spreading;
         break;
   }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

Recommend