Jump to content

Multi time frame indicator


bamik

Recommended Posts

Re: Multi time frame indicator requested

 

I was recommended this-

maybe good?

 

//+------------------------------------------------------------------+
//|                                         #MTF Supertrend line.mq4 |
//|                                      Copyright © 2006, Eli hayun |
//|                                          [url]http://www.elihayun.com[/url] |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Eli hayun"
#property link      "http://www.elihayun.com"

#property indicator_chart_window
#property indicator_buffers 8
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 Red
#property indicator_color4 Blue
#property indicator_color5 Red
#property indicator_color6 Blue
#property indicator_color7 Red
#property indicator_color8 Blue
//---- buffers
double buf_up1D[];
double buf_down1D[];

double buf_up4H[];
double buf_down4H[];

double buf_up1H[];
double buf_down1H[];

double buf_up30M[];
double buf_down30M[];

extern int Period_1 = PERIOD_M15;
extern int Period_2 = PERIOD_M30;
extern int Period_3 = PERIOD_H1;
extern int Period_4 = PERIOD_H4;

extern bool AutoDisplay      = true;

extern bool display_Period_1 = true;
extern bool display_Period_2 = true;
extern bool display_Period_3 = true;
extern bool display_Period_4 = true;

extern bool Play_Sound = true;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
 {
//---- indicators

  if (AutoDisplay)
  {
     display_Period_1 = false; display_Period_2 = false; display_Period_3 = false; display_Period_4 = false;
     switch (Period())
     {
        case PERIOD_M1  :  SetValues(PERIOD_M1,  PERIOD_M5, PERIOD_M15,PERIOD_M30, true,  true,  false, false); break;
        case PERIOD_M5  :  SetValues(PERIOD_M5,  PERIOD_M15,PERIOD_M30,PERIOD_H1,  true,  true,  false, false); break;
        case PERIOD_M15 :  SetValues(PERIOD_M5,  PERIOD_M15,PERIOD_M30,PERIOD_H1,  true,  true,  true,  false); break;
        case PERIOD_M30 :  SetValues(PERIOD_M5,  PERIOD_M15,PERIOD_M30,PERIOD_H1,  false, true,  true,  false); break;
        case PERIOD_H1  :  SetValues(PERIOD_M15, PERIOD_M30,PERIOD_H1, PERIOD_H4,  false, false, true,  true);  break;
        case PERIOD_H4  :  SetValues(PERIOD_M30, PERIOD_H1, PERIOD_H4, PERIOD_D1,  false, true,  true,  true);  break;
        case PERIOD_D1  :  SetValues(PERIOD_H1,  PERIOD_H4, PERIOD_D1, PERIOD_W1,  true,  true,  true,  false); break;
        case PERIOD_W1  :  SetValues(PERIOD_H4,  PERIOD_D1, PERIOD_W1, PERIOD_MN1, false, true,  true,  false); break;
        case PERIOD_MN1 :  SetValues(PERIOD_H4,  PERIOD_D1, PERIOD_W1, PERIOD_MN1, false, false, true,  true);  break;
     }
  }
  
  
  int draw = DRAW_LINE; if (!display_Period_4) draw = DRAW_NONE;
  
  SetIndexStyle(0,draw, STYLE_SOLID, 4);
  SetIndexBuffer(0,buf_up1D);
  SetIndexStyle(1,draw, STYLE_SOLID, 4);
  SetIndexBuffer(1,buf_down1D);
  SetIndexLabel(0, tf2txt(Period_4)); SetIndexLabel(1, tf2txt(Period_4));
  
  draw = DRAW_LINE; if (!display_Period_3) draw = DRAW_NONE;
  SetIndexStyle(2,draw, STYLE_SOLID, 3);
  SetIndexBuffer(2,buf_up4H);
  SetIndexStyle(3,draw, STYLE_SOLID, 3);
  SetIndexBuffer(3,buf_down4H);
  SetIndexLabel(2, tf2txt(Period_3)); SetIndexLabel(3, tf2txt(Period_3));


  draw = DRAW_LINE; if (!display_Period_2) draw = DRAW_NONE;
  SetIndexStyle(4,draw, STYLE_SOLID, 2);
  SetIndexBuffer(4,buf_up1H);
  SetIndexStyle(5,draw, STYLE_SOLID, 2);
  SetIndexBuffer(5,buf_down1H);
  SetIndexLabel(4, tf2txt(Period_2)); SetIndexLabel(5, tf2txt(Period_2));

  draw = DRAW_LINE; if (!display_Period_1) draw = DRAW_NONE;
  SetIndexStyle(6,draw, STYLE_SOLID, 1);
  SetIndexBuffer(6,buf_up30M);
  SetIndexStyle(7,draw, STYLE_SOLID, 1);
  SetIndexBuffer(7,buf_down30M);
  SetIndexLabel(6, tf2txt(Period_1)); SetIndexLabel(7, tf2txt(Period_1));
//----
  return(0);
 }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
 {
//----
  
//----
  return(0);
 }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
 {
  int    counted_bars=IndicatorCounted();
  int i=0, y1d=0, y4h=0, y1h=0, y30m=0;
  int limit=Bars-counted_bars;

  datetime TimeArray_1D[] ,TimeArray_4H[], TimeArray_1H[], TimeArray_30M[];
//----
  ArrayCopySeries(TimeArray_1D,MODE_TIME,Symbol(),Period_4); 
  ArrayCopySeries(TimeArray_4H,MODE_TIME,Symbol(),Period_3); 
  ArrayCopySeries(TimeArray_1H,MODE_TIME,Symbol(),Period_2); 
  ArrayCopySeries(TimeArray_30M,MODE_TIME,Symbol(),Period_1);
     
  for(i=0, y1d=0,  y4h=0,  y1h=0,  y30m=0;i<limit;i++)
  {
     if (Time[i]<TimeArray_1D[y1d]) y1d++;
     if (Time[i]<TimeArray_4H[y4h]) y4h++;
     if (Time[i]<TimeArray_1H[y1h]) y1h++;
     if (Time[i]<TimeArray_30M[y30m]) y30m++;
     
     
     buf_up1D[i] = iCustom(NULL, Period_4, "SuperTrend", false, 1, y1d);
     buf_down1D[i] = iCustom(NULL, Period_4, "SuperTrend", false, 0, y1d);
     
     if (i < 2)
     {
        SoundAlarm(buf_up1D[i] , iCustom(NULL, Period_4, "SuperTrend", false, 1, y1d+1), 4, "Down");
        SoundAlarm(buf_down1D[i] , iCustom(NULL, Period_4, "SuperTrend", false, 0, y1d+1), 4, "Up");
     }
     buf_up4H[i] = iCustom(NULL, Period_3, "SuperTrend", false, 1, y4h);
     buf_down4H[i] = iCustom(NULL, Period_3, "SuperTrend", false, 0, y4h);

     if (i < 2)
     {
        SoundAlarm(buf_up4H[i] , iCustom(NULL, Period_3, "SuperTrend", false, 1, y4h+1), 3, "Down");
        SoundAlarm(buf_down4H[i] , iCustom(NULL, Period_3, "SuperTrend", false, 0, y4h+1), 3, "Up");
     }
     
     buf_up1H[i] = iCustom(NULL, Period_2, "SuperTrend", false, 1, y1h);
     buf_down1H[i] = iCustom(NULL, Period_2, "SuperTrend", false, 0, y1h);
     
     if (i < 2)
     {
        SoundAlarm(buf_up1H[i] , iCustom(NULL, Period_2, "SuperTrend", false, 1, y1h+1), 2, "Down");
        SoundAlarm(buf_down1H[i] , iCustom(NULL, Period_2, "SuperTrend", false, 0, y1h+1), 2, "Up");
     }
     
     buf_up30M[i] = iCustom(NULL, Period_1, "SuperTrend", false, 1, y30m);
     buf_down30M[i] = iCustom(NULL, Period_1, "SuperTrend", false, 0, y30m);

     if (i < 2)
     {
        SoundAlarm(buf_up30M[i] , iCustom(NULL, Period_1, "SuperTrend", false, 1, y30m+1), 1, "Down");
        SoundAlarm(buf_down30M[i] , iCustom(NULL, Period_1, "SuperTrend", false, 0, y30m+1), 1, "Up");
     }
  }

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

void SoundAlarm(double v1, double v2, int prd, string sDir)
{
  bool bDisplay = true;
  string sPrd = "";
  
  static bool bAlreadyAlarm = true;
  
  if (NewBar())
     bAlreadyAlarm = false;
  
  switch ( prd )
  {
     case 4  : bDisplay = display_Period_4;  sPrd = tf2txt(Period_3); break;
     case 3  : bDisplay = display_Period_3;  sPrd = tf2txt(Period_3); break;
     case 2  : bDisplay = display_Period_2;  sPrd = tf2txt(Period_2); break;
     case 1  : bDisplay = display_Period_1;  sPrd = tf2txt(Period_1); break;
  }
  
  if ((!Play_Sound) || (!bDisplay) || bAlreadyAlarm)
     return;

  if ((v1 != EMPTY_VALUE) && (v2 == EMPTY_VALUE))   
  {
     Print("SuperTrend changed direction to " ,sDir, " at ", sPrd); // , " ",v1," ",v2," ",prd);
     PlaySound("alert.wav");
     bAlreadyAlarm = true;
  }  
}

bool NewBar()
{
  static datetime dt = 0;
  
  if (Time[0] != dt)
  {
     dt = Time[0];
     return(true);
  }
  return(false);
}


string tf2txt(int tf)
{
  if (tf == PERIOD_M1)    return("M1");
  if (tf == PERIOD_M5)    return("M5");
  if (tf == PERIOD_M15)    return("M15");
  if (tf == PERIOD_M30)    return("M30");
  if (tf == PERIOD_H1)    return("H1");
  if (tf == PERIOD_H4)    return("H4");
  if (tf == PERIOD_D1)    return("D1");
  if (tf == PERIOD_W1)    return("W1");
  if (tf == PERIOD_MN1)    return("MN1");
  
  return("??");
}

void SetValues(int p1, int p2, int p3, int p4, bool d1, bool d2, bool d3, bool d4)
{
  display_Period_1 = d1; display_Period_2 = d2; display_Period_3 = d3; display_Period_4 = d4;
  Period_1 = p1;   Period_2 = p2; Period_3 = p3; Period_4 = p4; 
}

Link to comment
Share on other sites

Re: Multi time frame indicator requested

 

I am mt4 novice bamik.

Can you please show me in code above where it calls SuperTrend.ex4

 

My friend when you making an MTF indicator from an indicator you need to have that base indicator in your folder indicator of MT4.

However,look at here that MTF indicator call base indicator:

buf_up1D[i] = iCustom(NULL, Period_4, "[size=150]SuperTrend[/size]", false, 1, y1d);
     buf_down1D[i] = iCustom(NULL, Period_4, "[size=150]SuperTrend[/size]", false, 0, y1d);
    
     if (i < 2)
     {
        SoundAlarm(buf_up1D[i] , iCustom(NULL, Period_4, "[size=150]SuperTrend[/size]", false, 1, y1d+1), 4, "Down");
        SoundAlarm(buf_down1D[i] , iCustom(NULL, Period_4, "[size=150]SuperTrend[/size]", false, 0, y1d+1), 4, "Up");
     }
     buf_up4H[i] = iCustom(NULL, Period_3, "[size=150]SuperTrend[/size]", false, 1, y4h);
     buf_down4H[i] = iCustom(NULL, Period_3, "[size=150]SuperTrend[/size]", false, 0, y4h);

     if (i < 2)
     {
        SoundAlarm(buf_up4H[i] , iCustom(NULL, Period_3, "[size=150]SuperTrend[/size]", false, 1, y4h+1), 3, "Down");
        SoundAlarm(buf_down4H[i] , iCustom(NULL, Period_3, "[size=150]SuperTrend[/size]", false, 0, y4h+1), 3, "Up");
     }
    
     buf_up1H[i] = iCustom(NULL, Period_2, "[size=150]SuperTrend[/size]", false, 1, y1h);
     buf_down1H[i] = iCustom(NULL, Period_2, "[size=150]SuperTrend[/size]", false, 0, y1h);
    
     if (i < 2)
     {
        SoundAlarm(buf_up1H[i] , iCustom(NULL, Period_2, "[size=150]SuperTrend[/size]", false, 1, y1h+1), 2, "Down");
        SoundAlarm(buf_down1H[i] , iCustom(NULL, Period_2, "[size=150]SuperTrend[/size]", false, 0, y1h+1), 2, "Up");
     }
    
     buf_up30M[i] = iCustom(NULL, Period_1, "[size=150]SuperTrend[/size]", false, 1, y30m);
     buf_down30M[i] = iCustom(NULL, Period_1, "[size=150]SuperTrend[/size]", false, 0, y30m);

     if (i < 2)
     {
        SoundAlarm(buf_up30M[i] , iCustom(NULL, Period_1, "[size=150]SuperTrend[/size]", false, 1, y30m+1), 1, "Down");
        SoundAlarm(buf_down30M[i] , iCustom(NULL, Period_1, "[size=150]SuperTrend[/size]", false, 0, y30m+1), 1, "Up");
     }
  }

