stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

MTF indicator help
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=5633
Page 1 of 2
Author:  c1borg [ Mon Mar 04, 2019 7:15 am ]
Post subject:  MTF indicator help

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
Author:  eRIKb81 [ Mon Mar 04, 2019 10:38 am ]
Post subject:  MTF indicator help

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.
Author:  c1borg [ Mon Mar 04, 2019 11:15 am ]
Post subject:  MTF indicator help

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); 
Author:  eRIKb81 [ Mon Mar 04, 2019 11:32 am ]
Post subject:  MTF indicator help

Hmm, just the TDJC indicator? I Get different results, H1 on top, H4 below. Try it with a fresh Empty4?
Author:  c1borg [ Mon Mar 04, 2019 11:39 am ]
Post subject:  MTF indicator help

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
Author:  eRIKb81 [ Mon Mar 04, 2019 12:01 pm ]
Post subject:  MTF indicator help

You could add something like

Code: Select all

IndicatorSetString(INDICATOR_SHORTNAME, TimeFrame);
to the init function, that will show you the timeframe in minutes.
Author:  c1borg [ Mon Mar 04, 2019 12:18 pm ]
Post subject:  MTF indicator help

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:
Author:  c1borg [ Mon Mar 04, 2019 2:03 pm ]
Post subject:  MTF indicator help

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?
Author:  tomele [ Mon Mar 04, 2019 5:09 pm ]
Post subject:  MTF indicator help

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
Author:  c1borg [ Mon Mar 04, 2019 6:06 pm ]
Post subject:  MTF indicator help

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.
All times are UTC Page 1 of 2