- EAs have no eyes. They don't need anything drawn on the chart.
- ZigZag is repainting indicator (what you see now is not what you did earlier.) Not good for trading.
- EAs have no eyes. They don't need anything drawn on the chart.
- ZigZag is repainting indicator (what you see now is not what you did earlier.) Not good for trading.
1. True, but we need to control that it is acting well. We can still create line, right? Using ObjectCreate.
2. Zigzag is just the type of line I wanted, not mentioning the indicator.
Do these points means it is not possible to draw something in the future/shifted?
1. True, but we need to control that it is acting well. We can still create line, right? Using ObjectCreate.
2. Zigzag is just the type of line I wanted, not mentioning the indicator.
Do these points means it is not possible to draw something in the future/shifted?
- EAs have no eyes. They don't need anything drawn on the chart.
- ZigZag is repainting indicator (what you see now is not what you did earlier.) Not good for trading.
You're not using zigzag right if that's what you think.
Hi,
I have coded an EA that is guessing future trend. I would need to draw that future trend on the chart by displaying a zig zag line shifted to the right of the chart.
From that post, the guy is asking about "How to draw something in future time coordinate ?" for indicators. I can see that it is easily possible by using PLOT_SHIFT like for Alligator indicator.
But for EA, is there a way to do it without calling an indicator to draw the line?
Thanks,
//+------------------------------------------------------------------+ //| ZigZagRayRight.mq4 | //| nicholishen | //| http://www.reddit.com/u/nicholishenFX | //+------------------------------------------------------------------+ #property copyright "nicholishen" #property link "http://www.reddit.com/u/nicholishenFX" #property version "1.00" #property strict #include <ChartObjects\ChartObjectsLines.mqh> //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { //--- struct ZP{double price;datetime time;}zz[2]={0}; for(int i=0,cnt=0;i<Bars&&cnt<2;i++) { double zig = iCustom(_Symbol,_Period,"ZigZag",50,5,3,0,i); if(zig > 0.0 && zig != EMPTY_VALUE) { zz[cnt].price = zig; zz[cnt].time = iTime(_Symbol,_Period,i); cnt++; } } CChartObjectTrend line; line.Create(0,"__zz_ray_right__",0,zz[1].time,zz[1].price,zz[0].time,zz[0].price); line.Detach(); } //+------------------------------------------------------------------+
It's pretty easy. Here's an example.
#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 .
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I have coded an EA that is guessing future trend. I would need to draw that future trend on the chart by displaying a zig zag line shifted to the right of the chart.
From that post, the guy is asking about "How to draw something in future time coordinate ?" for indicators. I can see that it is easily possible by using PLOT_SHIFT like for Alligator indicator.
But for EA, is there a way to do it without calling an indicator to draw the line?
Thanks,