← К каталогу
Исходный код · ID 4998

d1_w1_mn1_ranges.mq5

Вы автор или правообладатель?

Сообщите нам, если считаете, что материал размещён без разрешения.

Поиск по коду файла

#property indicator_chart_window
string IndicatorName = "D1_W1_MN1_Ranges";
#property strict

const int ZEROSTART   = 0;
const int NOSHIFT     = 0;
const int CHARTWINDOW = 0;
const int NOTIME      = NULL;  // Same as zero
const string  NL      = "\n";

enum BAR_SHIFT { BAR_ZERO, BAR_ONE };
extern bool   Daily_Line_On                   = true;   // Turn the line on and off
extern int    Daily_Range_Period              = 24;
extern bool   Weekly_Line_On                  = true;   // Turn the line on and off
extern int    Weekly_Range_Period             = 24;
extern bool   Monthly_Line_On                 = true;   // Turn the line on and off
extern int    Monthly_Range_Period            = 24;
extern BAR_SHIFT BAR_TO_USE                   = BAR_ONE;  // Use the forming bar, or the first complete bar
extern string Lines_Settings                  = "Lines Settings:"; 
extern color  dayHighLineClr                  = clrSalmon;
extern color  dayLowLineClr                   = clrSkyBlue;
extern color  weekHighLineClr                 = clrCrimson;
extern color  weekLowLineClr                  = clrRoyalBlue;
extern color  monthHighLineClr                = clrIndianRed;
extern color  monthLowLineClr                 = clrLightCoral;
extern ENUM_LINE_STYLE Line_Style             = STYLE_SOLID;    
extern int    LineThickness                   = 2;
extern string Line_Labels_FontStyle    = "Verdana";
extern int    Line_Labels_FontSize     = 10;

enum           LINEOBJECTS            { HI_TODAY,    LOW_TODAY,  HI_WEEK,    LOW_WEEK,  HI_MONTH,    LOW_MONTH, endLineObjects};  // Array Index to the 6 lines input properties
enum  LINE_MODE { LOW_LINE, HIGH_LINE };  // The lines can either show the high or the low of the range
const string   lineNames[]          = {"High_Today","Low_Today","High_Week","Low_Week","High_Month","Low_Month"};  // Give the lines nanmes
bool  lineSwitch[endLineObjects];   // Controls if a line is displayed or not.  Take the use input for a line being on or off
color lineColors[endLineObjects];   // Controls each lines color.  Take the use input for the line colors             
int   rangeBars[endLineObjects];    // Number of Bars to average for Range Average.
const ENUM_TIMEFRAMES linePeriods[] = { PERIOD_D1,   PERIOD_D1,  PERIOD_W1,  PERIOD_W1, PERIOD_MN1,  PERIOD_MN1};  // Array to store the timeframes for the lines
const LINE_MODE seriesMode[]        = { HIGH_LINE,   LOW_LINE,   HIGH_LINE,  LOW_LINE,  HIGH_LINE,   LOW_LINE};    // Array to indicate if the line is to be at the top of the range, or at the bottom

class RangeLine  // There will be an instance of this class for each range line (6 if all the lines are on)
 {
   private:
      static int      uniqueNumber;         // A Number to ensure names are unique to this indicator
      string          lineName;             // Name of the line
      color           lineColor;            // Color of ghe line
      int             lineWeight;           // weight of the line
      ENUM_LINE_STYLE lineStyle;            // The style of he line
      ENUM_TIMEFRAMES rangePeriod;          // Period for Locating the line
      LINE_MODE       lineMode;             // HIGH_LINE or LOW_LINE
      BAR_SHIFT       rangeBar;             // Bar to use to find a range on 
      datetime        startTime, endTime;   // Time for the line to start and end
      double          startPrice,endPrice;  // Price for the line to start ane end
      datetime        barZeroTime;          // New Bar Detection for updateing line endpoints and numbers.

      string          lineLabelText;  // Text to display on the line
      ENUM_ANCHOR_POINT anchorPoint;        // Where to anchor the line text
      string          labelName;            // Name of the label objet
      int             labelSize;            // Font size of the label object
      string          labelStyle;           // Font style of the label object.
      int             barsToAverage;        // Number of bar' High or Lows to aveage.
      double          barsAverage;          // Hold the average High or Low for the bars. 
      ENUM_ANCHOR_POINT SetlabelAnchor(void);       // Sent the anchorPoint value
      void GetLabelAnchorPoint(datetime&, double&); // create the time and price values to anchor the lable object
      string CreateLineLabelText(void);             // set lineLabelText
      double          GetBarsAverage(void); // find the average of barsToAverage bars, and store it in barsAverage.
   protected:
      void PeriodBarZeroUpdates(void);      // Set the start and end point values
      void CreateLine(void);                // Create the line and set it's attributes
      void MoveLine(void);                  // Put the line in positions
      string MakeLabelText(void);           // Make the label text that will be displayed
      void CreateLineLabel(void);           // Place the label on the display
      void UpdateLineLabel(void);           // Move the lable to the current position
      void SetTheEndTime(void);             // Sets line End Point based on the Chart (not range period) timeframe.
   public:
      void ~RangeLine(void); // A Public Destructor
      void RangeLine(string objName, color objColor, int strokeWeight, ENUM_LINE_STYLE lineType,
                     ENUM_TIMEFRAMES workingPeriod, LINE_MODE HIGH_LOW, BAR_SHIFT aBar,
                     string textStyle, int textSize, int barsToCount);                             // A Pulblic Constructor
      void UpdateLine(void);                // update the line
      string GetInstanceInfo(void);         // Get an instance information string
 };
