#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
input double Future_Price=1.18;//future price [projected]
input int Bars_Duration=125;//duration in bars (from last known ZZ to projected[future] ZZ)
input bool use_time_duration=false;//use time duration instead of bars ?
input int time_duration=600;//time duration in minutes
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
double zz_price[3];
datetime zz_time[3];
int OnInit()
{
//--- create timer
// EventSetTimer(60);
//find 2 latest valid zigzag points (it repaints though)
int fill=2;
double zz_value;
for(int x=1;x<Bars;x++)
{
zz_value=iCustom(Symbol(),Period(),"ZigZag",50,5,3,0,x);
//if zigzag exists
if(zz_value>0&&zz_value!=EMPTY_VALUE)
{
//decrease counter
fill--;
zz_price[fill]=zz_value;
zz_time[fill]=Time[x];
//if we got 2 values bounce
if(fill==0) break;
}
//if zigzag exists ends here
}
//projection(3rd zz value you provide)
zz_price[2]=NormalizeDouble(Future_Price,Digits());
//if we use bars duration for the projection
if(use_time_duration==false)
{
zz_time[2]=zz_time[1]+PeriodSeconds()*Bars_Duration;//in seconds ,to match the timestamp
}
//if we use time duration
if(use_time_duration==true)
{
zz_time[2]=zz_time[1]+time_duration*60;//conversion to seconds , to match the timestamp
}
//draw
string objna;
bool obji;
objna="NORMAL_ZZ";
ObjectDelete(0,objna);
obji=ObjectCreate(0,objna,OBJ_TREND,0,zz_time[0],zz_price[0],zz_time[1],zz_price[1]);
ObjectSetInteger(0,objna,OBJPROP_RAY_RIGHT,false);
ObjectSetInteger(0,objna,OBJPROP_RAY,false);
objna="PROJECTED_ZZ";
ObjectDelete(0,objna);
obji=ObjectCreate(0,objna,OBJ_TREND,0,zz_time[1],zz_price[1],zz_time[2],zz_price[2]);
ObjectSetInteger(0,objna,OBJPROP_RAY_RIGHT,false);
ObjectSetInteger(0,objna,OBJPROP_RAY,false);
ObjectSetInteger(0,objna,OBJPROP_TIME2,zz_time[2]);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//--- destroy timer
//EventKillTimer();
}
I guess by zigzag you mean the plotting method instead of the indicator .