fxDreema

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

    Variables and Constants

    Questions & Answers
    3
    5
    3154
    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.
    • ekanters
      ekanters last edited by

      Constants show up in the EA's input screen but can't be changed. On the other hand Variables that can be changed don't show up in the EA's input screen. What am I missing here??? Below a simple bot.
      0_1489082309309_variable.jpg

      1 Reply Last reply Reply Quote 0
      • M
        miro1360 last edited by

        0_1489084981162_upload-46c0891c-7d33-4193-80c3-82c7f53a54bd

        0_1489085020639_upload-e61d9a26-cc01-4d8a-ada2-c1cf7511fb3d

        Between trading and gambling is a very small gap, be careful.

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

          Ok so what was simple in the past like going from A to B we now need to go over the whole Alphabet. But thanks I am going to work with that. At least you explained it as simples as possible. I did tell you I love you didn't I 🙂

          1 Reply Last reply Reply Quote 0
          • M
            miro1360 last edited by miro1360

            thanks 😄 ... and actually using Constants as inputs is the best way 🙂 .... because one constant (or variable if you fill it with constant as example above) you can use it in many blocks ... but when you use check box you get a lot of input parameters (one for each check block) and in tester optimization you get a lot of combinations which can cost you time 😄

            Between trading and gambling is a very small gap, be careful.

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

              It's a long story...

              In the beginning Variables were just regular global variables and Constants were "extern" global variables. Then I started thinking "Hey, what if I remove the Constants and put a checkbox to turn any Variable into "extern" parameter?". And obviously I did that. But immediately I found a small problem...

              In MQL5 you can define "extern" variable and then modify it in the code. But in MQL5. Try this MQL5 code:

              input int inp = 0;
              
              void OnInit() {
              	inp = 1;
              }
              

              It can't be compiled, it says "'inp' - constant cannot be modified"
              If I use "extern" instead of "input", then there is no compile error, but also the variable is no longer an input parameters, it's like the keyword "extern" does nothing for MQL5.
              Only in MQL4 and only if you use the keyword "extern" you can have input parameter that can then be modified into the code. But this behavior is for legacy reasons.

              So, having input parameters that can be also modified in the code was (and still is) forbidden in MQL5 and even in MQL4 (when you use "input"). That's why after I added those checkboxes for the Variables I almost immediately regretted.

              What is the situation today? In the output code of the web version of fxDreema, both Constants and Variables are not global variables. They are members of two separate classes. This means that they all can be modified. But there are some problems again. I found that for people with many many Variables, the code is compiled very slowly. I guess that having classes with too many members is not good idea. So I'm now thinking to make Constants and Variables global variables again.

              There are some technical difficulties as you can see and this determines my decisions 🙂

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

              Online Users

              G
              K
              P
              M
              M

              17
              Online

              146.7k
              Users

              22.4k
              Topics

              122.6k
              Posts

              Powered by NodeBB Forums | Contributors