Problem with MTF Trendline Indicator

Kaloko
725
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?


#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


Kaloko
725
Kaloko  
Is there somebody that could help me with this issue please?
William Roeder
23727
William Roeder  
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

Kaloko
725
Kaloko  
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?

Keith Watford
Moderator
26609
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.

Kaloko
725
Kaloko  
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);
  }
Keith Watford
Moderator
26609
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.

Kaloko
725
Kaloko  
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

Keith Watford
Moderator
26609
Keith Watford  
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.