fxDreema

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

    count consecutive stop loss

    Questions & Answers
    4
    7
    2853
    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.
    • A
      alexdepa last edited by

      Hi, I need to count consecutive stop loss in a row to determine the next lot size. The problem is that with "check consecutive loss" it checks all the losses not only those trades closed at stop loss. I tried with "for each closed trade" and a counter storing the result in a variable...but if I restart the MT4 the varible resets so...nothing.
      I can't achieve this in any way. If it's possible with fxdreema can someone post an example please?

      Thanks!

      1 Reply Last reply Reply Quote 0
      • R
        Radar last edited by

        Hey Alexdepa,

        If you want your EA to remember state information (e.g number of consecutive trades that closed at a loss), you will have to either save that information to a file and read it back as required (and on restarts of mt4), or save it to Global Variables of the terminal (and read it back).

        I have no idea how to do either within fxDreema, as I started playing with it about 4 hours ago 😉

        Not much help, I know, but it might point you in the right direction.

        Have fun!
        Radar =8^)

        edit... I had a quick look, and found "Write To File" in the "Communication" group, but couldn't find a "Read From File" option.

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

          First look at the available Money management methods, maybe some will fit your needs: https://fxdreema.com/help/-/working%20w ... management

          The block "Check consecutive losses" counts how many loss trades there were in a row, but it doesn't calculate the total amount of losses in money or pips. If you want to calculate certain value in a group of trades, you can try the "Bucket" blocks. "For each..." (pink) blocks also can be used, but I made those "Bucket" blocks to be used when people work with multiple trades and want to extract certain value out of them.

          1 Reply Last reply Reply Quote 0
          • A
            alexdepa last edited by

            No, I'd want to count consecutive stop loss (so when the price hit the stop loss level), not simple losses, but I need that this "counting" remain after a MT4 restart. Is it possible?

            Thanks!

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

              possible is:

              • count it from history orders
              • if count from history is not enough, you can save into file (but yet is not in fxdreema readfile block - hard to make it universal for all, maybe only for variables, but you know, how many people use it?) -- you can always make own block to do this job - read your file, or with custom code block ...

              but normally, your variable after MT4 restart is lost

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

              1 Reply Last reply Reply Quote 0
              • R
                Radar last edited by

                Hey Alexdepa,

                I still can't do this in fxDreema, but I can give you some snippets of code that will do the job...

                I'll assume that you're using a global scope variable named "ConsecutiveSLCount" for this... Replace it with the name that you actually use...

                In init...

                   if (GlobalVariableCheck(StringConcatenate(<EAName> + "_" + Symbol() + "_" + string(Period()) + "_ConsecutiveSL_"  + string(<MagicNumber>))))
                   {
                      ConsecutiveSLCount = GlobalVariableGet(StringConcatenate(<EAName> + "_" + Symbol() + "_" + string(Period()) + "_ConsecutiveSL_" + string(<MagicNumber>)));
                   } // End if (GlobalVariableCheck(StringConcatenate(<EAName> + "_" + Symbol() + "_" + string(Period()) + "_ConsecutiveSL_" + string(MagicNumber))))
                   else ConsecutiveSLCount = 0;
                
                

                Obviously, replace <EAName> with the name of the EA, and <MagicNumber> with the name of the constant that holds the Magic Number 😉

                Now, just after the point where you update the counter, paste this bit of code...

                   if (ConsecutiveSLCount >= 1)
                   {
                      GlobalVariableSet(StringConcatenate(<EAName> + "_" + Symbol() + "_" + string(Period()) + "_ConsecutiveSL_" + string(<MagicNumber>)), ConsecutiveSLCount);
                   } // End if (ConsecutiveSLCount >= 1)
                   else
                   {
                      if (GlobalVariableCheck(StringConcatenate(<EAName> + "_" + Symbol() + "_" + string(Period()) + "_ConsecutiveSL_" + string(<MagicNumber>))))
                      {
                         GlobalVariableDel(StringConcatenate(<EAName> + "_" + Symbol() + "_" + string(Period()) + "_ConsecutiveSL_" + string(<MagicNumber>)));
                      } // End if (GlobalVariableCheck(StringConcatenate(<EAName> + "_" + Symbol() + "_" + string(Period()) + "_ConsecutiveSL_" + string(<MagicNumber>))))
                   } // End else
                

                Again, replace what needs to be replaced.

                Now, as the EA runs and consecutive SL's are counted and the global-scope variable is updated, the GlobalVariable of the terminal is also updated...
                You can shut down the terminal at the end of the week, and when you re-start next week, the code in init will read the GlobalVariable of the terminal, and update the global-scope variable with its contents.

                Have fun!
                Radar =8^)

                edit... I forgot to say that the EA name must be in double quotes.

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

                  I still don't understand what needs to be counted. But each trade exists in the database of MT4 even after restarting the PC, so you can always loop through the history trades (or the running trades) and get different values out of them. Of course, most blocks in fxDreema are set up in a way to work with particular Magic Number and with the current Symbol (Market), so if you need to work with all available trades, then some small changes are needed in the blocks (their Filter settings).

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

                  Online Users

                  D
                  A
                  M
                  K
                  M
                  B

                  17
                  Online

                  146.7k
                  Users

                  22.4k
                  Topics

                  122.6k
                  Posts

                  Powered by NodeBB Forums | Contributors