stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

My shell EA code
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=79
Page 17 of 23
Author:  SteveHopwood [ Thu Jul 09, 2015 6:19 pm ]
Post subject:  My shell EA code

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:
Author:  Baluda [ Tue Jul 14, 2015 2:39 pm ]
Post subject:  My shell EA code

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
Author:  SteveHopwood [ Tue Jul 14, 2015 3:22 pm ]
Post subject:  My shell EA code

Nice one Paul. Thanks. :clap:

:xm:
Author:  SteveHopwood [ Wed Jul 22, 2015 11:16 am ]
Post subject:  My shell EA code

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:
Author:  SteveHopwood [ Sat Jul 25, 2015 6:09 pm ]
Post subject:  My shell EA code

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:
Author:  Bruster400 [ Thu Oct 15, 2015 9:45 am ]
Post subject:  My shell EA code

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
Author:  SteveHopwood [ Thu Oct 15, 2015 5:36 pm ]
Post subject:  My shell EA code

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:
Author:  Bruster400 [ Fri Oct 16, 2015 7:01 am ]
Post subject:  My shell EA code

Steve, Thank you for your fast response and very comprehensive answer. It's a great help, much appreciated.
Author:  SteveHopwood [ Sun Oct 18, 2015 1:38 pm ]
Post subject:  My shell EA code

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:
Author:  Bruster400 [ Sun Oct 18, 2015 3:09 pm ]
Post subject:  My shell EA code

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
All times are UTC Page 17 of 23