论坛全局菜单下方 - TICKMILL 285X70论坛全局菜单下方 - ThinkMarkets285X70论坛全局菜单下方 - 荔枝返现285X70论坛全局菜单下方 -  icmarkets285X70
查看:1154回复:1
草龙
注册时间2004-12-17
[MT4指标]zz转折zigzag指标
楼主发表于:2014-10-19 23:17只看该作者倒序浏览
1楼 电梯直达
电梯直达
附图指标,zz转折zigzag指标 mt4指标类型:趋势指标 是否能用在mt4手机版上:否 是否含有未来函数:有 //+------------------------------------------------------------------+ //| Channel ZZ.mq4 | //+------------------------------------------------------------------+ #property copyright \"Copyright ? 2008, TheXpert\" #property link \"[email protected]\" extern string _1 = \"Channel width in points\"; extern int ChannelPoints = 150; extern string _2 = \"Channel width in percent\"; extern double ChannelPercent = 1.5; extern string _3 = \"If 0, channel is counted using ChannelPoints , if 1 -- using ChannelPercent\"; extern int ChannelType = 1; extern string _4 = \"Font size\"; extern int FontSize = 10; extern string _5 = \"Font name\"; extern string FontName = \"Arial Black\"; extern string _6 = \"Font color\"; extern color FontColor = Yellow; extern string _7 = \"Draw or not objects containing ZZ statistics\"; extern bool DrawStatistics = true; extern string _8 = \"Offset for stats objects in points\"; extern int StatisticsOffsetPoints = 20; extern string _9 = \"Alert or not when the direction has been changed\"; extern bool AlertBreakout = true; #property indicator_chart_window #property indicator_buffers 3 #property indicator_color1 LightGray #property indicator_width1 3 #property indicator_color2 LightGreen #property indicator_color3 Orange #property indicator_style2 STYLE_DASH #property indicator_style3 STYLE_DASH #define ID \"Channel ZZ Stats \" //---- buffers double ZZ; double UpChannel; double DnChannel; string symbol; #define UP 1 #define DN -1 #define NONE 0 int Direction; int LastDirection; datetime StartMax; datetime EndMax; datetime StartMin; datetime EndMin; // Channel Variables datetime StartChannel; datetime EndChannel; // Object Variables int Counter; int Length; int LastLength; double LastExtrValue; double ExtrValue; int ExtrDirection; datetime ExtrTime; int ChannelWidth; void DrawInfo(datetime endDraw) { if (!DrawStatistics) return; Length = MathAbs(MathRound((ExtrValue - LastExtrValue)/Point)); double pos = ExtrValue; if (Direction == UP) pos += StatisticsOffsetPoints*Point; string id = ID + Counter; string text; if (LastExtrValue != 0) { text = \"(\" + Length + \")\"; if (LastLength != 0) { text = DoubleToStr(Length/(1.0*LastLength), 2) + text; } } if (ObjectFind(id) == -1) { ObjectCreate(id, OBJ_TEXT, 0, endDraw, pos); ObjectSet(id, OBJPROP_COLOR, FontColor); } ObjectMove(id, 0, endDraw, pos); ObjectSetText(id, text, FontSize, FontName); } void NotifyDirectionChange() { if (!AlertBreakout) return; if (ExtrTime < Time[1]) return; string direction = \"UP\"; if (Direction != UP) direction = \"DOWN\"; Alert(\"Channel ZZ \", Symbol(), \" changed direction to \", direction); } void SetExtremum(double value, int direction, datetime time) { if (direction == ExtrDirection && ExtrTime != 0) { if (time == ExtrTime) { ExtrValue = value; DrawInfo(time); } else { ZZ[iBarShift(NULL, 0, ExtrTime)] = EMPTY_VALUE; ExtrValue = value; ExtrTime = time; DrawInfo(time); } } else { LastExtrValue = ExtrValue; ExtrValue = value; ExtrDirection = direction; ExtrTime = time; if (ChannelType == 1) { ChannelWidth = ChannelPercent*value/Point/100; } LastLength = Length; Counter++; DrawInfo(time); NotifyDirectionChange(); } ZZ[iBarShift(NULL, 0, ExtrTime)] = ExtrValue; } int init() { IndicatorShortName(\"-==-\"); IndicatorBuffers(3); SetIndexBuffer(0, ZZ); SetIndexBuffer(1, UpChannel); SetIndexBuffer(2, DnChannel); SetIndexStyle(0, DRAW_SECTION); SetIndexStyle(1, DRAW_SECTION, STYLE_DASH); SetIndexStyle(2, DRAW_SECTION, STYLE_DASH); symbol = Symbol(); Direction = NONE; Counter = 0; StartMax = 0; EndMax = 0; StartMin = 0; EndMin = 0; Length = 0; LastLength = EMPTY_VALUE; LastExtrValue = 0; if (ChannelType == 0) { ChannelWidth = ChannelPoints; } return(0); } int deinit() { for (int i = 0; i <= Counter; i++) { ObjectDelete(ID + i); } } int start() { int ToCount = Bars - IndicatorCounted(); if (ToCount > 2) { ToCount = Bars; ArrayInitialize(ZZ, EMPTY_VALUE); ArrayInitialize(UpChannel, EMPTY_VALUE); ArrayInitialize(DnChannel, EMPTY_VALUE); } for (int i = ToCount - 1; i >= 1; i--) { if (Direction == NONE) { CheckInit(i); continue; } if (Direction == UP) { CheckUp(i); } else { CheckDown(i); } DrawChannel(i); } return(0); } void CheckInit(int i) { if (StartMax == 0 || StartMin == 0) { if (StartMax == 0) StartMax = Time; if (StartMin == 0) StartMin = Time; ExtrTime = 0; return; } if (Direction == NONE) { double maxValue = High[iBarShift(symbol, 0, StartMax)]; double minValue = Low[iBarShift(symbol, 0, StartMin)]; double nowMax = High; double nowMin = Low; if (nowMax > maxValue && Time > StartMax) { EndMax = Time; StartMin = Time; Direction = UP; SetExtremum(nowMax, UP, EndMax); } else if (nowMin > minValue && Time > StartMin) { EndMin = Time; StartMax = Time; Direction = DN; SetExtremum(nowMin, DN, EndMin); } } } void CheckUp(int i) { int startIndex = iBarShift(symbol, 0, StartMax); int endIndex = iBarShift(symbol, 0, EndMax); double endMaxValue = High[endIndex]; if (endMaxValue < High) { endMaxValue = High; EndMax = Time; SetExtremum(High, UP, EndMax); } else { double startMaxValue = High[startIndex]; double startMinValue = Low[iBarShift(symbol, 0, StartMin)]; double nowMaxValue = endMaxValue; if (startIndex - endIndex != 0) { nowMaxValue += (endMaxValue - startMaxValue)/(startIndex - endIndex)*(endIndex - i); } double nowMinValue = Low; if (nowMaxValue - nowMinValue > ChannelWidth*Point) { if (EndMax != i) { StartMin = Time; EndMin = Time; Direction = DN; SetExtremum(Low, DN, EndMin); } } } } void CheckDown(int i) { int startIndex = iBarShift(symbol, 0, StartMin); int endIndex = iBarShift(symbol, 0, EndMin); double endMinValue = Low[endIndex]; if (endMinValue > Low) { endMinValue = Low; EndMin = Time; SetExtremum(Low, DN, EndMin); } else { double startMinValue = Low[startIndex]; double startMaxValue = High[iBarShift(symbol, 0, StartMax)]; double nowMinValue = endMinValue; if (startIndex - endIndex != 0) { nowMinValue += (endMinValue - startMinValue)/(startIndex - endIndex)*(endIndex - i); } double nowMaxValue = High; if (nowMaxValue - nowMinValue > ChannelWidth*Point) { if (EndMin != i) { EndMax = Time; StartMax = Time; Direction = UP; SetExtremum(High, UP, EndMax); } } } } void DrawChannel(int i) { switch (Direction) { case UP: DrawUp(i); break; case DN: DrawDn(i); break; } } void DrawUp(int i) { int startIdx = iBarShift(symbol, 0, StartMax); int endIdx = iBarShift(symbol, 0, EndMax); if (startIdx == i) { UpChannel = High; DnChannel = UpChannel - ChannelWidth*Point; return; } if (startIdx - i > 1) { UpChannel[i + 1] = EMPTY_VALUE; DnChannel[i + 1] = EMPTY_VALUE; } if (startIdx == endIdx) { UpChannel = UpChannel[startIdx]; DnChannel = DnChannel[startIdx]; return; } double upValue = High[startIdx] + (High[endIdx] - High[startIdx])/(endIdx - startIdx)*(i - startIdx); UpChannel = upValue; DnChannel = UpChannel - ChannelWidth*Point; } void DrawDn(int i) { int startIdx = iBarShift(symbol, 0, StartMin); int endIdx = iBarShift(symbol, 0, EndMin); if (startIdx == i) { UpChannel = Low; DnChannel = UpChannel + ChannelWidth*Point; return; } if (startIdx - i > 1) { UpChannel[i + 1] = EMPTY_VALUE; DnChannel[i + 1] = EMPTY_VALUE; } if (startIdx == endIdx) { UpChannel = UpChannel[startIdx]; DnChannel = DnChannel[startIdx]; return; } double dnValue = Low[startIdx] + (Low[endIdx] - Low[startIdx])/(endIdx - startIdx)*(i - startIdx); UpChannel = dnValue; DnChannel = UpChannel + ChannelWidth*Point; }
TK29帖子1楼右侧xm竖版广告90-240
个性签名

