My shell EA code

Post Reply
K-Lander
Trader
Posts: 35
Joined: Thu Nov 17, 2011 9:03 pm
Location: Buenos Aires, Argentina

My shell EA code

Post by K-Lander »

Hi Steve,
Attached I am sending Bare Bones with a working ForceSleepUntilNextBar feature.

A friendly reminder to anyone using the shells: Remember to DELETE the failsafe on the code (you´ll find it within the LookForTradingOpportunities function). Nothing will ever trigger a trade unless you do it (I forgot about it and took me 2 hours to figure out why the bugger doesn´t fire).

Thanks for the help Steve, and for the coding lesson.

All the best, and stay safe in these strange times.

Ariel

The subconscious is an amazing thingy and mine was at work as I typed the above. It just told me that I had given you duff info about the call to the function as well. Think about this call:

Code: Select all

if (ForceSleepUntilNextBar && DidTradeCloseBeforeCurrentCandle()) return (true);
   else
   return (false);  
This will also return 'false' if you have ForceSleepUntilNextBar set to 'false' to disable this filter, so the bot will never Trade. My fault. Here is the corrected code:

Code: Select all

   if (ForceSleepUntilNextBar)
   {
      if (DidTradeCloseBeforeCurrentCandle() ) return (true);
      else
      return (false);
   }//if (ForceSleepUntilNextBar)
:xm: :rocket:
You do not have the required permissions to view the files attached to this post.
User avatar
simplex
Trader
Posts: 124
Joined: Thu Feb 07, 2013 5:21 pm
Location: An insignificant village close to an insignificant former capital at the Rhine River.

Re: My shell EA code

Post by simplex »

Hi all,
I'm just working my way through this formidable piece of software. Stumbled over the object handling functionality:

Code: Select all

if (ObjectFind(LineName) == -1) {
	ObjectCreate(LineName, OBJ_HLINE, 0, TimeCurrent(), 0);
	...
}
https://docs.mql4.com/objects/objectfind states:
If the object is not found, the function returns a negative number.
So that return value is not -1 necessarily.
Maybe it's worth considering to replace

Code: Select all

ObjectFind(LineName) == -1
by

Code: Select all

ObjectFind(LineName) < 0
just to be sure ... as sure as one can be using mql ...
There are several similar ObjectFind calls in the source code.
If you can't explain it simply, you don't understand it well enough. (Albert Einstein)
It appears that the Weighted Moving Average was invented by a trader who did not have a firm grasp of filter theory in hopes of reducing lag. (John F. Ehlers)
User avatar
SteveHopwood
Owner
Posts: 9754
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Re: My shell EA code

Post by SteveHopwood »

simplex wrote: Sat May 13, 2023 4:49 pm Hi all,
I'm just working my way through this formidable piece of software. Stumbled over the object handling functionality:

Code: Select all

if (ObjectFind(LineName) == -1) {
	ObjectCreate(LineName, OBJ_HLINE, 0, TimeCurrent(), 0);
	...
}
https://docs.mql4.com/objects/objectfind states:
If the object is not found, the function returns a negative number.
So that return value is not -1 necessarily.
Maybe it's worth considering to replace

Code: Select all

ObjectFind(LineName) == -1
by

Code: Select all

ObjectFind(LineName) < 0
just to be sure ... as sure as one can be using mql ...
There are several similar ObjectFind calls in the source code.
Thanks for this. Brilliant point. :clap: :clap: :clap: :clap: :clap:

I am not going to do anything with this immediately as I can make the changes as I use the code. Plus, anyone such as yourself, can read your post and make the changes themselves. Anyone who cannot, cannot use the shells.

Thanks again. Hugely appreciated.

:xm: :rocket:
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. [email protected] is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
User avatar
simplex
Trader
Posts: 124
Joined: Thu Feb 07, 2013 5:21 pm
Location: An insignificant village close to an insignificant former capital at the Rhine River.

Re: My shell EA code

Post by simplex »

SteveHopwood wrote: Mon May 15, 2023 7:34 pm Plus, anyone such as yourself, can read your post and make the changes themselves. Anyone who cannot, cannot use the shells.
Agree & thanks! Now for my next find, which dives a little bit deeper in the trading logic. See function LookForTradingOpportunities():

Code: Select all

	if (BuySignal) {
		SendLong = true;
	}
	if (SendLong) {       // User choice of trade direction
		if (!TradeLong) {
			return;
		}
This is how buy trades are started. For sell trades, it looks like this:

Code: Select all

	if (!SendLong) {
		if (SellSignal) {
			SendShort = true;
		}
		if (SendShort) {
			if (!TradeShort) {      // User choice of trade direction
				return;
			}
So sell signals are only being processed if there's no buy signal present. In my opinion, long and short trades are generally equitable. By this logic, long trades are prioritized over short trades.

This may work in a perfect world. But let's assume we as coders implement some sort of faulty logic when it comes to analyse the market for entry opportunities. Allright: this is highly unlikely, but let's just assume the impossible is happening: our trading logic issues a buy and a sell signal at the same time for a given pair.

In above logic, the long trade will be placed, while the short trade is silently ignored. Do I want that? Don't know about you, but I do not. What I find alarming most of all is the fact that ignoring the short trades obviously happens silently. Maybe there are security checks later on dealing with such a situation, which I possibly am not aware of yet. Anyway, I believe it's better to deal with this case before actually placing trades.

So this is my proposal to (hopefully) improve that bit of the shell code:

Code: Select all

	// Security check: is our trading system going haywire? (simplex mod)
	if (BuySignal && SellSignal) {
		/* 
			do whatever seems appropriate to ring the alarm bells ...
			... suspend trading?
			... close / delete all trades?
			... display visible and / or audible alarm?
			... send an email to Steve for immediate help? ;-)
			... 
		 */
		return;
	}
	
	if (BuySignal) {
		SendLong = true;
	}
	if (SendLong) {
...
	if (SellSignal) {
		SendShort = true;
	}
	if (SendShort) {
...
Now long and short trades are treated in the exact same manner, and on the same indentation level in our code. Furthermore we have the opportunity to implement some code to ring the alarm bells if the unthinkable is actually happening.

I'm just working on this mod, it's not yet ready, but I'd like to discuss my proposal here, before possibly running (coding) into a completely wrong direction. Maybe this idea is worth to find its way into the shell itself, not only in my upcoming EA's. In the end, it makes the shell a bit more foolproof (which suits me perfectly!), because it deals with a faulty signal logic in a more appropriate manner as compared to just ignoring it.
If you can't explain it simply, you don't understand it well enough. (Albert Einstein)
It appears that the Weighted Moving Average was invented by a trader who did not have a firm grasp of filter theory in hopes of reducing lag. (John F. Ehlers)
Post Reply

Return to “Coders Hangout”