static int RangeLine::uniqueNumber = 863;   // Initialize static (global) class unique number
RangeLine *managedLines[];                  // Make an array of the lines

int OnInit()
 {
      // код доступен только после оплаты
   }

void OnDeinit(const int reason)
 {
   EventKillTimer();                   //--- destroy timer
   int arraySize = ArraySize(managedLines);  // Find the number of line instances
   for ( int i = 0; i < arraySize; i++ )  
    {
      delete(managedLines[i]);  // delete the line objects
    }
 }

void OnTimer()
 {
   for ( int i = 0; i < ArraySize(managedLines); i++ )
    {
      managedLines[i].UpdateLine();  // Update on timer; If a new bar occurs without a tick, it will still be updated at 'timer' frequency.
    }
 }

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[] )
 {
      // код доступен только после оплаты
   }

ENUM_ANCHOR_POINT RangeLine::SetlabelAnchor(void)  // select the anchor type for the range line description text.
 {
    ENUM_ANCHOR_POINT anchorValue;
    switch (rangePeriod)
    {
      case PERIOD_D1:
         switch (lineMode)
          {
            case HIGH_LINE:
               anchorValue = ANCHOR_RIGHT_UPPER;
               break;
            case LOW_LINE:
               anchorValue = ANCHOR_RIGHT_LOWER;
               break;
            default:
               anchorValue = ANCHOR_RIGHT;
               break;
          }
         break;
      case PERIOD_W1:
         switch (lineMode)
          {
            case HIGH_LINE:
               anchorValue = ANCHOR_RIGHT_UPPER;
               break;
            case LOW_LINE:
               anchorValue = ANCHOR_RIGHT_LOWER;
               break;
            default:
               anchorValue = ANCHOR_RIGHT;
               break;
          }
         break;
      case PERIOD_MN1:
         switch (lineMode)
          {
            case HIGH_LINE:
               anchorValue = ANCHOR_LEFT_UPPER;
               break;
            case LOW_LINE:
               anchorValue = ANCHOR_LEFT_LOWER;
               break;
            default:
               anchorValue = ANCHOR_RIGHT;
               break;
          }
         break;
      default:
         anchorValue = ANCHOR_RIGHT;
         Print("Text Anchor Defalted to ANCHOR_RIGHT, due to invalid Period value: ", IntegerToString(rangePeriod)); 
         break;
    }
   return(anchorValue);
 }
void RangeLine::GetLabelAnchorPoint(datetime& anchorTime, double& anchorPrice)  // Set the values for the Anchor Point (where the line label text will be displayed)
 {
    datetime timeFirstVisibleBar = iTime(Symbol(),Period(),WindowFirstVisibleBar()-1);  // find the time of the first visible time on the chart
    switch (rangePeriod)
    {
      case PERIOD_D1:
         switch (lineMode)
          {
            case HIGH_LINE:
               anchorTime  = endTime;
               anchorPrice = endPrice-(5*Point);
               break;
            case LOW_LINE:
               anchorTime  = endTime;
               anchorPrice = endPrice+(5*Point);
               break;
        

Показано первые 50% кода (символов: 15375)