fxDreema

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

    GlobalVariableSet - how to?

    Questions & Answers
    4
    18
    10594
    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.
    • H
      haidang8055 @fxDreema last edited by

      @fxdreema i created a EA with terminal variables block. then i add my EA to chart, press F3 to use Global variable, i can change value but when i press CLOSE button and F3 again, the value is not changed value, it is value that i have chosen in terminal variables block of EA. i dont understand and wonder how to change value when use Global variable to run EA with new value

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

        I'd like to set a previously defined global variable with a new value. My reading of MQL4 Book says I should use GlobalVariableSet.

        How do I achieve this in fxdreema? I apologise in advance if I've missed the obvious!

        Thanks.

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

          There is a block named "Set Global Variables in MT4", scroll down to the yellow blocks. To get the value... somewhere inside Condition.

          1 Reply Last reply Reply Quote 0
          • J
            james last edited by

            I'm clearly doing something wrong, but I can't work out what! Sorry. 😞

            Here's my EA: http://fxdreema.com/shared/pRvat0Hjd

            Its a much simplified version of one I'm working on. In it I'm taking the results of 3 formulae, and making "CurrentGV" equal to their result.

            Then on the next time interval, I'm making "PreviousGV" equal to "CurrentGV", and then calculating a new "CurrentGV".

            But when I run this EA, MT4 says "the name parameter for GlobalVariableCheck function must be a string".

            Where have I gone wrong?

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

              There are two types of global variables in MQL4. First one is... normal global variables, they are defined at the top of the code. They are global for the EA only. In fxDreema they are used for Constants, Variables and Formula results. The other type are global variables that can be accessed from all the other EA's on the same platform, they are just some values global for the MT4 platform, and these stays in (file) memory for 4 weeks. These are manipulated with all the GlobalVariableX functions. Click F3 on MT4 to see them.

              H 1 Reply Last reply Reply Quote 0
              • J
                james last edited by

                I'm really sorry about this, causing you more hassle!

                I don't seem to be able to get this to work at all. I've tried every which way I can think to get my little example to work: http://fxdreema.com/shared/Whla30wSd

                Does it work for you?

                For this purpose, I don't need the global value to be in the client terminal, which I think the "Set Global Variables in MT4" block does. I just need it to be global to the EA itself. I'm assuming that I'd set these in the "Constants" and "Variables" link near the top right of fxdreema.

                I did a little digging also. The information on http://docs.mql4.com/globals/GlobalVariableCheck says the syntax is:
                __if(!GlobalVariableCheck("g1"))[/quote:1oy8vjws]

                The code generated by the "Set Global Variables in MT4" block in fxdreema says:
                __if (GlobalVariableCheck(CurrentGV)==false) {return(0);}[/quote:1oy8vjws]

                There seems to be a difference in the "GlobalVariableCheck" statements where one uses "" around the variable's name and the other doesn't.

                This may not be relevant. Its just that I noticed it.

                If you take a look at http://fxdreema.com/shared/6c9bDxZ8, I've tried a slightly different approach. Although it doesn't work, since the variable "PreviousGV" doesn't get updated, it doesn't give me the "GlobalVariableCheck function must be a string" error in MT4.

                Here's the code I've put inside the "Custom MQL4 code" block:

                //==========================
                //        PreviousGV = CurrentGV
                //==========================
                double value_1=GlobalVariableGet("CurrentGV") ;
                //if(GetLastError()!=0) return(false) ;
                double PreviousGV=value_1 ;
                
                //==========================
                //        CALCULATE CurrentGV
                //==========================
                double CurrentGV=Result1+Result2+Result3 ;
                
                //==========================
                //          DISPLAY RESULTS
                //==========================
                Comment(
                "Account free margin is  ", DoubleToStr(AccountFreeMargin(),2),
                "\nCurrent date is ",TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES|TIME_SECONDS),
                "\nCurrentGV is ",CurrentGV,
                "\nPreviousGV is ",PreviousGV,
                "\nvalue_1 ",value_1) ;
                
                

                As I say, the updating of PreviousGV with the value in CurrentGV doesn't work (I commented out the GetLastError statement to let the EA continue to run). Would you mind very much telling me what I need to put here? Or is there a way of doing this using blocks in fxdreema?

                I'm so grateful for your help, and sorry to be a nuisance - again!

                1 Reply Last reply Reply Quote 0
                • J
                  james last edited by

                  Hooray! I've just found the problem! After much messing around due to my lack of knowledge...

                  Changing this:
                  __//==========================
                  // PreviousGV = CurrentGV
                  //==========================
                  double value_1=GlobalVariableGet("CurrentGV") ;
                  //if(GetLastError()!=0) return(false) ;
                  double PreviousGV=value_1 ;[/quote:36di6mp1]
                  ...to this:
                  __//==========================
                  // PreviousGV = CurrentGV
                  //==========================
                  double value_1=GlobalVariableGet("CurrentGV") ;
                  //if(GetLastError()!=0) return(false) ;
                  PreviousGV=value_1 ;[/quote:36di6mp1]
                  ...did the trick!

                  I suppose what I was doing was re-initalising PreviousGV every time by the use of the "double" function.

                  So simple... but took me ages! I'm not cut out to be a programmer! I'll leave that to fxdreema - the expert!

                  Just one thing: should it be
                  __... as generated by the "Set Global Variables in MT4" block in fxdreema

                  GlobalVariableCheck(CurrentGV)[/quote:36di6mp1]
                  or
                  __... as on http://docs.mql4.com/globals/GlobalVariableCheck

                  GlobalVariableCheck("CurrentGV")[/quote:36di6mp1]
                  ??? 🙂

                  Many thanks again.

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

                    "double" is not a function, with this keyword you define variable with "double" datatype.
                    "double variable1=0;" means "Create numeric variable named variable1 and assign value 0 to it"

                    In this examlpe: http://fxdreema.com/shared/Whla30wSd you are using CurrentGV as GlobalVariable name, so it should be string (text), not double (numeric)

                    Yes, if CurrentGV is a string (text) variable, it's ok to be

                    GlobalVariableCheck(CurrentGV)
                    

                    All the examples below does the same thing:

                    
                    GlobalVariableCheck("CurrentGV");
                    
                    
                    
                    string CurrentGV="CurrentGV";
                    GlobalVariableCheck(CurrentGV);
                    
                    
                    
                    string SomethingElse="CurrentGV";
                    GlobalVariableCheck(SomethingElse);
                    
                    

                    By the way here in this forum there are two buttons named MQL4 and MQL5. They produce better view of the source code 🙂

                    1 Reply Last reply Reply Quote 0
                    • J
                      james last edited by

                      I'm really sorry about this. I'm struggling to make sense of why I'm constantly getting... __the name parameter for GlobalVariableCheck function must be a string[/quote:2dcyqbhv] ...in MT4.

                      I've updated "GV_update_tests_2" EA and shared it again at http://fxdreema.com/shared/GTa0bFCXb.

                      In my "if CurrentGV=PreviousGV" block, I'm trying to create a filter, but am failing dismally! 😞

                      To my uneducated eye it looks like I've done everything correctly, but clearly not! I've saved my variables as type=numeric, so there shouldn't be a problem there.

                      So in my filter I'm trying to say... __If CurrentGV=PreviousGV, process the next block[/quote:2dcyqbhv] ...which is simply a comment block. But it isn't working, and I really can't work out why! If I take out my filter, it all works fine.

                      I'm so sorry. Thank you so much for your help and support. I really like fxdreema, and the level of support you give it is terrific!

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

                        I'm trying to understand what you are trying to do with these Global Variables 🙂

                        "/profiles/gvariables.dat" - this is the file where Global Variables are stored. And again, they should be used to exchange information between EA's on the same platform, or maybe to keep some parameters while some EA is down - but in this case the EA can create it's own file with information.

                        This is the function to get the value from some GV:

                        double GlobalVariableGet(string name)
                        

                        The only attribute of the function is the name of the GV - it must be text, string. What the function returns is the value of that GV, and the value is always numeric, double.

                        In your example you have two EA variables with initial value of 1, which is later modified, and that's ok. But you are also trying to use those numeric EA variables as names of GV. Non-sence.

                        What do you want to acheive?

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

                          http://fxdreema.com/shared/iv2hjNL9c

                          Open MT4, hit F3, create two GV's with their default names (gvar1 and gvar2), put some values on them and you will see those values as a Comment on the chart.

                          But in this EA there is no really need to use EA variables to hold the names of the GV's, if those names can be used directly inside the blocks.

                          1 Reply Last reply Reply Quote 0
                          • J
                            james last edited by

                            Thank you again for your quick reply.

                            I think I'm correct in saying there are 2 types of global variable:

                            • Global variable of Client Terminal
                            • Global variable of EA

                            At present I don't need to use the "Global variable of Client Terminal" type of variable. I only need the variable to be visible to the whole of the EA, what I believe is a "Global variable of EA" type of variable. However, I don't mind placing the variable in the Client Terminal, if that's what's needed to achieve my ends.

                            So, in my "GV_update_tests_2" EA shared at http://fxdreema.com/shared/GTa0bFCXb, I have:

                            • declared 2 variables, CurrentGV and PreviousGV
                            • run 3 formulae, at the end of which
                              --- the value of CurrentGV is loaded into PreviousGV
                              --- and CurrentGV is loaded with a new value based on the 3 formulae, and calculated MathAbs(Result1+Result2+Result3)

                            Then, if the values in CurrentGV and PreviousGV are equal, these are displayed on the chart.

                            As far as I can see, I have to calculate the formula CurrentGV=MathAbs(Result1+Result2+Result3) in a Custom MQL4 code block, which I've called "PreviousGV=CurrentGV & Display". I don't see how to do this in a Formula block.

                            I'm realising that the problem is my erroneous use of the "Global Variables in MT4" operand in my block called "if CurrentGV=PreviousGV".

                            What I'd like to do with this block is simply do a true/false. So if true, then process the comment block and show the results on the chart; if false, ignore on this tick.

                            I'm coming round to the realisation that the correct operand to use in my block called "if CurrentGV=PreviousGV" would probably be Formula Results. However, because my formula is created in a Custom MQL4 code block, the results of its formula don't appear in the drop-down list beside the Formula Results operand.

                            It seems that to make this work I either have to be able to pick up the results from the Custom code block in the formula drop down list, or have the "if CurrentGV=PreviousGV" block check two variables.

                            I'm sure there will be a work-around, but I just can't see it! Sorry - again! 😞

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

                              "if CurrentGV=PreviousGV" - to be true, you have to compare both EA variables, but not using GV. On both sides choose "Value (numeric)" instead of "Global variables in MT4" and load those variables or write their names inside the input fields.

                              1 Reply Last reply Reply Quote 0
                              • J
                                james last edited by

                                Oh my goodness! I feel really dumb! I don't know how I could have missed this important piece of information. I'm sure it must be in your documentation somewhere. I'm so sorry! 😳

                                But thank you again for being patient with me, and helping me get fxDreema to work. 😄

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

                                  @haidang8055 Do you need a standard variable for internal EA calculations or do you really need that Terminal variable to communicate to another device?

                                  (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.

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

                                    @l-andorrà I need to change value in global variables. Fxdreema help said that I can see and change value when using terminal variables but when I press F3 change value then close, I press f3 to open again the changed value have been gone,

                                    1 Reply Last reply Reply Quote 0
                                    • H
                                      haidang8055 last edited by

                                      @l-andorrà said in GlobalVariableSet - how to?:

                                      Terminal variable to communicate to another device
                                      i think i need this

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

                                        @haidang8055 I'm afraid this is not my field of expertise, sorry. Maybe miro or any real programmer could help with that.

                                        (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
                                        • 1 / 1
                                        • First post
                                          Last post

                                        Online Users

                                        P
                                        R
                                        A
                                        D
                                        A

                                        23
                                        Online

                                        146.7k
                                        Users

                                        22.4k
                                        Topics

                                        122.6k
                                        Posts

                                        Powered by NodeBB Forums | Contributors