HGB FIFO and Error Traps Thread

EA's inspired by nanningbob's work here, especially those based on his 240 Moving Average trend detection filter.

HGB FIFO and Error Traps Thread

Postby spgandau » Sat Mar 14, 2015 9:09 pm

SERIOUS WARNING
  • Most Forex traders lose all their money.
  • Using the robot posted here in trading Forex does not guarantee success.
  • Trading this robot could lead to serious financial loss.
  • Trading this robot without understanding its underlying trading strategies guarantees traders will lose their money.
  • This is not a set-and-forget ea; there is no such thing and anyone who tries to claim there is, is either stupid or lying. This ea requires frequent manual intervention.
  • At best, a trading robot is only 90% as good as the manual strategy it trades. At best. At worst, it can be much less effective. If the strategy is rubbish, so is the robot.
  • To trade this robot, you have to understand:
    • How to use EA's.
    • Bob's HGI indicator.

Hello fellow HGB user,

This forum is thanks to the generosity of Steve Hopwood. I hope that what I have learned and applied to the my current version of HGB bots will be useful for you!

I am a US based trader, using Empty4. I currently use Oanda for my trading platform.

I have followed nanningbob, and use HGB. I was getting many trade-related errors. Often the errors caused an intended trade to not execute, at all. I developed 4 fundamental functions that dealt with the most common server-side 'errors' that were being thrown....especially to US traders who deal with FIFO limits. Since most of the people on this site are non-US traders, I find some excellent EA's ... only to be limited by the US FIFO law. So, I have worked to create workarounds for the FIFO traders. They do NOT go around the FIFO issues, but they will close out orders in proper sequence, to avoid errors, and non-closing trades when an EA attempts to close an out-of-sequence trade order.

In the end, I re-wrote the overall "flow" of the routines. I had struggled with duplicate trades, odd behaviors of results. Rather than just add patches, I decided to document the existing program logic flow, modify it to fit my own personal logic patterns, and then resubmit it. I have NOT written lots of new code. The people on this site and various forums are excellent at sharing what they have developed. I have tried to use their work (sometimes modified to fit my US needs), and then add specific features that I could not find elsewhere. Essentially, I just re-arranged the existing sub routines, and removed subroutines that caused duplication.

My basic plan has been to use HGI and the HGB EA. I recognize that it works best with good solid trends. I wanted to get it working very well, before I ventured out and tried to adapt other EA material to a US-limited environment. I have used the core of work done by boinvest (no longer on the threads).

BASIC story:

I have re-written 4 functions to handle all ordersend, ordermodify, orderclose and orderdelete calls. These 4 functions will handle recursive attempts to deal with common 136, 137, 138, 141, errors...
I then experienced the FIFO error that US forex traders deal with. I eventually resolved that issue with CloseEarlierTrades(). I have written this code so that I if the EA is trying to close one particular trade, ALL prior trades of that symbol will be closed before the current trade will be closed, regardless of trade comment/type. This applies only to US traders. If your broker is not FIFO compliant, this feature will not affect your trading...it will allow the trades to execute as requested by the EA.

You must install the feature "hgb_lib.mqh" and "TradeContext.mqh" in the includes folder and "hgi_lib.ex4" in libraries folder before the EA will function properly

Good luck! :)

UPDATE: Jul 4, 2019. Z_trailingBuyStop.mq4 is actually for BUY / SELL trades. It is a stop entry EA that uses a 'trail' to capture a best entry point.

Cheers! :good:
You do not have the required permissions to view the files attached to this post.
spgandau
 
Posts: 50
Joined: Thu Sep 20, 2012 2:17 am

HGB FIFO and Error Traps Thread

Postby spgandau » Sat Mar 14, 2015 9:12 pm

To those using Holy Graily Bob.

I have another two modifications that may affect those who use the MA240 filter.
I have changed the code to read: (around line 2912 in HGB_v01e_strict_spgandau)

