Download MetaTrader 5
To add comments, please log in or register
MQL5.community allows users to store their source codes in MQL5 Storage. Try it!
Paul
529
Paul 2014.11.04 22:27 
Can any one show me how to create the current 5 min candle with this code?
//+------------------------------------------------------------------+
//|                                                  MTF Candles.mq4 |
//|                                       2007, Christof Risch (iya) |
//| Shows candles from another (usually higher) timeframe.                              |
//+------------------------------------------------------------------+
#property link "http://www.forexfactory.com/"
#property indicator_chart_window

#property indicator_buffers 10

#property indicator_color1 Lime // long wick up
#property indicator_width1 1
#property indicator_color2 Red // long wick down
#property indicator_width2 1
#property indicator_color3 Lime // long body up
#property indicator_width3 6
#property indicator_color4 Red // long body down
#property indicator_width4 6

#property indicator_color5 White
#property indicator_width5 1
#property indicator_style5 2
#property indicator_color6 White
#property indicator_width6 1
#property indicator_style6 2
#property indicator_color7 White
#property indicator_width7 1
#property indicator_style7 2

//---- input parameters
extern int              TimeFrame               = 0,            // {1=M1, 5=M5, ..., 60=H1, 240=H4, 1440=D1, ...}
                                        BarWidth                        = 1,
                                        CandleWidth             = 6;

//---- buffers
double LongWickUp[],        LongCandleUp[],
                 LongWickDown[],         LongCandleDown[];
                 
double EMA_H[];
double EMA_L[];
double EMA_C[];

string Sym = "";

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
        IndicatorShortName("MTF Candles ("+TimeFrame+")");
        
        SetIndexBuffer(0,LongWickUp);
        SetIndexBuffer(1,LongWickDown);                         
        SetIndexBuffer(2,LongCandleUp);
        SetIndexBuffer(3,LongCandleDown);
        
        SetIndexStyle(0,DRAW_HISTOGRAM,0,BarWidth);
        SetIndexStyle(1,DRAW_HISTOGRAM,0,BarWidth);
        SetIndexStyle(2,DRAW_HISTOGRAM,0,CandleWidth);
        SetIndexStyle(3,DRAW_HISTOGRAM,0,CandleWidth);
        
        SetIndexBuffer(4,EMA_H);
        SetIndexBuffer(5,EMA_L);
        SetIndexBuffer(6,EMA_C);
        
        SetIndexStyle(4,DRAW_LINE);
        SetIndexStyle(5,DRAW_LINE);
        SetIndexStyle(6,DRAW_LINE);
        
        Sym = Symbol();
        
        return(0);
}


//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
        for(int i = Bars-1-IndicatorCounted(); i >= 0; i--)
        {
        
       EMA_H[i] = iHigh(NULL,TimeFrame,Time[0]);             //  iMA(Sym, TimeFrame, 34, TimeFrame, MODE_EMA, PRICE_HIGH, i );
       EMA_L[i] = iLow(NULL,TimeFrame,Time[0]);             //  iMA(Sym, TimeFrame, 34, TimeFrame, MODE_EMA, PRICE_LOW, i );
       EMA_C[i] = iClose(NULL,TimeFrame,Time[0]);             //  iMA(Sym, TimeFrame, 34, TimeFrame, MODE_EMA, PRICE_CLOSE, i );
                
                
                int shift1 = iBarShift(NULL,TimeFrame,Time[0]),
                         time1  = iTime    (NULL,TimeFrame,shift1),
                         shift2 = iBarShift(NULL,0,time1);

                double  high            = iHigh(NULL,TimeFrame,shift1),  //
                                        low             = iLow(NULL,TimeFrame,shift1),  //
                                        open            = iOpen(NULL,TimeFrame,shift1),  //
                                        close           = iClose(NULL,TimeFrame,shift1),  //
                                        
                                        bodyHigh        = MathMax(open,close),
                                        bodyLow = MathMin(open,close);
                                        
                                        

                if( open <= close && close > EMA_H[i] )
                
                {
                        LongWickUp[shift2] = high;                 LongCandleUp[shift2] = bodyHigh;
                        LongWickDown[shift2] = low;             LongCandleDown[shift2] = bodyLow;
                }
                
                else if( open >= close && close > EMA_H[i] )
                
                {
                        LongWickUp[shift2] = low;                  LongCandleUp[shift2] = bodyLow;
                        LongWickDown[shift2] = high;            LongCandleDown[shift2] = bodyHigh;
                }
                
                
        }

        return(0);
}
//+------------------------------------------------------------------+

I've tried creating a current 5 minute candle (usd/chf) in a separate window.   This is the closest I have gotten.  The candle is not proportional.
Paul
529
Paul 2014.11.04 22:30  
/
To add comments, please log in or register