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.
nonlinear
Trader
Posts: 293
Joined: Fri Jun 01, 2012 2:56 pm
Location: Washington DC

HGB FIFO and Error Traps Thread

Post by nonlinear »

FXCM offered me this option when Citi closed (or was forced to close) its retail fx leg and transferred my accounts to FXCM. Citi did not have to comply with FIFO rules and allowed hedging. I didn't take up FXCM on its offer because some of my systems are sensitive to latency delays. Now I am considering taking up that offer on some accounts or transferring a few to ATC, who I have a small account with. The odd thing is that even though ATC supposedly uses FXCM for liquidity, the feeds are different. Not by much, but certainly enough to change performance with some systems (a few pips here and there can change things).
nonlinear
Trader
Posts: 293
Joined: Fri Jun 01, 2012 2:56 pm
Location: Washington DC

HGB FIFO and Error Traps Thread

Post by nonlinear »

nonlinear » Mon Nov 02, 2015 5:01 pm wrote:I am bumping this older thread to see if any US folks have tried using FXCM's off shore server option (UK I believe). I have heard FXCM can run accounts on the UK Empty4 server and then net back-end like ATC, thus making FIFO not an issue anymore. Of course this only works for systems where execution delay (sending orders across the Atlantic) is not that important.
I contacted FXCM about this and its not an option.
spgandau
Trader
Posts: 50
Joined: Thu Sep 20, 2012 2:17 am

HGB FIFO and Error Traps Thread

Post by spgandau »

Hello,

I have been out after a lengthy illness. I think I am "back on track", so hopefully will be back into the forex market.
I have been reviewing the various EA's and trying to determine which EA to use. I will be reviewing Holy Graily Bob n Grid, and HGB and his ma. I also looked at the Dream Teams Unbelievably Magnificent Shell Thingy.
I have re-installed BoHGB2x3 EA, with the 10.7/10.9 template that uses the Stoch indi for trade info.
I will be re-installing 10.7 HGB_v01k_strict_spgandau.mq4 and seeing how that does.

If anyone is using any EA that uses nanningbob's HGI / HGB (or versions thereof) that has been reasonably successful, I would be interested to take a look.

I tend to manually trade the signals from HGI, but also still looking for a good robot to help me when I am away from the computer.

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

HGB FIFO and Errors - Partial closures of multiple trades

Post by spgandau »

Partial order close issues with FIFO accounts,

I had an error code this past week. I had tried to use partial close features in HGB (a variety of the basic HGB EA). It appears that if any order is partially closed on a FIFO account, if the ORIGINAL order was partially closed, the part of the trade that remains will retain the original order time!

Therefore, any trade that was made AFTER the original trade (assuming you have multiple trades of the same symbol) will be UNABLE to do a partial close. You will get the error from the broker that you must close the earlier trades first. When the remaining part of the original trade is closed, then the next oldest order may be partially closed..etc...etc.

So, for FIFO (US traders), it seems that partial closing only works if there are only single trades of any given symbol.

I am using multiple open order strategies in a FIFO account, so from this point going forward, I will ensure that partial close features in any EA are turned off.

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

TooClose bug

Post by spgandau »

Hello fellow HGB traders,

Here is what I have found: When comparing the close of one trade and the opening of another....such that if the two are 'too close', the SafetyViolation triggers... if the OrderSelect value finds multiple trades of the same pair, and it happens to find an OLDER trade first, then compares to TimeCurrent, it can get a false indication to allow trading...which could violate the MinMinutesBetweenTrades value of the more recent trade. so, I removed the break value, and let the whole loop execute.

The original code of TooClose() is:

Code: Select all

//+------------------------------------------------------------------+
//|   original TooClose Code                                         |
//+------------------------------------------------------------------+
bool TooClose()
{
   //Returns false if the previously closed trade and the proposed new trade are sufficiently far apart, else return true. Called from IsTradeAllowed().
   
   SafetyViolation = false;//For chart feedback
         
   if (OrdersHistoryTotal() == 0) return(false);
   
   for (int cc = OrdersHistoryTotal() - 1; cc >= 0; cc--)
   {
      if (!OrderSelect(cc, SELECT_BY_POS, MODE_HISTORY) ) continue;
      if (OrderMagicNumber() != MagicNumber) continue;
      if (OrderSymbol() != Symbol() ) continue;
      
      //Examine the OrderCloseTime to see if it closed far enought back in time.
      if (TimeCurrent() - OrderCloseTime() < (MinMinutesBetweenTrades * 60))
      {
         SafetyViolation = true;
         return(true);//Too close, so disallow the trade
      }//if (OrderCloseTime() - TimeCurrent() < (MinMinutesBetweenTrades * 60))
      break;      
   }//for (int cc = OrdersHistoryTotal() - 1; cc >= 0; cc--)
   
   //Got this far, so there is no disqualifying trade in the history
   return(false);
   
}//bool TooClose()
My updated TooClose() code:

