fxDreema

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

    How to define constants without making them extern?

    Questions & Answers
    3
    5
    1809
    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.
    • M
      MetaTrader last edited by

      In mql4 i can write
      const double foo = 42;

      How can I do that in fxdreema?
      Using Constants makes them "extern"

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

        mt... im use the app version vs the web based one.. but on the main window-- in the upper right hand corner is a "constants input" tab... Would that work?

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

          I prefer the desktop variant over the online variant as well.

          Thess constants created in the constants tab arent really constants more that are extern's

          there are two ways to define constants in mql4

          const double foo = 13.8;
          extern double bar = 42.7;

          both create a not changeable constant but the second one could be modified by EA settings in the compiled version in Terminal

          I use often constants as for eg array indizes or for writing better readable code like mql4 do itself with al enumerations and constants like OP_SELL OP_BUY among others

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

            No, real constants can't be added.

            Remember that this tool is meant to be used from people that don't even know what constants and variables are, so from the very beginning I was using these terms to describe some fxDreema elements that may have different names in MQL4/MQL5.

            extern parameters should not be modified and in MQL5 I think such attempt will result in an error, so externs are constants in some way. I use few real constants in the code, but you are maybe the first one to ask why these are missing from fxDreema 🙂

            There is small problem with the real constnts - there are many predefined constants with various names already in MQL4/MQL5. What if someone decides to make a constant OP_SELL... he will not be able to do that. I think that the real constants are too geeky.

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

              I wrote a small custom function for a common problem:
              Often you want to know if a variable is changed since last tick or so.
              Usually you start tricking around with myVal and myOldVal or something crappy. If it comes to a handful values you want to compare this way becomes ugly.
              We need a short time memory and so I wrote this:

              
              bool isChanged(int index, double value)
              {
                  static double memory[];
                  if ((index +1) > ArraySize(memory)){
                    ArrayResize(memory, (index+1));
                    memory[index] = EMPTY_VALUE;
                 }
                 
                 if (memory[index] != value){
                    memory[index] = value;
                    return (true);
                 }
                 return (false);
              }
              
              

              now you can use it like ```
              isChanged(MY_INDEX, myJumpingValue)

              
              it automagically stores and compares the value and returns true if the value is changed.
              And I use constants for the indices because mql4 has no associative arrays like php -> you can not use a string as index. 
              
              To know if one of the values changed i can do something like this:
              
              

              const CHANNEL_HIGH = 0;
              const CHANNEL_LOW = 1;
              const TRIGGER_HIGH = 2;
              const TRIGGER_LOW = 3;

              double hi, lo, thi, tlo;

              // some code / blocks for setting the variables

              if (isChanged(CHANNEL_HIGH, hi) || isChanged(CHANNEL_LOW, lo) || isChanged(TRIGGER_HIGH, thi) || isChanged(TRIGGER_LOW, tlo){
              do_some_magic();
              }

              
              of course you can use the same in dreema's condition block.
              
              leftValue Boolean true und in  the adjust 
              
              

              && isChanged(CHANNEL_HIGH, hi) || isChanged(CHANNEL_LOW, lo) || isChanged(TRIGGER_HIGH, thi) || isChanged(TRIGGER_LOW, tlo

              
              Thats why I asked for the constants ;) But I understand your reasons and I will switch extern to const in my code before I compile the production version.
              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post

              Online Users

              K
              A
              D
              S
              G

              17
              Online

              146.7k
              Users

              22.4k
              Topics

              122.6k
              Posts

              Powered by NodeBB Forums | Contributors