The buy target uses FiboEntryLevel instead of FiboTpLevel, making the calculated target equal to the trigger.
Fibonacci & ZigZag Retracement
Builds retracement triggers from the two most recent non-zero ZigZag points and draws the corresponding Fibonacci object.
How the source is structured
- On each new H1 bar, scan the ZigZag buffer for two recent pivot values.
- Calculate a 61.8% retracement trigger for a long or short entry.
- Attempt an order when price crosses the trigger, then mark that trigger as consumed.
Default inputs
| Volume | 0.1 lot |
|---|---|
| Entry / stop / target levels | 61.8 / 100 / 0 |
| ZigZag period | H1 |
| Depth / deviation / backstep | 12 / 5 / 3 |
Source-review notes
These observations come from reading this uploaded version. They are not compiler output or a complete code audit. The download retains the source as supplied.
The sell stop and target add the level percentage to the full swing instead of multiplying the swing by it.
Buffer-copy results and order success are not checked before consuming values or triggers. Recent ZigZag pivots also need stability checks in a backtest.
Dependencies
Examples\ZigZag.ex5 is referenced by iCustom. That indicator is not included in this upload.
Source & attribution
No author or license declaration appears in the supplied source.
Included in the Edge Quant source collection with existing notices preserved. Free download does not imply a new license grant.
Inspect the original source
The browser preview is decoded for reading; the download keeps the original file bytes.
Expand full MQL5 source · 113 lines
#include <Trade/Trade.mqh>input double Lots = 0.1;input double FiboEntryLevel = 61.8;input double FiboSlLevel = 100;input double FiboTpLevel = 0;input ENUM_TIMEFRAMES ZigZagTimeframe = PERIOD_H1;input int ZigZagDepth = 12;input int ZigZagDeviation = 5;input int ZigZagBackStep = 3;CTrade trade;int handleZigZag;datetime timestamp;double triggerBuy;double slBuy;double tpBuy;double triggerSell;double slSell;double tpSell;int OnInit(){ handleZigZag = iCustom(_Symbol,ZigZagTimeframe,"Examples\\ZigZag.ex5",ZigZagDepth,ZigZagDeviation,ZigZagBackStep); return(INIT_SUCCEEDED); }void OnDeinit(const int reason){ }void OnTick(){ static double zigZagLast = 0; static datetime zigZagLastTime = 0; static double zigZagLastLast = 0; static datetime zigZagLastLastTime = 0; datetime time0 = iTime(_Symbol,ZigZagTimeframe,0); if(timestamp != time0){ timestamp = time0; zigZagLast = 0; zigZagLastLast = 0; for(int i = 1; i <1000; i++){ double zigZag[]; CopyBuffer(handleZigZag,MAIN_LINE,i,1,zigZag); if(zigZag[0] != EMPTY_VALUE && zigZag[0] != 0){ if(zigZagLast ==0){ zigZagLast = zigZag[0]; zigZagLastTime = iTime(_Symbol,ZigZagTimeframe,i); }else{ zigZagLastLast = zigZag[0]; zigZagLastLastTime = iTime(_Symbol,ZigZagTimeframe,i); } } if(zigZagLast != 0 && zigZagLastLast != 0){ if(zigZagLast > zigZagLastLast && triggerBuy < DBL_MAX){ if(triggerSell >= DBL_MAX) triggerSell = 0; triggerBuy = zigZagLast - (zigZagLast - zigZagLastLast) * FiboEntryLevel / 100; slBuy = zigZagLast - (zigZagLast - zigZagLastLast) * FiboSlLevel / 100; tpBuy = zigZagLast - (zigZagLast - zigZagLastLast) * FiboEntryLevel / 100; createFibo("FiboBuy",zigZagLastLastTime,zigZagLastLast,zigZagLastTime,zigZagLast); } if(zigZagLast < zigZagLastLast && triggerSell < DBL_MAX){ if(triggerBuy >=DBL_MAX) triggerBuy = 0; triggerSell = zigZagLast + (zigZagLastLast - zigZagLast) * FiboEntryLevel / 100; slSell = zigZagLast + (zigZagLastLast - zigZagLast) + FiboSlLevel / 100; tpSell = zigZagLast + (zigZagLastLast - zigZagLast) + FiboTpLevel / 100; createFibo("FiboSell",zigZagLastLastTime,zigZagLastLast,zigZagLastTime,zigZagLast); } break; } } } double bid = SymbolInfoDouble(_Symbol,SYMBOL_BID); double ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK); if(triggerBuy > 0 && triggerBuy < DBL_MAX && ask < triggerBuy){ trade.Buy(Lots,_Symbol,ask,slBuy,tpBuy); triggerBuy = DBL_MAX; if(zigZagLast < zigZagLastLast) triggerBuy = 0; } if(triggerSell > 0 && triggerSell < DBL_MAX && bid > triggerSell){ trade.Sell(Lots,_Symbol,ask,slSell,tpSell); triggerSell = DBL_MAX; if(zigZagLast > zigZagLastLast) triggerBuy = 0; } }void createFibo(string prefix, datetime zigZagLastLastTime, double zigZagLastLast, datetime zigZagLastTime, double zigZagLast){ ObjectsDeleteAll(0,prefix); string objName = prefix+TimeToString(zigZagLastLastTime); ObjectCreate(0,objName,OBJ_FIBO,0,zigZagLastLastTime,zigZagLastLast,zigZagLastTime,zigZagLast); for(int i = 0; i < ObjectGetInteger(0,objName,OBJPROP_LEVELS); i++){ if(prefix=="FiboBuy") ObjectSetInteger(0,objName,OBJPROP_LEVELCOLOR,i,clrBlue); if(prefix=="FiboBSell") ObjectSetInteger(0,objName,OBJPROP_LEVELCOLOR,i,clrRed); ObjectSetInteger(0,objName,OBJPROP_LEVELSTYLE,i,STYLE_DASH); ObjectSetInteger(0,objName,OBJPROP_LEVELWIDTH,i,1); } if(prefix=="FiboBuy")ObjectSetInteger(0,objName,OBJPROP_COLOR,clrBlue); if(prefix=="FiboSell")ObjectSetInteger(0,objName,OBJPROP_COLOR,clrRed);}Educational source material, not investment advice. No profitability, execution quality or live-readiness claim is made for this upload.