Ideal ZigZag - MetaTrader 4 Script | Trading Script Download - MT4/MT5 Resources - MetaTrader 5 Resources




1. Memory requirements. The indicator uses 5 buffers instead of 2 (or even 1) as in other similar implementations. But (IMHO) it's a great price for advantages #6 and #7. None of the fast ZigZags I've seen can handle history inserts without a full rebuild. Mine does just that. And it does it in an efficient way
2. Additional lines are available. This is required to make the data visible to any external code. These lines should never be visible.
ZZ is drawn based on the channel principle.
Channel width can be defined in points (XLab_ZZ) or percentage (XLab_ZZP)
outer integer channel width = 100 ; #property Indicator_chart_window #Attribute indicator_buffers 1 #property Indicator_color1 Red #Attribute indicator_width1 3 DateTimeLast ; IntegerInitialize () { last time = 0 ; return ( 0 ); } boolean get value( double directory, integer bar, integer previous bar, double & peak, integer & peak bar, datetime and peaktime) { if (directory < 0 ) { datetimet = custom ( symbol (), 0 , "XLab_ZZ" , channel-width, 2 , bars); int i = iBarShift ( symbol (), 0 , t); if (i == previous column) { t = custom ( symbol (), 0 , "XLab_ZZ" , channel-width, 2 , bars + 1 ); i = iBarShift ( symbol (), 0 , t); } double v = custom ( symbol (), 0 , "XLab_ZZ" , channelWidth , 1 , i ); if (v== empty_VALUE ) { t = custom ( symbol (), 0 , "XLab_ZZ" , channel-width, 2 , bars + 1 ); i = iBarShift ( symbol (), 0 , t); v = custom ( symbol (), 0 , "XLab_ZZ" , channel-width, 1 , i ); } peak=v; peakbar = i; Peak time = t; } Else if (directory > 0 ) { t = custom ( symbol (), 0 , "XLab_ZZ" , channel-width, 3 , bars ); i = iBarShift ( symbol (), 0 , t); if (i == previous column) { t = custom ( symbol (), 0 , "XLab_ZZ" , channel-width, 3 , bars + 1 ); i = iBarShift ( symbol (), 0 , t); } v = custom ( symbol (), 0 , "XLab_ZZ" , channel-width, 0 , i ); if (v== empty_VALUE ) { t = custom ( symbol (), 0 , "XLab_ZZ" , channel-width, 3 , bars + 1 ); i = iBarShift ( symbol (), 0 , t); v = custom ( symbol (), 0 , "XLab_ZZ" , channel-width, 0 , i ); } peak=v; peakbar = i; Peak time = t; } other { return (false); } return (true); } integer start() { if (last_time == time[ 0 ]) return ( 0 ); last_time = time [ 0 ]; double directory = custom ( symbol (), 0 , "XLab_ZZ" , channel-width, 4 , 1 ); double rdir = -dir; if (directory == empty_VALUE ) return ( 0 ); Double v1, v2, v3, v4, v5; Integers i1, i2, i3, i4, i5; Date and time t1, t2, t3, t4, t5; Get value (directory, 1 , 0 , v1, i1, t1); Get value (rdir, i1, 0 , v2, i2, t2); GetValue(dir, i2, i1, v3, i3, t3); GetValue(rdir, i3, i2, v4, i4, t4); GetValue(dir, i4, i3, v5, i5, t5); Set Point ( "1" , v1, t1); Set Point ( "2" , v2, t2); Set Point ( "3" , v3, t3); Set Point ( "4" , v4, t4); Set point ( " 5 " , v5 , t5 ); Print ( v1 , " " , v2, " " , v3, " " , v4, " " , v5, " " , i1, " " , i2, " " , i3, " ", i4, " " , i5); Return ( 0 ); } void setpoint( string name, double price, date time time) { object create (name, obj_arrow , 0 , time, price); object set (name, OBJPROP_ARROWCODE , 108 ); object set (name, OBJPROP_PRICE1, price); object set (name, OBJPROP_TIME1, time); }
This example is an indicator that marks (once per bar) the previous five peaks (including the current formation)
attention! This code may not work properly if 0th Bar mode is turned on
Set with the DrawZeroBar variable. Off by default.
It is not recommended to use this option, especially when the indicator is used for EA
Enjoy using it ;). If you have any questions, please feel free to ask.
If you find any bugs, please report them to me. Thanks.
Attachment download
📎 XLab_ZZ.mq4 (4.6 KB)
📎 XLab_ZZP.mq4 (4.62 KB)
Source: MQL5 #10671
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •