Author: Copyright � 2012, Ivan Kornilov. All rights reserved.
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
SimpleBars
//+------------------------------------------------------------------+
//|                                                    SimpleBars.mq4|
//|                                                  excelf@gmail.com|
//+------------------------------------------------------------------+
#property copyright "Copyright © 2012, Ivan Kornilov. All rights reserved."
#property link "excelf@gmail.com"

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Red
#property indicator_color2 Green
#property indicator_color3 Red
#property indicator_color4 Green

#define SIGNAL_NONE        0//Ïóñòîé ñèãíàë
#define SIGNAL_BUY         1//Ñèãíàë íà ïîêóïêó 
#define SIGNAL_SELL       -1//Ñèãíàë íà ïðîäàæó 
#define SIGNAL_TRADE_ALLOW 3//Ñèãíàë ðàçðåøàþùèé òîðãîâëþ


extern int period=6;
extern bool useClose=true;
extern int width=1;

double bufferRed1[];
double bufferGreen1[];
double bufferRed2[];
double bufferGreen2[];
double trand[];
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init() 
  {
   IndicatorBuffers(5);

   SetIndexBuffer(0,bufferRed1);
   SetIndexBuffer(1,bufferGreen1);
   SetIndexBuffer(2,bufferRed2);
   SetIndexBuffer(3,bufferGreen2);
   SetIndexBuffer(4,trand);

   IndicatorDigits(Digits+1);
   SetIndexStyle(0,DRAW_HISTOGRAM,0,1);
   SetIndexStyle(1,DRAW_HISTOGRAM,0,1);
   SetIndexStyle(2,DRAW_HISTOGRAM,0,width);
   SetIndexStyle(3,DRAW_HISTOGRAM,0,width);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start() 
  {
   int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   int limit=Bars-counted_bars;
   if(counted_bars==0) limit-=1+period;

   int j;
   double buyPrice;
   double sellPrice;
   for(int i=limit-1; i>=0; i--) 
     {
      if(useClose) 
        {
         buyPrice=Close[i];
         sellPrice=Close[i];
           } else {
         buyPrice=Low[i];
         sellPrice=High[i];
        }
      if(trand[i+1]==SIGNAL_NONE || trand[i+1]==EMPTY_VALUE) 
        {
         if(Close[i]>Open[i]) 
           {
            trand[i]=SIGNAL_BUY;
              } else {
            trand[i]=SIGNAL_SELL;
           }
           } else {
         if(trand[i+1]==SIGNAL_BUY) 
           {
            if(buyPrice>Low[i+1]) 
              {
               trand[i]=SIGNAL_BUY;
                 } else {
               for(j = 2; j <= period; j++) 
                 {
                  if(buyPrice>Low[i + j]) 
                    {
                     trand[i]=SIGNAL_BUY;
                     break;
                       } else {
                     trand[i]=SIGNAL_SELL;
                    }
                 }
              }
              } else if(trand[i+1]==SIGNAL_SELL) {
            if(sellPrice<High[i+1]) 
              {
               trand[i]=SIGNAL_SELL;
                 } else {
               for(j = 2; j<= period; j++) 
                 {
                  if(sellPrice<High[i+j]) 
                    {
                     trand[i]=SIGNAL_SELL;
                     break;
                       } else {
                     trand[i]=SIGNAL_BUY;
                    }
                 }
              }
           }
        }

      if(trand[i]==SIGNAL_SELL) 
        {//RED BAR 
         bufferRed1[i]=High[i];
         bufferGreen1[i]= Low[i];
         bufferRed2[i]  = MathMax(Open[i],Close[i]);
         bufferGreen2[i]= MathMin(Open[i],Close[i]);
           } else if(trand[i]==SIGNAL_BUY) {
         bufferRed1[i]=Low[i];
         bufferGreen1[i]= High[i];
         bufferRed2[i]  = MathMin(Open[i],Close[i]);
         bufferGreen2[i]= MathMax(Open[i],Close[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 ---