// Downloaded From https://www.WiseStockTrader.com #property copyright "Copyright © 2011, Xaphod" #property link "http://wwww.xaphod.com" #property indicator_chart_window #property indicator_buffers 3 #property indicator_color1 DimGray #property indicator_color2 OrangeRed #property indicator_color3 MediumSeaGreen #property indicator_width1 1 #property indicator_width2 2 #property indicator_width3 2 #property indicator_style1 STYLE_DOT #property indicator_maximum 1 #property indicator_minimum 0 #define INDICATOR_NAME "xSuperTrend MTF" #define INDICATOR_VERSION "v1.01, www.xaphod.com" // Indicator parameters extern string Version_Info=INDICATOR_VERSION; extern string SuperTrend_Settings="——————————————————————————————"; extern int SuperTrend_Period = 10; // SuperTrend ATR Period extern double SuperTrend_Multiplier= 1.7; // SuperTrend Multiplier extern int SuperTrend_TimeFrame = 0; // SuperTrend Timeframe extern bool SuperTrend_AutoTF = True; // Select next higher TF. If TF=M15 then H1 is selected extern bool alertsOn = False; extern bool alertsOnCurrentBar = true; extern bool alertsMessage = true; extern bool alertsSound = false; extern bool alertsEmail = false; // Global module varables double gadUpBuf[]; double gadDnBuf[]; double gadSuperTrend[]; int giTimeFrame; int giRepaintBars; //----------------------------------------------------------------------------- // function: init() // Description: Custom indicator initialization function. //----------------------------------------------------------------------------- int init() { // Set buffers SetIndexStyle(0, DRAW_LINE); SetIndexBuffer(0, gadSuperTrend); SetIndexLabel(0, "SuperTrend"); SetIndexStyle(1, DRAW_LINE); SetIndexBuffer(1, gadDnBuf); SetIndexLabel(1, "SuperTrend Down"); SetIndexStyle(2, DRAW_LINE); SetIndexBuffer(2, gadUpBuf); SetIndexLabel(2, "SuperTrend Up"); // Set Timeframe if (SuperTrend_TimeFrame==0) SuperTrend_TimeFrame=Period(); if (SuperTrend_AutoTF==True) SuperTrend_TimeFrame=NextHigherTF(Period()); // Calculation call via iCustom if (SuperTrend_AutoTF==False && SuperTrend_Settings=="") { giRepaintBars=0; } // Higher Time-frame else if (SuperTrend_TimeFrame!=Period()) { IndicatorShortName(INDICATOR_NAME+" "+TF2Str(SuperTrend_TimeFrame) +"["+SuperTrend_Period+";"+DoubleToStr(SuperTrend_Multiplier,1)+"]"); giRepaintBars=SuperTrend_TimeFrame/Period()*2+1; } // Current Time-frame else { IndicatorShortName(INDICATOR_NAME+" "+TF2Str(SuperTrend_TimeFrame) +"["+SuperTrend_Period+";"+DoubleToStr(SuperTrend_Multiplier,1)+"]"); giRepaintBars=0; } return(0); } //----------------------------------------------------------------------------- // function: deinit() // Description: Custom indicator deinitialization function. //----------------------------------------------------------------------------- int deinit() { return (0); } ///----------------------------------------------------------------------------- // function: start() // Description: Custom indicator iteration function. //----------------------------------------------------------------------------- int start() { int iNewBars, iCountedBars, i; double dAtr,dUpperLevel, dLowerLevel; // Get unprocessed ticks iCountedBars=IndicatorCounted(); if(iCountedBars < 0) return (-1); if(iCountedBars>0) iCountedBars--; iNewBars=MathMax(giRepaintBars,Bars-iCountedBars); for(i=iNewBars; i>=0; i--) { // Calc SuperTrend Locally if (SuperTrend_TimeFrame==Period()) { dAtr = iATR(NULL, 0, SuperTrend_Period, i); dUpperLevel=(High[i]+Low[i])/2+SuperTrend_Multiplier*dAtr; dLowerLevel=(High[i]+Low[i])/2-SuperTrend_Multiplier*dAtr; // Set supertrend levels if (Close[i]>gadSuperTrend[i+1] && Close[i+1]<=gadSuperTrend[i+1]) { gadSuperTrend[i]=dLowerLevel; } else if (Close[i]=gadSuperTrend[i+1]) { gadSuperTrend[i]=dUpperLevel; } else if (gadSuperTrend[i+1]dUpperLevel) gadSuperTrend[i]=dUpperLevel; else gadSuperTrend[i]=gadSuperTrend[i+1]; // Draw Histo gadUpBuf[i]=EMPTY_VALUE; gadDnBuf[i]=EMPTY_VALUE; if (Close[i]>gadSuperTrend[i] || (Close[i]==gadSuperTrend[i] && Close[i+1]>gadSuperTrend[i+1])) gadUpBuf[i]=gadSuperTrend[i]; else if (Close[i]