Code: Select all

//
//+------------------------------------------------------------------+
//|   modified TooClose from spgandau                                |
//+------------------------------------------------------------------+
bool TooClose()
{
	//Returns false if the previously closed trade and the proposed new trade are sufficiently far apart, else return true. Called from IsTradeAllowed().
	//-- also called by ReasonsNotToContinue()

	SafetyViolation = false;	//--For chart feedback

	if (OrdersHistoryTotal() == 0) return(false);

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

		//Examine the OrderCloseTime() to see if it closed far enough back in time.
		if (TimeCurrent() - OrderCloseTime() < (MinMinutesBetweenTrades * 60))	//--based on assumption that this is in 'seconds' not 'milliseconds'
		{
			SafetyViolation = true;
			return(true);//Too close, so disallow the trade
		}//-- end if (OrderCloseTime() - TimeCurrent() < (MinMinutesBetweenTrades * 60))
		//
      //break;	//--if there are multiple trades, it will take the first trade that it finds of the proper symbol....
		//--- If the trade happens to be an OLDer trade that is NOT within the SafetyViolation window, it will allow
		//--- trading to occur, which WILL trigger a Rogue Trading warning. THEREFORE, the 'break' has been removed.
		//--- This will allow ALL trades of the same symbol to be evaluated. Any one of them can trigger the SafetyViolation
		//--- to be 'true' before the routine ends.
	}//for (int cc = OrdersHistoryTotal() - 1; cc >= 0; cc--)
	//
	//Got this far, so there is no disqualifying trade in the history
	return(false);

}//bool TooClose()
Hopefully, this will be useful for some of you.
Cheers!
User avatar
Kopan
Trader
Posts: 15
Joined: Mon Apr 17, 2017 9:12 pm
Location: U.S.A.

HGB FIFO and Error Traps Thread

Post by Kopan »

A quick note to say "Thank You"! :good:

As a fellow US trader I was excited and relieved to see the work that you have contributed to address the ridiculous FIFO rules that we have to contend with. Certainly saves me some serious coding time making the additions.

I am still very much at the learning stage when it comes to HGI but am available to help Beta Test/Brainstorm code concepts should you desire. (have 25+ years IT industry experience). This week I am planning to review in detail your latest code version. At first glance, I appreciate the abundance of comments and tweaks to logic flow.

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

HGB FIFO and Error Traps Thread

Post by spgandau »

Kopan » Sun May 14, 2017 2:46 pm wrote:A quick note to say "Thank You"! :good:

As a fellow US trader I was excited and relieved to see the work that you have contributed to address the ridiculous FIFO rules that we have to contend with. Certainly saves me some serious coding time making the additions.

I am still very much at the learning stage when it comes to HGI but am available to help Beta Test/Brainstorm code concepts should you desire. (have 25+ years IT industry experience). This week I am planning to review in detail your latest code version. At first glance, I appreciate the abundance of comments and tweaks to logic flow.

Cheers

Thanks for the kind words. I have tended to stay with HGI / HGB basic code. I used BoHGB because he used the library version HGI ( hgi_lib.ex4 and mqh )....which IMHO deals with the "repaint" conversation quite well. I still use the HGI indicator on my charts, so that I have some reference when I troubleshoot my results. I have never participated in the repaint conversation, as I understand the issues and have been able to work with (and around) it.
It was from BoHGB's mods of Steve's primary input that I have made my inputs. As I read the Pips on Steriods Mq4 code, I can see possibilities for use by US traders, but it would be a LOT of work to adjust for the FIFO limits in that code.
So, I began to re-arrange the overall flow of the logic so that eventually, I could call more than one type of trade style in the "LookingForTradingOpportunities" subroutine.

I have stayed away from *.dll useage (I am on a linux machine, using WINE just for Empty4). When I have this code working with minimal trouble, I will begin re-using HGBB / MPTM to properly manage trades.

the pdf is not 100% detail complete...mostly block diagrams with some specific references to subroutines. I wanted the block diagram not to have "holes" in the logic. If you see some effective ways to simplify / improve the logic, let me know. I will be glad to look at it.
PS. I have been fixed glitches this week. Fixed code will come up in a few hours...

Cheers!
User avatar
Kopan
Trader
Posts: 15
Joined: Mon Apr 17, 2017 9:12 pm
Location: U.S.A.

HGB FIFO and Error Traps Thread

Post by Kopan »

Great!
Just grabbed your latest "02" version will start with it tomorrow.

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

HGB FIFO and Error Traps Thread

Post by spgandau »

I have just posted 2018 v01 c. However, I am struggling with non-executing code. In rollingtradecontrol, something is wrong with my logic(?). The intent was that if price retraced a specific amount, it would close the most profitable trade. Somehow, this is not happening.... I find that all trades will be allowed to go negative... not sure why. If you see the logical error, let me know.

For example: There are 5 trades that exist. Each one was opened at a different price (ie. 1st trade was at 1.220, 2nd trade at 1.240, 3rd trade at 1.260, 4th trade at 1.280, 5th trade at 1.300). Price is DOWN to 1.200. I sometimes see all 5 trades still live and all will be negative profit.

The logic that controls this is in rollingtradecontrol(...). When price hit 1.300, there would have been 5 live trades. if price reached 1.310, then the HIGH[0] is the 'trigger' value....if price drops 30 pips to 1.280, the pgm was designed to close the most profitable trade (in this case the 1st trade made at 1.220). This is not happening consistently.

I must be missing something obvious as to why the most profitable trade would not be closed. I am looking at the switch code:

Code: Select all

switch(cnt)
	{
			case 5:	//-- cnt = 5, which means there are 5 trades
         {
				//--if there are 5 trades, check the least profitable and see if it is > 0
				if(cnt >= 5)
				{
               if(OrderSelect((int)orderdata[0][1],SELECT_BY_TICKET)==true)
               {
                        ................................
                        ................................
               }   					   
					//
					if ( ((int)orderdata[0][4]==0 && (Bid > NormalizeDouble(orderdata[0][3], Digits) - (30/factor)) && (Bid > (NormalizeDouble(High[0], Digits) - (40/factor))) ) || ((int)orderdata[0][4]==1 && Bid < NormalizeDouble(orderdata[0][3], Digits) + (30/factor) && (Bid < (NormalizeDouble(Low[0], Digits) + (40/factor)))  ) ) //--price is moving and has not retraced OR..
					//-- price has never moved in the proper direction, but has not yet broken the open price.
					{
			         	Print("5 orders exist, price of order[0] has not retraced. Do not close any trades." );
               }
		   		else
               {
      						Print("5 orders exist, price retraced, close order[4](",(int)orderdata[4][1],"-- most profitable): ", NormalizeDouble(orderdata[4][0],Digits) );
			      			//
						      CloseEarlierTrades((int)orderdata[4][1], __FUNCTION__);   //-- only used for FIFO rules.  It will not affect non-FIFO accts if FIFObroker==false;
Many times, nothing is done at all. the trades just continue as if hte EA is not working. i have seen that the EA is displayed properly in the upper rt hand corner, so it appears to be operating..

if any of you logic types can evaluate this, and let me know what I am missing,...that would be appreciated!
Cheers!
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.

HGB FIFO and Error Traps Thread

Post by SteveHopwood »

Your code merely confuses me. I have no idea what the ticket part of your OrderSelect(etc) call is all about. I would be prepared to bet a fiver that the compiler does not either. :lol:

A pound to a penny bets that you have balsed up by over-complicating thingies. Simple is best, as a general rule.

The reason nobody has stepped up to try to help is: we haven't the foggiest idea what you are talking about.

Best to get your own thoughts straight and simplify what it is you are trying to achieve. To be honest, and not deliberately unkind, your OrderSelect() call looks nonsensical. As a general rule of life, if something looks ridiculous, then it usually is ridiculous.

Not a lot of help, I know, but the nearest I can come to helping. I hope you get this sorted out. You can always try the Steve Nuclear Option: start again. You would be amazed to learn how often I have pressed that little red button. :lol:

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

Return to “Thingy Bob EA's”