stop EA from trading after one loss

 
Hi, I love MT4!

Here's my question: I have searched without success on Google and at MQL4.com for a code snippet that will stop EA from trading after a losing trade. I want this as a safety switch in live forward testing to prevent EA from a runaway losing streak before I can shut it off to analyze performance. I found http://www.forexfactory.com/showthread.php?t=93595 , https://www.mql5.com/en/forum/137546 and https://www.mql5.com/en/forum/101505, but they aren't really a cut and paste solution. I want a code snippet I can input to Molanis MQL Block in Strategy Builder. I can code without SB, but I like to use it to speed up my development. If I discover a solution before I receive an answer, I will post it here for everybody.

What I'm looking for is an "OFF" switch for Hal 9000, before he blows up my account. It could be a variable number of losses to make it useful to more coders, but I only need it to trigger after (1) loss.

Thanks, Chika : )
 

You have already provided the codes within the first link I looked at. If you're really a programmer than that should have already worked for you with very little modifications. Here's how I would do it.

- I would create a Extern Variable for the #-of-last-trades-to-look-at.

- I would create a function which returns the #-of-losing-trades among those.

- I would sort the history pool by OrderOpenTime || OrderCloseTime to ensure I'm looking at recent trades.

- Within the start(), I would ask if( #-of-losing-trades() >=  #-of-last-trades-to-look-at){ return; }

Now if I could write the code snippet faster than the above I would have provided that instead. But really, this is not the forum for copy-paste codes, we help people code for themselves.  

 
ohoh7:
Hi, I love MT4!

Here's my question: I have searched without success on Google and at MQL4.com for a code snippet that will stop EA from trading after a losing trade. I want this as a safety switch in live forward testing to prevent EA from a runaway losing streak before I can shut it off to analyze performance. I found http://www.forexfactory.com/showthread.php?t=93595 , https://www.mql5.com/en/forum/137546 and https://www.mql5.com/en/forum/101505, but they aren't really a cut and paste solution. I want a code snippet I can input to Molanis MQL Block in Strategy Builder.
If you want to create something using Molanis why aren't you asking in the Molanis forum ?  if you want to code then learn to code. 
 
RaptorUK:
If you want to create something using Molanis why aren't you asking in the Molanis forum ?  if you want to code then learn to code. 


10 print "Raptor, here's a pointed answer for you: I have asked in the Molanis forum. And I instantly received a polite, constructive reply."

20 goto 10 

 

Ubzen: thank you for your wise, helpful words. I will use your framework in my logic. 

 

Chika : ) 

 
ohoh7:  but they aren't really a cut and paste solution. I want ...
Since there are no slaves here, you have only three choices: Search for it, learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt and the nature of your problem.
 
ohoh7:


10 print "Raptor, here's a pointed answer for you: I have asked in the Molanis forum. And I instantly received a polite, constructive reply."

Constructive ?  

 

"We do not have that available but you may want to look at the martingale code that says if the last position is a win/lose. Maybe use it as a base to get what you want.

Look in the code for //Martingale lot calculation." 

 

I think . . .  " if you want to code then learn to code. "   is way more constructive.

 
RaptorUK:

Constructive ?  

 

"We do not have that available but you may want to look at the martingale code that says if the last position is a win/lose. Maybe use it as a base to get what you want.

Look in the code for //Martingale lot calculation." 

 

I think . . .  " if you want to code then learn to code. "   is way more constructive.


Actually, it gave me the clue to create the code. Now, I can charge you for it. Goto 10. END
 
ohoh7:

Actually, it gave me the clue to create the code. Now, I can charge you for it. Goto 10. END
So you are learning a little code,  glad you took my advice,  well done  :-)
Reason: