Problem with MTF Trendline Indicator

 

Hello i want to create a trendline on 4hr Timeframe and access the starting point price of the trendline (or any shift of the trendline) on all the other timeframes.


From 1min to Daily timeframes i get the correct price but on weekly and montlhy the price i get is 0


How can i get the correct price on all timeframes. Is there any prblem on my code or there is a problem on mql4 language?


#property copyright "Copyright 2020, "
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

int Timeframe=240;

int OnInit()
  {
//--- indicator buffers mapping
   
   
   int StartPoint=13;
   int EndPoint=8;

string label="Trendline";



       if(ObjectFind(NULL,label)==0)
       ObjectDelete(label);

   
   ObjectCreate(label, OBJ_TREND, 0, iTime(NULL,Timeframe,StartPoint),iLow(NULL,Timeframe,StartPoint), iTime(NULL,Timeframe,EndPoint),iLow(NULL,Timeframe,EndPoint), 0, 0);
   
 
          Print("Start Trendline Value :"+ObjectGetValueByTime(NULL,label,iTime(NULL,Timeframe,StartPoint),0));
          Print("End Trendline Value :"+ObjectGetValueByTime(NULL,label,iTime(NULL,Timeframe,EndPoint),0));

          Print("StartPoint "+Timeframe+" "+StartPoint);

   
   
   
//---
   return(INIT_SUCCEEDED);
  }


Here are the results i get


 
Is there somebody that could help me with this issue please?
 
Kaloko: From 1min to Daily timeframes i get the correct price but on weekly and montlhy the price i get is 0
  1. Weekly/Monthly is not supported in the tester.
              'Testing Features and Limits in MetaTrader 4' - MQL4 Articles 2012 (The comment about “Zero bar of another timeframe,” is no longer valid.)

  2. On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
              Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26.4 2019.05.20

 
William Roeder:
  1. Weekly/Monthly is not supported in the tester.
              'Testing Features and Limits in MetaTrader 4' - MQL4 Articles 2012 (The comment about “Zero bar of another timeframe,” is no longer valid.)

  2. On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
              Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26.4 2019.05.20

I am not testing it on strategy tester..


Also i am not trying to access a candle or an indicator..

I want to use GetValueByTime and get the value of a trendline that was created on 4hr timeframe....but on daily weekly and monhtly i get 0

Also if create the trendline on 30min timeframe i get 0 value on timeframes above 30min

How can i get the values of trendline on all the timeframes?

 

Do not double post!

I have deleted your duplicated topic.

I want to use GetValueByTime and get the value of a trendline that was created on 4hr timeframe....but on daily weekly and monhtly i get 0

Show the code if you want help.

 
Keith Watford:

Do not double post!

I have deleted your duplicated topic.

I want to use GetValueByTime and get the value of a trendline that was created on 4hr timeframe....but on daily weekly and monhtly i get 0

Show the code if you want help.

This is the code. I have posted on the first post too. Ant help woud be much appreciated.

#property copyright "Copyright 2020, "
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

int Timeframe=240;

int OnInit()
  {
//--- indicator buffers mapping
   
   
   int StartPoint=13;
   int EndPoint=8;

string label="Trendline";



       if(ObjectFind(NULL,label)==0)
       ObjectDelete(label);

   
   ObjectCreate(label, OBJ_TREND, 0, iTime(NULL,Timeframe,StartPoint),iLow(NULL,Timeframe,StartPoint), iTime(NULL,Timeframe,EndPoint),iLow(NULL,Timeframe,EndPoint), 0, 0);
   
 
          Print("Start Trendline Value :"+ObjectGetValueByTime(NULL,label,iTime(NULL,Timeframe,StartPoint),0));
          Print("End Trendline Value :"+ObjectGetValueByTime(NULL,label,iTime(NULL,Timeframe,EndPoint),0));

          Print("StartPoint "+Timeframe+" "+StartPoint);

   
   
   
//---
   return(INIT_SUCCEEDED);
  }
 

This is one of the reasons why, in my opinion, you should only use trend-lines on the TF where they are drawn.

Although the 2 time anchors are different on the H4 chart, on the weekly chart both of them are within the same bar. This means that the trendline is vertical and that is why you are getting 0.

Try a start and end  point that are in different weeks and you will get values.

 
Keith Watford:

This is one of the reasons why, in my opinion, you should only use trend-lines on the TF where they are drawn.

Although the 2 time anchors are different on the H4 chart, on the weekly chart both of them are within the same bar. This means that the trendline is vertical and that is why you are getting 0.

Try a start and end  point that are in different weeks and you will get values.

Yes the start and end point work fine...but i have problem when i try to get the price of other shifts of the trendline...

Is there any other way that could make it work...i have to create an MTF Trendline indicator and get prices from all shifts of the trendline

 
Kaloko:

Yes the start and end point work fine...but i have problem when i try to get the price of other shifts of the trendline...

Is there any other way that could make it work...i have to create an MTF Trendline indicator and get prices from all shifts of the trendline

Did you read my post that you have quoted?

Keith Watford:

This is one of the reasons why, in my opinion, you should only use trend-lines on the TF where they are drawn.

Although the 2 time anchors are different on the H4 chart, on the weekly chart both of them are within the same bar. This means that the trendline is vertical and that is why you are getting 0.

Try a start and end  point that are in different weeks and you will get values.

If the trend-line is vertical there are no other shifts to get values from.

 
Kaloko:

Hello i want to create a trendline on 4hr Timeframe and access the starting point price of the trendline (or any shift of the trendline) on all the other timeframes.


From 1min to Daily timeframes i get the correct price but on weekly and montlhy the price i get is 0


How can i get the correct price on all timeframes. Is there any prblem on my code or there is a problem on mql4 language?

Here are the results i get


There is error : the name of the line is not the same

  if(ObjectFind(NULL,label)==0)
       ObjectDelete(label);

   
   ObjectCreate(label, OBJ_TREND, 0, iTime(NULL,Timef 

ObjectGetValueByTime(NULL,label,iTime(NU

And also you have to add a  fonction :  int start()

 
ffoorr:

There is error : the name of the line is not the same

And also you have to add a  fonction :  int start()

 ObjectGetTimeByShift require an id_chart

in the others fonctions it is facultative, we can put an chart_id or not.

OjectCreate have to have a chart_id, so the name of the line is the same in the two fonctions

double  ObjectGetValueByTime( 
   long       chart_id,      // chart ID 
   string     object_name,   // object name 
   datetime   time,          // time 
   int        line_id=0      // line ID 
   );
bool  ObjectCreate( 
   long          chart_id,      // chart ID 
   string        object_name,   // object name 
   ENUM_OBJECT   object_type,   // object type 
   int           sub_window,    // window index 
   datetime      time1,         // time of the first anchor point 
   double        price1,        // price of the first anchor point 
   ... 
   datetime      timeN=0,       // time of the N-th anchor point 
   double        priceN=0       // price of the N-th anchor point 
   );
 

The function creates an object with the specified name, type, and the initial coordinates in the specified chart subwindow:



bool  ObjectCreate( 
   string        object_name,   // object name 
   ENUM_OBJECT   object_type,   // object type 
   int           sub_window,    // window index 
   datetime      time1,         // time of the first anchor point 
   double        price1,        // price of the first anchor point 
   datetime      time2=0,       // time of the second anchor point 
   double        price2=0,      // price of the second anchor point 
   datetime      time3=0,       // time of the third anchor point 
   double        price3=0       // price of the third anchor point 
   );
 
Reason: