ExpertRemove() ...... or maybe it doesn't!!

Post Reply
Bruster400
Trader
Posts: 192
Joined: Tue Sep 24, 2013 3:19 pm

ExpertRemove() ...... or maybe it doesn't!!

Post by Bruster400 »

Hi,

In my manual trading, I like to make things as easy as possible so I've coded a number of scripts to help me place trades and adjust stops etc. However, I've recently coded a couple of very simple EA's to wait for the right time to enter and then place the trade before removing themselves much like a script would. An example of the code from one that opens a trade on the next Heiken Ashi change for example would be:

Code: Select all

if(HATrend ==-1 && HATrend1 ==1)
           {
           Print("HA_Open: Opening Trade at the switch to a bullish HA trend");
           PlaceBuyTrade();
           } 
and then in the PlaceBuyTrade() function I have the following:

Code: Select all

 // wrap up and remove
         if(gBuyTicket!=0)
           {
           Print("HA_Open: Buy Trade Placed. Expert Removing");
           Comment("");
           ExpertRemove();
           }
which gives the following Expert's tab entries:
2018-02-15_0858.png
So in theory this is all good. When I see that conditions are right to enter the market, I can load the EA and it will enter on the next change in HA trend. EXCEPT!!! the ea that placed this trade was not loaded onto the chart!! - or any other chart! And yes, I've checked and double-checked.