阅尽天下指标
搬砖开始,始于2014

广告
TK30+TK31帖子一樓廣告
TK30+TK31帖子一樓廣告

本站免责声明:

1、本站所有广告及宣传信息均与韬客无关,如需投资请依法自行决定是否投资、斟酌资金安全及交易亏损风险;

2、韬客是独立的、仅为投资者提供交流的平台,网友发布信息不代表韬客的观点与意思表示,所有因网友发布的信息而造成的任何法律后果、风险与责任,均与韬客无关;

3、金融交易存在极高法律风险,未必适合所有投资者,请不要轻信任何高额投资收益的诱导而贸然投资;投资保证金交易导致的损失可能超过您投入的资金和预期。请您考虑自身的投资经验及风险承担能力,进行合法、理性投资;

4、所有投资者的交易帐户应仅限本人使用,不应交由第三方操作,对于任何接受第三方喊单、操盘、理财等操作的投资和交易,由此导致的任何风险、亏损及责任由投资者个人自行承担;

5、韬客不隶属于任何券商平台,亦不受任何第三方控制,韬客不邀约客户投资任何保证金交易,不接触亦不涉及投资者的任何资金及账户信息,不代理任何交易操盘行为,不向客户推荐任何券商平台,亦不存在其他任何推荐行为。投资者应自行选择券商平台,券商平台的任何行为均与韬客无关。投资者注册及使用韬客即表示其接受和认可上述声明,并自行承担法律风险。

版权所有:韬客外汇论坛 www.talkfx.com 联络我们:[email protected]