MTF Candles

Author: Copyright � 2009, Julien Loutre
MTF Candles
Price Data Components
Series array that contains open prices of each barSeries array that contains close prices for each bar
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
MTF Candles
#property copyright "Copyright © 2009, Julien Loutre"
#property link      "http://www.zenhop.com"

#property  indicator_chart_window
#property  indicator_buffers 1
#property  indicator_color1  LightBlue
#property  indicator_width1 1

extern string timeframe = "H4";
extern color  BullColor = SteelBlue;
extern color  BearColor = White;

double      extBuffer[];

double open,close,open1,close1,high,low;
int p;
int currentCandle = 0;

int init() {
   IndicatorBuffers(1);
   SetIndexStyle(0,DRAW_NONE);
   SetIndexDrawBegin(0,0);
   SetIndexEmptyValue(0, 0.0);
   SetIndexBuffer(0,extBuffer);
   SetIndexLabel(0,"Open Price");
   IndicatorDigits(6);
   return(0);
}

int start() {
   int    counted_bars=IndicatorCounted();
   int    limit,i,j;
   double tmp;
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   p = tfstrtoint(timeframe);
   for(i=limit-1; i>=0; i--) {
      int rp  = MathCeil(i*Period()/p);
      int rp1 = MathCeil((i+1)*Period()/p);
      for (j=i;j<=i+p/Period();j++) {
         if (iOpen(NULL,p,rp) == iOpen(NULL,0,i)) {
            open = iOpen(NULL,0,i);
            close = iClose(NULL,0,i);
            open1 = iOpen(NULL,p,rp1);
            close1 = iClose(NULL,p,rp1);
         }
      }
      extBuffer[i] = open;
      if (extBuffer[i] != extBuffer[i+1]) {
         currentCandle++;
         createCandle(Time[i],open);
      }
      updateCandle(Time[i],close1);
   }
   return(0);
}

void createCandle(double t, double o) {
   ObjectCreate("candle"+currentCandle,OBJ_RECTANGLE,0,t,o,t,o);
}
void updateCandle(double t, double c) {
   ObjectSet("candle"+currentCandle, OBJPROP_TIME2, t);
   ObjectSet("candle"+currentCandle, OBJPROP_PRICE2, c);
   if (ObjectGet("candle"+currentCandle, OBJPROP_PRICE1)>ObjectGet("candle"+currentCandle, OBJPROP_PRICE2)) {
      ObjectSet("candle"+currentCandle, OBJPROP_COLOR, BearColor);
   } else {
      ObjectSet("candle"+currentCandle, OBJPROP_COLOR, BullColor);
   }
}
void deleteCandles() {
   ObjectsDeleteAll(0, OBJ_RECTANGLE);
}
int deinit() {
   deleteCandles();
   return(0);
}
int tfstrtoint(string str) {
   if (str == "M1") {
      return(1);
   }
   if (str == "M5") {
      return(5);
   }
   if (str == "M15") {
      return(15);
   }
   if (str == "M30") {
      return(30);
   }
   if (str == "H1") {
      return(60);
   }
   if (str == "H4") {
      return(240);
   }
   if (str == "D1") {
      return(1440);
   }
   if (str == "W1") {
      return(10080);
   }
   if (str == "MN") {
      return(43200);
   }
   if (str == "") {
      return(0);
   }
}

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 ---