MTF indicator help

The forum for experienced coders to upload their helpful hints, tips and lessons.
User avatar
c1borg
Trader
Posts: 456
Joined: Sun Aug 14, 2016 5:09 pm

MTF indicator help

Post by c1borg »

I am diving in to Empty4 and having some success but stuck on something thats probably easy for you coders out there. I have an indicator which works on current chart timeframe, however I want to make it MTF, in otherwords set a fixed time frame which is different from the chart timeframe.

I have added

Code: Select all

input  ENUM_TIMEFRAMES     TimeFrame        =  PERIOD_H4;
and used the TimeFrame like this

Code: Select all

 //Indicator Buffer 1
      if(iCustom(NULL, TimeFrame, "JMA_StarLight-signal", 5, 4, 0, 0, 0, i) > iCustom(NULL, TimeFrame, "JMA_StarLight-base", 7, 4, 0, 0, 0, i)) //JMA_StarLight-signal > JMA_StarLight-base
        {
         Buffer1[i] = Low[i]; //Set indicator value at Candlestick Low
         if(i == 1 && Time[1] != time_alert) myAlert("indicator", "Buy");  //Alert on next bar open
         time_alert = Time[1];
        }
      else
        {
         Buffer1[i] = 0;
        }
and here

Code: Select all

// TDesk code.
   TDESKSIGNALS signal = FLAT;
   if(iCustom(NULL, TimeFrame, "JMA_StarLight-signal", 5, 4, 0, 0, 0, 0) > iCustom(NULL, TimeFrame, "JMA_StarLight-base", 7, 4, 0, 0, 0, 0)) signal = LONG;
   if(iCustom(NULL, TimeFrame, "JMA_StarLight-signal", 5, 4, 0, 0, 0, 0) < iCustom(NULL, TimeFrame, "JMA_StarLight-base", 7, 4, 0, 0, 0, 0)) signal = SHORT;
But when I switch timeframes on the chart the indicator still displays the current time frame?

Any help/guidance appreciated :smile:

Indicator(s) attached
You do not have the required permissions to view the files attached to this post.
eRIKb81
Trader
Posts: 22
Joined: Wed Jul 05, 2017 6:03 am

MTF indicator help

Post by eRIKb81 »

My first guess is it has to do with the line

Code: Select all

PublishTDeskSignal("TDJC",(ENUM_TIMEFRAMES)Period(),Symbol(),signal);
You use 'TimeFrame' everywhere, except when you publish the signals, there you use the current chart timeframe.

This is how the example code looks:

Code: Select all

if(SendTDeskSignals)
      {
         if(Signal!=OldSignal) {
            PublishTDeskSignal("SS",TimeFrame,Symbol(),Signal);
            OldSignal=Signal;
         }
      }
Does that solve things? I'm a bit lazy and not testing it, because this indicator is abracadabra to me.
User avatar
c1borg
Trader
Posts: 456
Joined: Sun Aug 14, 2016 5:09 pm

MTF indicator help

Post by c1borg »

eRIKb81 » Mon Mar 04, 2019 10:38 am wrote:My first guess is it has to do with the line

Code: Select all

PublishTDeskSignal("TDJC",(ENUM_TIMEFRAMES)Period(),Symbol(),signal);
You use 'TimeFrame' everywhere, except when you publish the signals, there you use the current chart timeframe.

This is how the example code looks:

Code: Select all

if(SendTDeskSignals)
      {
         if(Signal!=OldSignal) {
            PublishTDeskSignal("SS",TimeFrame,Symbol(),Signal);
            OldSignal=Signal;
         }
      }
Does that solve things? I'm a bit lazy and not testing it, because this indicator is abracadabra to me.
I see what you are saying and that might be a problem with the indicator output to TDesk I hadnt thought of. If I put a version set at 1H (the top one) in the picture and the other at 4H (the bottom one) I get the same histogram which cant be right?
Screenshot.png
This code seems to be ok

Code: Select all

PublishTDeskSignal("TDJC",(ENUM_TIMEFRAMES)TimeFrame,Symbol(),signal); 
You do not have the required permissions to view the files attached to this post.
eRIKb81
Trader
Posts: 22
Joined: Wed Jul 05, 2017 6:03 am

MTF indicator help

Post by eRIKb81 »

Hmm, just the TDJC indicator? I Get different results, H1 on top, H4 below. Try it with a fresh Empty4?
You do not have the required permissions to view the files attached to this post.
User avatar
c1borg
Trader
Posts: 456
Joined: Sun Aug 14, 2016 5:09 pm

MTF indicator help

Post by c1borg »

Ok think ive done it at least the indicators histograms are now different how do I display the indicator set timeframe on each indicator?
Screenshot.png
Capture.PNG
You do not have the required permissions to view the files attached to this post.
eRIKb81
Trader
Posts: 22
Joined: Wed Jul 05, 2017 6:03 am

MTF indicator help

Post by eRIKb81 »

You could add something like

Code: Select all

IndicatorSetString(INDICATOR_SHORTNAME, TimeFrame);
to the init function, that will show you the timeframe in minutes.
User avatar
c1borg
Trader
Posts: 456
Joined: Sun Aug 14, 2016 5:09 pm

MTF indicator help

Post by c1borg »

Managed even better :clap: now displays H4 etc top left of indicator window

Code: Select all

string tftext=EnumToString(TimeFrame);
   StringReplace(tftext,"PERIOD_","");
   IndicatorShortName(WindowExpertName()+" - "+tftext);
Thanks again for the pointers :hi:
User avatar
c1borg
Trader
Posts: 456
Joined: Sun Aug 14, 2016 5:09 pm

MTF indicator help

Post by c1borg »

Another question, in order to stop flip flopping I have added this code.

Code: Select all

{
         Buffer1[i] = Close[1+i]; //Set indicator value at Candlestick Close
         if(i == 1 && Time[1] != time_alert) myAlert("indicator", "Buy");  //Alert on next bar open
         time_alert = Time[1];
        }
Is this correct?
User avatar
tomele
Administrator
Posts: 1208
Joined: Tue May 17, 2016 3:40 pm
Location: Germany, Forest of Odes, Defending the Limes

MTF indicator help

Post by tomele »

Hi Nev.

Although I don't have the time to help you with all your questions, here is a general tip for you. I did it this way when I started to code MQL4:

Whenever you want to add something to your code, find another code that does what you imagine. Then read and work to understand this code. Study the MQL4 reference for each statement you don't fully understand. Now try to adapt the code to your needs, play with it and voila - suddenly there you go.

Best wishes
Thomas
Happy pippin, Thomas :-BD

It ain't what you don't know that gets you into trouble.
It's what you know for sure that just ain't so.
(Mark Twain)

Keep the coder going: Donate
User avatar
c1borg
Trader
Posts: 456
Joined: Sun Aug 14, 2016 5:09 pm

MTF indicator help

Post by c1borg »

tomele » Mon Mar 04, 2019 5:09 pm wrote:Hi Nev.

Although I don't have the time to help you with all your questions, here is a general tip for you. I did it this way when I started to code MQL4:

Whenever you want to add something to your code, find another code that does what you imagine. Then read and work to understand this code. Study the MQL4 reference for each statement you don't fully understand. Now try to adapt the code to your needs, play with it and voila - suddenly there you go.

Best wishes
Thomas
Good advice and funnily enough thats what seems to be happening, the indy is now working as expected and its really satisfying to do it yourself (with a little help) :smile:

I will continue making some more tweaks.
Post Reply

Return to “Coding Lessons - info for all”