0 Views
0 Downloads
0 Favorites
ShowGAP
//+------------------------------------------------------------------+
//|                                                      ShowGAP.mq4 |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2014, AST"
#property  link      "Russia"
//---- indicator settings
#property indicator_chart_window
#property description "Îòîáðàæàåò íà ãðàôèêå ðàçðûâû öåíû"
#property strict

extern int   SizeGAP        = 2;      // Ðàçìåð ÃÝÏà
extern color ColorUp        = clrBlue;
extern color ColorDown      = clrRed;
extern int   LineWidth      = 3;

#define PREFIX                        "GAP_"       // Ïðåôèêñ ãðàôè÷åñêèõ îáúåêòîâ,..
#define SIGN_TREND_LINE               "TR_LINE_"   // Ïðèçíàê îáúåêòà "òðåíäîâàÿ ëèíèÿ"

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
  return(0);
}
//+-----------------------------------------------------------------------------+
//| Custom indicator deinitialization function
//+-----------------------------------------------------------------------------+
int deinit()
{
  DeleteAllObjects();
  return(0);
}
//+------------------------------------------------------------------+
//| Start                                                            |
//+------------------------------------------------------------------+
int start()
{
  int limit;
  int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
  if(counted_bars>0) counted_bars--;
  limit=Bars-counted_bars;
  if(counted_bars==0) limit-=1+1;

  for(int i=1; i<limit; i++)
  {
    if (Close[i+1] > Open[i+1]) //up bar
    {
      if (Close[i] > Open[i] && NormalizeDouble((Open[i]-Close[i+1])/Point,0) >= SizeGAP)
        ShowTrendLine(i,Time[i+1],Close[i+1],Time[i-1],ColorUp,LineWidth);
      if (Close[i] < Open[i] && NormalizeDouble((Close[i]-Close[i+1])/Point,0) >= SizeGAP)
        ShowTrendLine(i,Time[i+1],Close[i+1],Time[i-1],ColorUp,LineWidth);
      if (Close[i] < Open[i] && NormalizeDouble((Open[i+1]-Open[i])/Point,0) >= SizeGAP)
        ShowTrendLine(i,Time[i+1],Open[i+1],Time[i-1],ColorUp,LineWidth);
      if (Close[i] > Open[i] && NormalizeDouble((Open[i+1]-Close[i])/Point,0) >= SizeGAP)
        ShowTrendLine(i,Time[i+1],Open[i+1],Time[i-1],ColorUp,LineWidth);
    }
    if (Close[i+1] < Open[i+1]) //down bar
    {
      if (Close[i] < Open[i] && NormalizeDouble((Close[i+1]-Open[i])/Point,0) >= SizeGAP)
        ShowTrendLine(i,Time[i+1],Close[i+1],Time[i-1],ColorDown,LineWidth);
      if (Close[i] > Open[i] && NormalizeDouble((Close[i+1]-Close[i])/Point,0) >= SizeGAP)
        ShowTrendLine(i,Time[i+1],Close[i+1],Time[i-1],ColorDown,LineWidth);
      if (Close[i] > Open[i] && NormalizeDouble((Open[i]-Open[i+1])/Point,0) >= SizeGAP)
        ShowTrendLine(i,Time[i+1],Open[i+1],Time[i-1],ColorDown,LineWidth);
      if (Close[i] < Open[i] && NormalizeDouble((Close[i]-Open[i+1])/Point,0) >= SizeGAP)
        ShowTrendLine(i,Time[i+1],Open[i+1],Time[i-1],ColorDown,LineWidth);
    }
  }
  return(0);
}

//+-----------------------------------------------------------------------------+
//| Îòîáðàæåíèå òðåíäîâîé ëèíèè
//+-----------------------------------------------------------------------------+
void ShowTrendLine(int index, datetime leftTime, double leftPrice, datetime rightTime, color clr, int w)
{
  string name = PREFIX + SIGN_TREND_LINE + DoubleToStr(index,0) + "_" + (string)leftTime;

  if (ObjectFind(name) < 0)
  {
    ObjectCreate(name, OBJ_TREND, 0, leftTime, leftPrice, rightTime, leftPrice);
    ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID);
    ObjectSet(name, OBJPROP_COLOR, clr);
    ObjectSet(name, OBJPROP_WIDTH,w); 
    ObjectSet(name, OBJPROP_BACK, true);
    ObjectSet(name, OBJPROP_RAY, false);
    return;
  }
   
  ObjectMove(name, 0, leftTime, leftPrice);
  ObjectMove(name, 1, rightTime, leftPrice);
}

//+-----------------------------------------------------------------------------+
//| Óäàëåíèå âñåõ îáúåêòîâ, ñîçäàííûõ ïðîãðàììîé
//+-----------------------------------------------------------------------------+

void DeleteAllObjects()
{
  for (int i = ObjectsTotal() - 1; i >= 0; i--)     
    if (StringSubstr(ObjectName(i), 0, StringLen(PREFIX)) == PREFIX)
      ObjectDelete(ObjectName(i));
}

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---