//MA
if (UseDoubleMA)
{
//Read once a minute
static datetime OldMaBarTime = 0;
if (TimeCurrent() >= NextReadTime)
//if (OldMaBarTime != iTime(Symbol(), PERIOD_M1, 0) )

{
//OldMaBarTime = iTime(Symbol(), PERIOD_M1, 0);
TradingDirection = none;
FastTrendMaVal = GetMa(Symbol(), FastMaTdTF, FastMaTdPeriod, FastMaTdShift, FastMaTdMethod, FastMaTdAppliedPrice, 0);
SlowTrendMaVal = GetMa(Symbol(), SlowMaTdTF, SlowMaTdPeriod, SlowMaTdShift, SlowMaTdMethod, SlowMaTdAppliedPrice, 0);
TradingDirection = ranging;
if((FastTrendMaVal > SlowTrendMaVal) && (Bid > FastTrendMaVal)) TradingDirection = up;
if((FastTrendMaVal < SlowTrendMaVal) && (Bid < FastTrendMaVal)) TradingDirection = down;
/*
if (Bid > FastTrendMaVal)
if (Bid > SlowTrendMaVal)
TradingDirection = up;
if (Bid < FastTrendMaVal)
if (Bid < SlowTrendMaVal)
TradingDirection = down;
*/
}//if (OldMaBarTime != iTime(Symbol(), PERIOD_M1, 0) )

}//if (UseDoubleMA)

1st change:
I have adjusted the "read" to be the same value as HGIReadDelaySeconds. Whenever the user chooses to have HGI check for signals, then a reading of this UseDoubleMA is sufficient to check trend values as well.

The 2nd change:
Normally, when the fast MA < slow MA, we call it a down trend (and vice versa).
In the prior code, if the trend was down, but price moved (or spiked up) above the slow MA, the HGB code would call for a Trading direction to be UP. However, a review of prices vs. overall trend shows that this is usually a temporary situation and the trend will return down, because the fast MA is still below the slow MA.
It would appear that this scenario would best reflect a situation that is Ranging (price might continue up or might return back down). Until the fast MA crosses up over the slow MA and becomes a up trend, the trend is something between 'down' or 'up'...it would seem to be best determined as ranging. I have adjusted my copy of HGB_ver01e_strict_spgandau and HGB_ver01i_strict_spgandau to reflect this change.

Cheers!
Scott
spgandau
 
Posts: 50
Joined: Thu Sep 20, 2012 2:17 am

HaveWeHitProfitTarget() bug

Postby spgandau » Sat Mar 14, 2015 9:12 pm

for some of us, we have had HGB deliver the following message (from line 5483 in OnTick):
Comment(" GLOBAL PROFIT TARGET REACHED");

the problem is that we KNOW that there was not enough profit taken on the particular pair for this day....and sometimes the message shows up and the EA has not taken ANY trades today! Why?

Well, I have figured out the solution:
Go to the sub routine: HaveWeHitProfitTarget()
Scroll down to the section that reads:

for (int cc = OrdersHistoryTotal() - 1; cc >= 0; cc--)
{
if (!OrderSelect(cc, SELECT_BY_POS, MODE_HISTORY) ) continue;
if (OrderMagicNumber() != MagicNumber) continue;
if (TimeDayOfWeek(OrderCloseTime()) != TimeDayOfWeek(TimeCurrent()) ) continue;

Replace the last line to read:
if (OrderCloseTime() < iTime(Symbol(),PERIOD_D1,0) ) continue; //--order was closed before current day

There is a logic 'hole' in (TimeDayOfWeek(OrderCloseTime()) != TimeDayOfWeek(TimeCurrent()) ) continue;

Each section of this line of code will produce a number for the day (ie for Monday it will produce a "2", for Tuesday, it will produce a "3", etc). When it compares each number, it will correctly sift out any closed order if the day 'number' does not equal today's 'number'.
HOWEVER, it WILL accept all closed trades that do have the same day number as today. Therefore, all of last week's trades on the same 'day' number as today will be counted as part of today's profit...including two weeks ago, three weeks ago, four weeks ago. As long as the day 'number' equals today, the profit evaluation will include it.

So, I changed the section to read: (i have added the lines in bold)
for (int cc = OrdersHistoryTotal() - 1; cc >= 0; cc--)
{
if (!OrderSelect(cc, SELECT_BY_POS, MODE_HISTORY) ) continue;
if(OrderSymbol() != Symbol() ) continue; //--only use this pair's profit, to stop this pair trading.
if (OrderMagicNumber() != MagicNumber) continue;
//if (TimeDayOfWeek(OrderCloseTime()) != TimeDayOfWeek(TimeCurrent()) ) continue;
if (OrderCloseTime() < iTime(Symbol(),PERIOD_D1,0) ) continue;

This change will only accept orders that have closed during today's bar period. All future modified versions of HGB, from spgandau, will include this change.

Cheers.
spgandau
 
Posts: 50
Joined: Thu Sep 20, 2012 2:17 am

HGB FIFO and Error Traps Thread

Postby spgandau » Sat Mar 14, 2015 9:12 pm

reserved
spgandau
 
Posts: 50
Joined: Thu Sep 20, 2012 2:17 am

HGB FIFO and Error Traps Thread

Postby SteveHopwood » Sat Mar 14, 2015 9:23 pm

Thanks spgandau. Your work is in the best tradition of SHF. :clap: :clap: :clap:

We are all grateful to you.

:xm:
Read the effing manual, ok?

Global Prime is the official SHF broker. Click here to sign up for a live account with Global Prime and join the several thousand SHF members who wisely choose GP as their broker of choice.

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 Tommaso (milanese) for all the incredible work he does here.
User avatar
SteveHopwood
 
Posts: 9198
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

HGB FIFO and Error Traps Thread

Postby MurphyMan » Sun Mar 22, 2015 3:30 pm

Thanks spgandau, will give it a go. As a USA guy who also uses FXCM, I think this will be really useful. Thanks for your effort. :clap:
User avatar
MurphyMan
 
Posts: 337
Joined: Tue Nov 15, 2011 2:35 pm
Location: Southern Illinois, USA

HGB FIFO and Error Traps Thread

Postby grasshopper » Mon Mar 23, 2015 8:12 pm

Thank you spgandau.

We need all the help we can get as hamstrung US fx traders.

Below is a link to an article on work a rounds for FIFO brokers that offer mini-lots.







http://www.tradingheroes.com/how-to-get ... us-broker/
grasshopper
 
Posts: 24
Joined: Sat Jan 14, 2012 2:58 pm

HGB FIFO and Error Traps Thread

Postby spgandau » Tue Mar 24, 2015 3:01 am

grasshopper » Mon Mar 23, 2015 3:12 pm wrote:Thank you spgandau.

We need all the help we can get as hamstrung US fx traders.

Below is a link to an article on work a rounds for FIFO brokers that offer mini-lots.

http://www.tradingheroes.com/how-to-get ... us-broker/


I looked at that link. Unfortunately, FXCM always combines any trades, regardless of trade lot size. So, anytime HGB calls for a trade change, I need FIFO to get an orderly exit out of existing positions. It has worked very well for the past several weeks.
Thanks for the input.

Cheers!
spgandau
 
Posts: 50
Joined: Thu Sep 20, 2012 2:17 am

HGB FIFO and Error Traps Thread

Postby MurphyMan » Tue Mar 24, 2015 12:20 pm

Spectacular so far. :yahoo:

Here is a new $10,000 demo running since Sunday evening. Currently up 1,740 pips. I think if it was live, I'd close everything and restart, but for now I'll let 'er run and see what happens. Set file also attached.

Untitled.png
You do not have the required permissions to view the files attached to this post.
User avatar
MurphyMan
 
Posts: 337
Joined: Tue Nov 15, 2011 2:35 pm
Location: Southern Illinois, USA

HGB FIFO and Error Traps Thread

Postby MurphyMan » Tue Mar 31, 2015 12:56 pm

I wish I could have posted results from last week, unfortunately, my computer had a severe crash last week and I had to take in to a shop (Which I NEVER do).

I started a fresh FXCM demo on Sunday evening and as of this morning, things are looking very good - up 1,112 pips! Incredible. :hi: Same set file as previously posted.

Some kind of magic going on here. BTW - I just scrolled through all the alert messages, and not one error alert!

Thanks to all.

Sam
User avatar
MurphyMan
 
Posts: 337
Joined: Tue Nov 15, 2011 2:35 pm
Location: Southern Illinois, USA

Next

Return to Thingy Bob EA's

Who is online

Users browsing this forum: No registered users and 0 guests