My shell EA code

Post Reply
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.

My shell EA code

Post by SteveHopwood »

This dimwit was stupid enough to pm me with the same questions. He is now a member of the group that can do bugger all here except read posts.

: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.
User avatar
Baluda
Trader
Posts: 330
Joined: Mon Feb 06, 2012 2:00 pm
Location: An insignificant village in the Netherlands

My shell EA code

Post by Baluda »

Minor improvement suggestion in DisplayUserFeedback().

I have changed this:

Code: Select all

//Code for time to bar-end display from Candle Time by Nick Bilak
double i;
int m, s;
m=iTime(Symbol(), TradingTF, 0) + TradingTF*60-CurTime();
i=m/60.0;
s=m%60;
m=(m-m%60)/60;
SM(m + " minutes " + s + " seconds left to bar end" + NL);
into this:

Code: Select all

SM( TimeToString( iTime(Symbol(), TradingTimeFrame, 0) + TradingTtimeFrame * 60 - CurTime(), TIME_MINUTES|TIME_SECONDS ) + " left to bar end" + NL );
Take care,

Paul
Check the MQL4 Market for my best EA's and Indicators.
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.

My shell EA code

Post by SteveHopwood »

Nice one Paul. Thanks. :clap:

: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.
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.

My shell EA code

Post by SteveHopwood »

I used Bare Bones to code an ea for a member who required a trailing stop feature and found the ts does not work. There is a vital line of code that I somehow managed to delete at some stage. The fixes are in post 1 (Bare Bones and Bob Stuff) but it is easier to make the changes yourselves.

Go to void TrailingStopLoss() and add
if (CloseEnough(sl, 0) ) sl = OrderStopLoss();
under the sl declaration at line 3 of the function.

All the other stop loss functions have this line, so no idea what I was thinking when I removed it from the ts function.

: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.
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.

My shell EA code

Post by SteveHopwood »

It looks as though the factor calculation for xau/gold is out by a factor of 10 and should be 100 not 10. I discovered this whilst coding the data-gathering for Big Mac Gold (coming soon to a spot near here) and it displayed the Renko bar size as 5 rather than 50.

: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

My shell EA code

Post by Bruster400 »

Steve et al,

Firstly, thanks for sharing these shells. As a newbie to MQL4 they are not only an easy way in but also a great teaching tool to see how it should be done!

However, I have one question - how hard is it to make these shells (Barebones particularly) trade multiple trades simultaneously on the same symbol? I've had some success using only hard sl and tp but when things like Breakeven and Trailing stop are involved, the use of TicketNo , OrderTicket() and ticket don't line up to keep track of the open trades. I've tried to follow the code through but it looks like ticket is overwritten with each new trade so there is no "history". I guess it needs an array to hold the ticket numbers and an increment of some sort but beyond that I'm getting lost.

So actually my real question is - does anyone have a multi-trade version of this shell that they could share - or even point me to an existing multi-trade ea (with BE and trailing) that's already coded that I could strip back to a shell myself?

Thanks once again.

Bruce
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.

My shell EA code

Post by SteveHopwood »

Bruster400 » Thu Oct 15, 2015 9:45 am wrote:Steve et al,

Firstly, thanks for sharing these shells. As a newbie to MQL4 they are not only an easy way in but also a great teaching tool to see how it should be done!

However, I have one question - how hard is it to make these shells (Barebones particularly) trade multiple trades simultaneously on the same symbol? I've had some success using only hard sl and tp but when things like Breakeven and Trailing stop are involved, the use of TicketNo , OrderTicket() and ticket don't line up to keep track of the open trades. I've tried to follow the code through but it looks like ticket is overwritten with each new trade so there is no "history". I guess it needs an array to hold the ticket numbers and an increment of some sort but beyond that I'm getting lost.

So actually my real question is - does anyone have a multi-trade version of this shell that they could share - or even point me to an existing multi-trade ea (with BE and trailing) that's already coded that I could strip back to a shell myself?

Thanks once again.

Bruce
These shells are intended primarily for single trade use, but I adapt them for multi-trade use all the time. The ticket variable is pretty much irrelevant in a multi-trade EA. All you have to do is ensure that LookForTradingOpportunities() is called when there is already a trade open.

Declare a variable somewhere - usually as an extern - such as MaxOpenTradesAllowed. Go to the end of OnTick() and change

Code: Select all

if (TicketNo == -1)
to

Code: Select all

if (OpenTrades < MaxOpenTradesAllowed)
.

All the management features are called in CountOpenTrades() as the ea iterates through each trade, so the relevant trade is already selected when functions such as JumpingStopLoss() are called. I suppose the functions should be called with the order ticket number i.e.

Code: Select all

      //Profitable trade management
      if (OrderProfit() > 0) 
      {
         TradeManagementModule();
      }//if (OrderProfit() > 0) 
 
should be

Code: Select all

      //Profitable trade management
      if (OrderProfit() > 0) 
      {
         TradeManagementModule(OrderTicket());
      }//if (OrderProfit() > 0) 
 
then the management module and all the functions it calls should have (int ticket) as a parameter and the function should check that the order is still open i.e.
if (!OrderSelect(ticket) ) return;

as an extra layer of security, but the code works ok as it is.

Don't forget to save the OrderTicket() in a temporary variable if one of your called functions in its turn iterates through the orders list, so you can re-select it i.e.
int TempTicket = OrderTicket();
<call the function that iterates through the order list>
if (!OrderSelect(TempTicket) ) continue;

: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

My shell EA code

Post by Bruster400 »

Steve, Thank you for your fast response and very comprehensive answer. It's a great help, much appreciated.
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.

My shell EA code

Post by SteveHopwood »

I have uploaded updated versions of Bugger All, Bare Bones and Bob Stuff to post 1.

I have:
  • added the new input MaxTradesAllowed and edited the code snippet at the end of the code to make it easier to write multi-trade ea's.
  • adopted that nifty way of presenting users with a choice of time frames that I described in the Goosey thread.
  • added code to CloseAllTrades() so the function will delete pending trades as well. It does two passes, closing the market trades on the first pass to get them closed as quickly as possible.
  • added the extra security I described to Bruster a couple of posts ago. Any bloops introduced by this will show themselves with use.
: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

My shell EA code

Post by Bruster400 »

That's great Steve, thanks! I'd made the changes you described before in BareBones and it seems to be working ok. I'll drop my trade logic into the new shell and see how I get on. I will of course share if I come up with anything that is profitable! :?

Thanks

Bruce
Post Reply

Return to “Coders Hangout”