count consecutive stop loss
-
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!
-
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.
-
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.
-
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!
-
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
-
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 elseAgain, 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.
-
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).