Link to comment
Share on other sites

  • 1 year later...
  • 3 years later...

Hello

 

Somebody can code value of supertrend of all time frame in single window of metatrader if in 5min its Price above supertrend than green colour and 15 min price is below supertrend than value in Red colour.

 

All TIMEFRAME Value in single window dont have to scroll to everytime frame to see the value

 

Hope somebody have the code.

 

Thankyou

Krisna

Edited by kkrishna79
Link to comment
Share on other sites

Krishna, have a look and test this This is the work of xaphod If you have specific questions about the indicators or if you want mq4 indicators to make an EA, you have to ask him on his website.www.xaphod.com.

 

Now regarding so called "repainting".

MTF indicators will update/redraw all bars on the lower time-frame that represent the open higher time-frame bar until the higher time-frame bar closes. This is normal and expected behavior for an MTF indicator.

You can use the 'xSuperTrend Alert' Indicator to give alerts for any timeframe you wish. You will have to add it to your chart in addition to the xSuperTrend indicator you are using.

All bars on the chart associated with a higher time-frame bar that is open will continue to update with the current status of the higher time-frame supertrend until that bar closes. Krishna, I think it would be easier for you to understand the nature of MTF indicators and the repainting which it is often accused of, is to just remember "that MTF indicators update/redraw all bars on the lower time-frame that represent the open higher time-frame bar until the higher time-frame barcloses. This is normal and expected behavior for an MTF indicator." That's a quote from Xaphod himself.

 

 

 

 