It seems that ExpertRemove(); has not done a full job of removing it. If I look at the chart there is no evidence of the EA in the top right hand corner and there is no Expert Properties in a right click context menu. However, if I open up the profile file and read the entry for that chart, the EA is shown as loaded!
2018-02-15_0905.png
Does anyone else have any experience of using ExpertRemove and is there something else I should be doing? I did have my computer crash yesterday (which means the profile wasn't saved on exit) which might explain it but I'd assumed that if the EA was in the chart's profile then it should show on the chart?

I've manually deleted it from the profile which has stopped the issue but I thought I'd flag it in case anyone else is using helper EA's or has seen this issue before.

Bruster
You do not have the required permissions to view the files attached to this post.
User avatar
renexxxx
Trader
Posts: 860
Joined: Sat Dec 31, 2011 3:48 am

ExpertRemove() ...... or maybe it doesn't!!

Post by renexxxx »

Bruster400 » Thu Feb 15, 2018 7:11 pm wrote: It seems that ExpertRemove(); has not done a full job of removing it. If I look at the chart there is no evidence of the EA in the top right hand corner and there is no Expert Properties in a right click context menu. However, if I open up the profile file and read the entry for that chart, the EA is shown as loaded!
Have you considered sleeping a little bit? The trade has just been sent, you got a ticket number, but it might still be waiting for an acknowledgment from the server. Have you tried this:

Code: Select all

 // wrap up and remove
         if(gBuyTicket!=0)
           {
           Print("HA_Open: Buy Trade Placed. Expert Removing");
           Comment("");
           while( !OrderSelect(gBuyTicket, SELECT_BY_TICKET) ) {
              Sleep(100);
           }
           ExpertRemove();
           }
Just an idea.
Bruster400
Trader
Posts: 192
Joined: Tue Sep 24, 2013 3:19 pm

ExpertRemove() ...... or maybe it doesn't!!

Post by Bruster400 »

Thanks Rene, I'll give that a go of course but it doesn't seem to be placing a trade that it has an issue with and I don't do anything with the trade after it is placed. I actually have a "sleep" in after the trade is placed but didn't post that code (sorry).

Code: Select all

// Place the trade:
         gBuyTicket=Trade.OpenMarketOrderWithTPAndSLPrices(_Symbol,OP_BUY,lotSize,SL,TP,"HA Buy Order:"+":"+IntegerToString(MagicNumber),0);
         
         while(IsTradeContextBusy()) Sleep(100);
         
         // wrap up and remove
         if(gBuyTicket!=0)
           {
           Print("HA_Open: Buy Trade Placed. Expert Removing");
           Comment("");
           ExpertRemove();
           }
The scary thing is that an EA can be executing in the background without showing as loaded on the screen.

I'm going to check the profile files for each chart that I use it on over the next couple of days to see if the EA is fully removed at the time or whether it needs the profile to be saved to complete it. I feel that it has something to do with my computer crash yesterday but it didn't happen while I was using the EA so that may be a dead end too.
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

ExpertRemove() ...... or maybe it doesn't!!

Post by SteveHopwood »

The documentation led me to believe that ExpertRemove() will not work until the EA has completed its thread, whatever that means. The practical effect is that the call does not always succeed.

I declare bool RemoveExpert=false; in the general declarations space, then place this construct at the top of OnTick()/Timer() :

Code: Select all

   if (RemoveExpert)
   {
      ExpertRemove();
      return;
   }//if (RemoveExpert)
I set RemoveExpert to 'true' at the appropriate place in the code and exit the function. The EA spots the removal code at the next tick/timer event and deletes itself. the 'return' statement tells it that the current thread is complete.

I think. :youknow: It seems to work.

:xm:
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. pianodoodler@hotmail.com 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.
Bruster400
Trader
Posts: 192
Joined: Tue Sep 24, 2013 3:19 pm

ExpertRemove() ...... or maybe it doesn't!!

Post by Bruster400 »

Thanks Steve,

I'll build that in and see if it helps. The return might be the issue but I'm surprised that the EA needs to complete after it's been removed.... still, this is Empty4 we're dealing with here.....

Bruster
Bruster400
Trader
Posts: 192
Joined: Tue Sep 24, 2013 3:19 pm

ExpertRemove() ...... or maybe it doesn't!!

Post by Bruster400 »

Just to close off this topic, I've found the issue so thought I'd share. The problem was caused by my computer crashing. It didn't crash whilst the EA was exiting or anything like that it's actually that the profile does not get updated until you manually close Empty4. Until then, even though the EA has exited from your chart, the chart details in the profile do not reflect this until you close Empty4. If your PC crashes, when you re-open Empty4 the EA will still be functioning on the chart even though it will not be showing any signs of being loaded.

I've tested this with both the ExpertRemove function in an EA and actually manually removing the EA - the effect is the same - the EA is not fully removed until a manual shut down of the platform - or loading another EA to that chart.

Worth knowing.
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

ExpertRemove() ...... or maybe it doesn't!!

Post by SteveHopwood »

That is indeed useful to know. Remove an EA from the chart and follow that up by shutting down and restarting the platform.

Or, to be really sure the EA is removed:
  • Remove the EA.
  • Close the chart.
  • Shut down the platform.
  • Shut down the computer.
  • Switch off the electric power to the entire house for a few minutes.
  • Ritually sacrifice a chicken.
  • Restart the power.
  • Restart the computer.
  • Restart the platform.
There is then a dim chance that the damn EA might not be running secretly in the background. :xm: :xm: :xm:

:lol:
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. pianodoodler@hotmail.com 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
tomele
Administrator
Posts: 1208
Joined: Tue May 17, 2016 3:40 pm
Location: Germany, Forest of Odes, Defending the Limes

ExpertRemove() ...... or maybe it doesn't!!

Post by tomele »

Bruster400 » 06 Mar 2018, 10:44 wrote:... the EA is not fully removed until a manual shut down of the platform - or loading another EA to that chart.
That leads to an idea. We could have an EA that does nothing than immediately removing itself. We could use that one to kill any EA probably running in the background.
Happy pippin, Thomas :-BD

It ain't what you don't know that gets you into trouble.
It's what you know for sure that just ain't so.
(Mark Twain)

Keep the coder going: Donate
fx805
Posts: 5
Joined: Sun Dec 29, 2013 4:37 am

ExpertRemove() ...... or maybe it doesn't!!

Post by fx805 »

I was thinking the same thing as tomele... Could we remove have a functioin that calls the ExpertRemove() funtion ---then next in the function have it call and open another "dummy" ea .. This new dummy EA does nothing other then over write the first EA (essentially removing it from the profile and placing the new "dummy' ea on the chart... Since the new dummy ea does nothing-- though its there-- you cant get into trouble with mystery trades being placed by the Orginal EA you didnt know was still lurking in the background..

We might not be able to call a EA but would the act of calling an indicator or script (even to just write "your safe no EAs active") on the screen... Would that be enough to overwrite the removed EA from the profile?
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

ExpertRemove() ...... or maybe it doesn't!!

Post by SteveHopwood »

It is not a complicated business. You can always just close down the chart, then the platform.

Empty4 is such utter, total bollocks that you should close and restart the platform every time you set up anything that remotely appears clever, complicated, or above the understanding of a newt before the damn thing receives the next tick. Platform I mean, not newt. No idea whether newts receive ticks or not. I hope they enjoy the experience, if they do.

If instead you absolutely insist on refusing to recognise the Total Bollockhood of Empty4 and do not carry out the steps I outlined above, you can always try the attached EA. It took about 30 seconds to code it in response to an earlier post, and because I was bored. It took about 30 seconds more to forget about it because I am not an idiot (my assertion only and open to debate) and have a fair few ideas about how to combat the Cretins at Crapperquotes.

The latest post here reminded me about it and so I post it here for your delectation and await your gales of warm applause for such a technically advanced piece of hitherto unbelievably-concepted piece of kit. Rene is currently gasping in amazement at it and wondering, "Now why did I never think of that?"

My expertise knows no bounds.

In case any of you are daft/inexperienced enough to still be wondering: yes, I have imbibed tonight. There could be more nonsense to come.

:xm: :rocket:
You do not have the required permissions to view the files attached to this post.
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. pianodoodler@hotmail.com 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.
Post Reply

Return to “Coders Hangout”