fxDreema

    • Register
    • Login
    • Search
    • Back to the main page
    • Categories
    • Recent
    • Tags
    • Popular
    • Search

    Call a function for calculating next higher timeframe ** SOLVED **

    Questions & Answers
    7
    10
    2241
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T
      trader.philipps last edited by trader.philipps

      Hi folks, looks like today I'm a little stupid. One of my indicators requires the input of a timeframe. In order to make it flexible, I'd like to calculate the next higher timerframe. For instance if chart timeframe is H1 it should return H4, . for M15 -> M30 and so on.
      I create that project Next Timeframe Project and hope that someone can help me.

      In details:
      I copied a sample code from mql5.com:

      //+---------------------------------------------------------------------+
      //| subGetNextTimeFrame function - returns the next timeframe |
      //+---------------------------------------------------------------------+
      int subGetNextTimeFrame()
      {
      int TimeFrames[9] = { 1,5,15,30,60,240,1440,10080,43200 };
      int CurrentTimeIndex = ArrayBsearch(TimeFrames,_Period,8,0,MODE_ASCEND);
      return((ENUM_TIMEFRAMES) TimeFrames[CurrentTimeIndex+1]);
      }

      and put it on "on Init" tab in a custom code block. However, I fail to call that function somehow and receive the error "'subGetNextTimeFrame' - function can be declared only in the global scope".

      What am I doing wrong?

      I like to share my knowledge, but expect the others to contribute as well.

      T 1 Reply Last reply Reply Quote 0
      • T
        trader.philipps @trader.philipps last edited by trader.philipps

        I found the solution. I do the following in the on Init tab:
        0_1567721558667_Auswahl_514.png

        The in variables vi_current_timeframe and vi_next_timeframe I defined in variables as integer.

        Here the code if someone wants to do the same:

        //
        int TimeFrames_cust[9] = { 1,5,15,30,60,240,1440,10080,43200 };
        int CurrentTimeIndex = ArrayBsearch(TimeFrames_cust,_Period,8,0,MODE_ASCEND);

        vi_current_timeframe= (ENUM_TIMEFRAMES) TimeFrames_cust[CurrentTimeIndex];
        vi_next_timeframe= (ENUM_TIMEFRAMES) TimeFrames_cust[CurrentTimeIndex+1];
        //

        I like to share my knowledge, but expect the others to contribute as well.

        C Zackry 2 Replies Last reply Reply Quote 3
        • C
          CPxiom @trader.philipps last edited by

          @trader-philipps Wow thanks, this is very helpful.

          1 Reply Last reply Reply Quote 0
          • l'andorrà
            l'andorrà last edited by l'andorrà

            Impressive! 😮 This is why coders will always beat all of us simple fxDreema users 😄

            (English) I will try to help everyone in these fxDreema forums. But if you want to learn how to use the platform in depth or more quickly, I can help you with my introductory fxDreema course in English at https://www.theandorraninvestor.eu.

            (Català) Miraré d’ajudar tothom en aquests fòrums d’fxDreema. Tanmateix, si vols aprendre a fer servir la plataforma amb més profunditat o més de pressa, t’hi puc ajudar amb el meu curs d’introducció a fxDeema en català a https://www.theandorraninvestor.eu/ca.

            (Español) Intentaré ayudar a todo el mundo en estos foros de fxDreema. Sin embargo, si quieres aprender a usar la plataforma en profundidad o más deprisa, te puedo ayudar con mi curso de introducción a fxDreema en español en https://www.theandorraninvestor.eu/es.

            1 Reply Last reply Reply Quote 0
            • Zackry
              Zackry @trader.philipps last edited by Zackry

              @trader-philipps hi Philipps , do you think this would work: 0_1578657729276_Screenshot_5.png

              i am using the code you provided, the idea is to save a price level in variable , let say the ea is attached to m1 and once a price level is saved the ea should look on to the next higher timeframe and see if the candle closes above that level or not ,

              T 1 Reply Last reply Reply Quote 0
              • T
                trader.philipps @Zackry last edited by

                @zackry Should work. I use it the same way in one of my current projects in order to use an indicator on next higher timeframes.

                I like to share my knowledge, but expect the others to contribute as well.

                1 Reply Last reply Reply Quote 0
                • B
                  bhadzLagayan last edited by

                  will this work in reverse? like I need the next lower timeframe?

                  TipsyWisdom 1 Reply Last reply Reply Quote 0
                  • TipsyWisdom
                    TipsyWisdom @bhadzLagayan last edited by

                    @bhadzlagayan said in Call a function for calculating next higher timeframe ** SOLVED **:

                    will this work in reverse? like I need the next lower timeframe?

                    The code would need to be changed, but yes, it could.

                    1 Reply Last reply Reply Quote 0
                    • iKnow
                      iKnow last edited by

                      Since the initialization of this is done, in the OnInit() function, add a condition to prevent "out of range" that is if am in the lowest TF in my array, they is no need adding 1 (for the next HTF) or subtracting 1 (for the next LTF), it should just output a message letting you know.

                      If you know, you know, if you don't, you know when you know.
                      Signed:iKnow

                      1 Reply Last reply Reply Quote 0
                      • B
                        bhadzLagayan last edited by

                        Thank you for the reply. Turns out you can directly code.

                        You can call the function Period(). This will give you the current timeframe then use if else or swtich to lower it down.

                        If ( Period() == PERIOD_H4 ) TF = PERIOD_H1;

                        Not elegant, i know, but works. Just make sure that the TF is a variable with a ENUM_TIMEFRAMES as the type.

                        1 Reply Last reply Reply Quote 0
                        • 1 / 1
                        • First post
                          Last post

                        Online Users

                        E
                        N
                        N
                        F
                        M
                        A
                        L
                        O
                        S

                        24
                        Online

                        146.7k
                        Users

                        22.4k
                        Topics

                        122.6k
                        Posts

                        Powered by NodeBB Forums | Contributors