XSupertrend Pack.zip (40.95KB)

https://www.sendspace.com/file/3wg5t3

Includes (all ex4 files)

xSupertrendMTF

xSupertrendAlert

xSupertrendCandles

xSupertrendTapeMTF

xSuperTrend

xSupertrendTape

TF Slicer

xSuperTrend.tpl (template)

Edited by CashManic
Link to comment
Share on other sites

Thanks Cash, reminds me of the XXX system hehe:)

The template file is handy too

 

Buddy boy,

Yes xSupertrendCandles is also used in the XXX system,but other than that everything else is different, in fact both systems complement each other!

Link to comment
Share on other sites

  • 3 years later...
Krishna, have a look and test this This is the work of xaphod If you have specific questions about the indicators or if you want mq4 indicators to make an EA, you have to ask him on his website.www.xaphod.com.

 

Now regarding so called "repainting".

MTF indicators will update/redraw all bars on the lower time-frame that represent the open higher time-frame bar until the higher time-frame bar closes. This is normal and expected behavior for an MTF indicator.

You can use the 'xSuperTrend Alert' Indicator to give alerts for any timeframe you wish. You will have to add it to your chart in addition to the xSuperTrend indicator you are using.

All bars on the chart associated with a higher time-frame bar that is open will continue to update with the current status of the higher time-frame supertrend until that bar closes. Krishna, I think it would be easier for you to understand the nature of MTF indicators and the repainting which it is often accused of, is to just remember "that MTF indicators update/redraw all bars on the lower time-frame that represent the open higher time-frame bar until the higher time-frame barcloses. This is normal and expected behavior for an MTF indicator." That's a quote from Xaphod himself.

 

 

 

 

XSupertrend Pack.zip (40.95KB)

https://www.sendspace.com/file/3wg5t3

Includes (all ex4 files)

xSupertrendMTF

xSupertrendAlert

xSupertrendCandles

xSupertrendTapeMTF

xSuperTrend

xSupertrendTape

TF Slicer

xSuperTrend.tpl (template)

 

Thank you .

Link to comment
Share on other sites

  • 2 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...