1. Are the two vertical lines far enough to create a good looking trend line in lower time frame?
2. You should share your code for best help from people in forum.
1. Are the two vertical lines far enough to create a good looking trend line in lower time frame?
2. You should share your code for best help from people in forum.
#property copyright "Copyright 2023, MetaQuotes Ltd." #property link "https://www.mql5.com" #property version "1.00" #property indicator_chart_window string vline="vertical_line"; string vline_2="vertical_line_2"; bool is_object_being_dragged=false; bool is_object_being_dragged2=false; int time_a=0; int time_b=0; int i=0; datetime final_time; datetime final_time2; double std_channel_1 = 1; double std_channel_2 = 2; int n; double a, b, c, sumy, sumx, sumxy, sumx2, value,iClose[]; datetime iTime[]; int endbar; int startbar; color clr1=StringToColor("40,40,40"); color clr_tline=StringToColor("56,1,124"); int OnInit() { bool obj=ObjectCreate(ChartID(),vline,OBJ_VLINE,0,iTime(_Symbol,PERIOD_CURRENT,1),0); bool obj2=ObjectCreate(ChartID(),vline_2,OBJ_VLINE,0,iTime(_Symbol,PERIOD_CURRENT,10),0); //Print("curr_time",+final_time); //Print("i=",+i); ObjectSetInteger(ChartID(),vline,OBJPROP_SELECTABLE,true); ObjectSetInteger(ChartID(),vline,OBJPROP_WIDTH,2); ObjectSetInteger(ChartID(),vline,OBJPROP_BACK,true); ObjectSetInteger(ChartID(),vline,OBJPROP_COLOR,clr1); ObjectSetInteger(ChartID(),vline, OBJPROP_SELECTED, true); ChartSetInteger(ChartID(),CHART_EVENT_MOUSE_MOVE,true); ObjectSetInteger(ChartID(),vline_2,OBJPROP_SELECTABLE,true); ObjectSetInteger(ChartID(),vline_2,OBJPROP_WIDTH,2); ObjectSetInteger(ChartID(),vline_2,OBJPROP_BACK,true); ObjectSetInteger(ChartID(),vline_2,OBJPROP_COLOR,clr1); ObjectSetInteger(ChartID(),vline_2, OBJPROP_SELECTED, true); ChartSetInteger(ChartID(),CHART_EVENT_MOUSE_MOVE,true); return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { ObjectsDeleteAll(0,vline); ObjectsDeleteAll(0,vline_2); ObjectsDeleteAll(0,"TrendLine"); ObjectsDeleteAll(0,"TrendLine_a"); ObjectsDeleteAll(0,"TrendLine_b"); ObjectsDeleteAll(0,"TrendLine_c"); ObjectsDeleteAll(0,"TrendLine_d"); } bool IsNewBar(){ static datetime previousTime = 0; datetime currentTime=iTime(_Symbol,PERIOD_CURRENT,0); if(previousTime!=currentTime){ previousTime=currentTime; return true; } return false; } int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { func1(); //Print("final_time_dotor=",final_time); //if(IsNewBar()){ //Print("final_time_dotor=",final_time); //Print("final_time2_dotor=",final_time2); //Print("final_time_bar=",iBarShift(_Symbol,PERIOD_CURRENT,final_time)); //Print("final_time2_bar=",iBarShift(_Symbol,PERIOD_CURRENT,final_time2)); //func1(); //} return(rates_total); } void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { if(id==CHARTEVENT_OBJECT_CLICK && sparam==vline && vline!="" && !is_object_being_dragged) { if(ObjectGetInteger(0,vline,OBJPROP_SELECTED)) { is_object_being_dragged=true; time_a=ObjectGetInteger(0,vline,OBJPROP_TIME); } if(!ObjectGetInteger(0,vline,OBJPROP_SELECTED)) is_object_being_dragged=false; } if(id==CHARTEVENT_MOUSE_MOVE && is_object_being_dragged) { double time_a_sub=ObjectGetInteger(0,vline,OBJPROP_TIME); if(time_a_sub!=time_a) { time_a=time_a_sub; Print("New Drag Price : "+ time_a); } } if(id==CHARTEVENT_OBJECT_DRAG && is_object_being_dragged) { double time_a_sub= ObjectGetInteger(0,vline,OBJPROP_TIME); time_a=time_a_sub; Print("Final Price : "+(datetime) time_a); final_time=(datetime) time_a; Print("Final time : "+final_time); is_object_being_dragged=false; } if(id==CHARTEVENT_OBJECT_CLICK&&sparam==vline_2&&vline_2!=""&&!is_object_being_dragged2) { if(ObjectGetInteger(0,vline_2,OBJPROP_SELECTED)) { is_object_being_dragged2=true; time_b=ObjectGetInteger(0,vline_2,OBJPROP_TIME); } if(!ObjectGetInteger(0,vline_2,OBJPROP_SELECTED)) is_object_being_dragged2=false; } if(id==CHARTEVENT_MOUSE_MOVE&&is_object_being_dragged2) { double time_b_sub=ObjectGetInteger(0,vline_2,OBJPROP_TIME); if(time_b_sub!=time_b) { time_b=time_b_sub; Print("New Drag Price2 : "+ time_b); } } if(id==CHARTEVENT_OBJECT_DRAG&&is_object_being_dragged2) { double time_b_sub= ObjectGetInteger(0,vline_2,OBJPROP_TIME); time_b=time_b_sub; Print("Final Price2 : "+(datetime) time_b); final_time2=(datetime) time_b; Print("Final time2 : "+final_time2); is_object_being_dragged2=false; } } void func1() { //here regression trend line calculation }
This is code. It create trend line with moving interval of vertical lines. When new bar creates it holds position of start date and end date. I run it at 1h timeframe. Then i applied synchronizer it can not draw trend line at 5 minute timeframe.
but it can draw vertical lines at 5 minute timeframe. :-)
1. I cannot see a OBJ_TREND. I can see two vertical lines(OBJ_VLINE).
2. What your code is doing is :
Create two vertical lines ==> one at first closed bar and the other at 10th closed bar.
What exactly do you expect? Every time you change time frame it will reload the indicator and create those lines respective to the new chart.
1. I cannot see a OBJ_TREND. I can see two vertical lines(OBJ_VLINE).
2. What your code is doing is :
Create two vertical lines ==> one at first closed bar and the other at 10th closed bar.
What exactly do you expect? Every time you change time frame it will reload the indicator and create those lines respective to the new chart.
in void func1() trend line calculation. I omitted calculation code here. I wonder why trend line could not synchronized.
#property copyright "Copyright 2023, MetaQuotes Ltd." #property link "https://www.mql5.com" #property version "1.00" #property indicator_chart_window string vline="vertical_line"; string vline_2="vertical_line_2"; bool is_object_being_dragged=false; bool is_object_being_dragged2=false; int time_a=0; int time_b=0; int i=0; datetime final_time; datetime final_time2; double std_channel_1 = 1; double std_channel_2 = 2; int n; double a, b, c, sumy, sumx, sumxy, sumx2, value,iClose[]; datetime iTime[]; int endbar; int startbar; color clr1=StringToColor("40,40,40"); color clr_tline=StringToColor("56,1,124"); int OnInit() { bool obj=ObjectCreate(ChartID(),vline,OBJ_VLINE,0,iTime(_Symbol,PERIOD_CURRENT,1),0); bool obj2=ObjectCreate(ChartID(),vline_2,OBJ_VLINE,0,iTime(_Symbol,PERIOD_CURRENT,10),0); final_time2= ObjectGetInteger(0,vline,OBJPROP_TIME); final_time= ObjectGetInteger(0,vline_2,OBJPROP_TIME); //Print("curr_time",+final_time); //Print("i=",+i); ObjectSetInteger(ChartID(),vline,OBJPROP_SELECTABLE,true); ObjectSetInteger(ChartID(),vline,OBJPROP_WIDTH,2); ObjectSetInteger(ChartID(),vline,OBJPROP_BACK,true); ObjectSetInteger(ChartID(),vline,OBJPROP_COLOR,clr1); ObjectSetInteger(ChartID(),vline, OBJPROP_SELECTED, true); ChartSetInteger(ChartID(),CHART_EVENT_MOUSE_MOVE,true); ObjectSetInteger(ChartID(),vline_2,OBJPROP_SELECTABLE,true); ObjectSetInteger(ChartID(),vline_2,OBJPROP_WIDTH,2); ObjectSetInteger(ChartID(),vline_2,OBJPROP_BACK,true); ObjectSetInteger(ChartID(),vline_2,OBJPROP_COLOR,clr1); ObjectSetInteger(ChartID(),vline_2, OBJPROP_SELECTED, true); ChartSetInteger(ChartID(),CHART_EVENT_MOUSE_MOVE,true); return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { ObjectsDeleteAll(0,vline); ObjectsDeleteAll(0,vline_2); ObjectsDeleteAll(0,"TrendLine"); ObjectsDeleteAll(0,"TrendLine_a"); ObjectsDeleteAll(0,"TrendLine_b"); ObjectsDeleteAll(0,"TrendLine_c"); ObjectsDeleteAll(0,"TrendLine_d"); } bool IsNewBar(){ static datetime previousTime = 0; datetime currentTime=iTime(_Symbol,PERIOD_CURRENT,0); if(previousTime!=currentTime){ previousTime=currentTime; return true; } return false; } int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { func1(); //Print("final_time_dotor=",final_time); //if(IsNewBar()){ //Print("final_time_dotor=",final_time); //Print("final_time2_dotor=",final_time2); //Print("final_time_bar=",iBarShift(_Symbol,PERIOD_CURRENT,final_time)); //Print("final_time2_bar=",iBarShift(_Symbol,PERIOD_CURRENT,final_time2)); //func1(); //} return(rates_total); } void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { if(id==CHARTEVENT_OBJECT_DRAG) { final_time2= ObjectGetInteger(0,vline,OBJPROP_TIME); final_time= ObjectGetInteger(0,vline_2,OBJPROP_TIME); func1(); } } void func1() { startbar=iBarShift(_Symbol, PERIOD_CURRENT, final_time, false); endbar=iBarShift(_Symbol, PERIOD_CURRENT, final_time2, false); double price1=iClose(_Symbol, PERIOD_CURRENT, startbar); double price2=iClose(_Symbol, PERIOD_CURRENT, endbar); ObjectCreate(ChartID(), "TrendLine", OBJ_TREND, 0, final_time, price1, final_time2, price2); }
#property copyright "Copyright 2023, MetaQuotes Ltd." #property link "https://www.mql5.com" #property version "1.00" #property indicator_chart_window string vline="vertical_line"; string vline_2="vertical_line_2"; bool is_object_being_dragged=false; bool is_object_being_dragged2=false; int time_a=0; int time_b=0; int i=0; datetime final_time; datetime final_time2; double std_channel_1 = 1; double std_channel_2 = 2; int n; double a, b, c, sumy, sumx, sumxy, sumx2, value,iClose[]; datetime iTime[]; int endbar; int startbar; color clr1=StringToColor("40,40,40"); color clr_tline=StringToColor("56,1,124"); int OnInit() { EventSetMillisecondTimer(100); bool obj=ObjectCreate(ChartID(),vline,OBJ_VLINE,0,iTime(_Symbol,PERIOD_CURRENT,1),0); bool obj2=ObjectCreate(ChartID(),vline_2,OBJ_VLINE,0,iTime(_Symbol,PERIOD_CURRENT,10),0); final_time2= ObjectGetInteger(0,vline,OBJPROP_TIME); final_time= ObjectGetInteger(0,vline_2,OBJPROP_TIME); //Print("curr_time",+final_time); //Print("i=",+i); ObjectSetInteger(ChartID(),vline,OBJPROP_SELECTABLE,true); ObjectSetInteger(ChartID(),vline,OBJPROP_WIDTH,2); ObjectSetInteger(ChartID(),vline,OBJPROP_BACK,true); ObjectSetInteger(ChartID(),vline,OBJPROP_COLOR,clr1); ObjectSetInteger(ChartID(),vline, OBJPROP_SELECTED, true); ChartSetInteger(ChartID(),CHART_EVENT_MOUSE_MOVE,true); ObjectSetInteger(ChartID(),vline_2,OBJPROP_SELECTABLE,true); ObjectSetInteger(ChartID(),vline_2,OBJPROP_WIDTH,2); ObjectSetInteger(ChartID(),vline_2,OBJPROP_BACK,true); ObjectSetInteger(ChartID(),vline_2,OBJPROP_COLOR,clr1); ObjectSetInteger(ChartID(),vline_2, OBJPROP_SELECTED, true); ChartSetInteger(ChartID(),CHART_EVENT_MOUSE_MOVE,true); return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { EventKillTimer(); ObjectsDeleteAll(0,vline); ObjectsDeleteAll(0,vline_2); ObjectsDeleteAll(0,"TrendLine"); ObjectsDeleteAll(0,"TrendLine_a"); ObjectsDeleteAll(0,"TrendLine_b"); ObjectsDeleteAll(0,"TrendLine_c"); ObjectsDeleteAll(0,"TrendLine_d"); } int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { return(rates_total); } void OnTimer() { final_time2= ObjectGetInteger(0,vline,OBJPROP_TIME); final_time= ObjectGetInteger(0,vline_2,OBJPROP_TIME); startbar=iBarShift(_Symbol, PERIOD_CURRENT, final_time, false); endbar=iBarShift(_Symbol, PERIOD_CURRENT, final_time2, false); double price1=iClose(_Symbol, PERIOD_CURRENT, startbar); double price2=iClose(_Symbol, PERIOD_CURRENT, endbar); ObjectCreate(ChartID(), "TrendLine", OBJ_TREND, 0, final_time, price1, final_time2, price2); }

- 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, if someone faced this issue before. Please advise me.
I created trend line indicator which has start date and end date of moving vertical line.
Indicator works correct. I run it at 1h timeframe and it drawn trend line. Then I applied synchronizer at 1h and 5minute timeframe.
trend line could not appear at 5 minute timeframe. There is only two vertical line of interval appearing at 5 minute timeframe.
how to sync trend line at 5 minute timeframe?
How to solve this issue?
Thank you