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

HGI custom Call
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=4901
Page 1 of 2
Author:  traderduke [ Fri Sep 16, 2016 4:39 pm ]
Post subject:  HGI custom Call

Coders
I appear to be missing several signals on HGI, Trend being the worst. I see changes to HGI_16.09 and I was wondering if there was any change to the icustom code for calling the HGI? I've added the redundant code, " HGI_Trend_UpArrow == true || HGI_TrendUp > 0 ||", but that didn't seem to help,

The latest I have was by Tommaso in March, 2015. See Code:

Code: Select all

void ReadIndicatorValues() //shift=0 is on
{
   // NEWEST CALL for v16.09 from Tommaso 3-1-2015; //coders hangout; custom call for 16.04
   // reset the signals
   HGI_Trend_UpArrow=false;
   HGI_Trend_DownArrow=false;
   HGI_Wavy_Gold=false;
   HGI_Wavy_Blue=false;

   HGI_Trend_Up = 0;
   HGI_Trend_Dn = 0;
   HGI_Wavy_G = 0;
   HGI_Wavy_B = 0;
                                 //Indic_Name = "HGI_v16.09";
   if (iCustom(Symbol(),TFHGI,Indic_Name,  0, Shift)!= EMPTY_VALUE) HGI_Trend_UpArrow=true;
   if (iCustom(Symbol(),TFHGI,Indic_Name,  1, Shift)!= EMPTY_VALUE) HGI_Trend_DownArrow=true;
   if (iCustom(Symbol(),TFHGI,Indic_Name,  6, Shift)!= EMPTY_VALUE) HGI_Wavy_Gold=true;
   if (iCustom(Symbol(),TFHGI,Indic_Name,  7, Shift)!= EMPTY_VALUE) HGI_Wavy_Blue=true;

   HGI_TrendUp = iCustom(Symbol(),TFHGI,Indic_Name,  0, Shift);
   HGI_TrendDn = iCustom(Symbol(),TFHGI,Indic_Name,  1, Shift);
   HGI_Wavy_G =  iCustom(Symbol(),TFHGI,Indic_Name,  6, Shift);
   HGI_Wavy_B =  iCustom(Symbol(),TFHGI,Indic_Name,  7, Shift);
    
}

bool BuySignal() 
   {
  ReadIndicatorValues();
 if (((HGI_Trend_UpArrow == true || 
      HGI_TrendUp > 0 ||
      HGI_Wavy_Blue == true ||   
      HGI_Wavy_B >0) && 
      (Close[1] > HGI_Wavy_B))
   && TimeCondition()) return(true);  return(false);
   }  
bool SellSignal() 
   {
  ReadIndicatorValues();
  if (((HGI_Trend_DownArrow == true || 
      HGI_TrendDn > 0 ||
      HGI_Wavy_Blue == true ||
      HGI_Wavy_B >0) &&
      (Close[1] < HGI_Wavy_B))
    && TimeCondition()) return(true);  return(false);
   }
bool BuyExitSignal()
   {
   ReadIndicatorValues();
  if (( ExitMode ==0 && (OrderType()==OP_BUY) &&
   ((HGI_Wavy_Gold == true && Close[1] < HGI_Wavy_G)|| (HGI_Wavy_Blue == true && Close[1] < HGI_Wavy_B)||(HGI_Trend_DownArrow == true))
     )|| !TimeCondition()) return(true);  return(false); 
   }
bool SellExitSignal()
   {
   ReadIndicatorValues();
  if  (( ExitMode ==0 && (OrderType()==OP_SELL) &&
   ((HGI_Wavy_Gold == true && Close[1] > HGI_Wavy_G)|| (HGI_Wavy_Blue == true && Close[1] > HGI_Wavy_B)||(HGI_Trend_UpArrow == true))
     )|| !TimeCondition()) return(true);  return(false); 
   }
Appreciate any help
Ray
Author:  milanese [ Fri Sep 16, 2016 4:55 pm ]
Post subject:  HGI custom Call

traderduke » Fri Sep 16, 2016 4:39 pm wrote:Coders
I appear to be missing several signals on HGI, Trend being the worst. I see changes to HGI_16.09 and I was wondering if there was any change to the icustom code for calling the HGI? I've added the redundant code, " HGI_Trend_UpArrow == true || HGI_TrendUp > 0 ||", but that didn't seem to help,

The latest I have was by Tommaso in March, 2015. See Code:

Code: Select all

void ReadIndicatorValues() //shift=0 is on
{
   // NEWEST CALL for v16.09 from Tommaso 3-1-2015; //coders hangout; custom call for 16.04
   // reset the signals
   HGI_Trend_UpArrow=false;
   HGI_Trend_DownArrow=false;
   HGI_Wavy_Gold=false;
   HGI_Wavy_Blue=false;

   HGI_Trend_Up = 0;
   HGI_Trend_Dn = 0;
   HGI_Wavy_G = 0;
   HGI_Wavy_B = 0;
                                 //Indic_Name = "HGI_v16.09";
   if (iCustom(Symbol(),TFHGI,Indic_Name,  0, Shift)!= EMPTY_VALUE) HGI_Trend_UpArrow=true;
   if (iCustom(Symbol(),TFHGI,Indic_Name,  1, Shift)!= EMPTY_VALUE) HGI_Trend_DownArrow=true;
   if (iCustom(Symbol(),TFHGI,Indic_Name,  6, Shift)!= EMPTY_VALUE) HGI_Wavy_Gold=true;
   if (iCustom(Symbol(),TFHGI,Indic_Name,  7, Shift)!= EMPTY_VALUE) HGI_Wavy_Blue=true;

   HGI_TrendUp = iCustom(Symbol(),TFHGI,Indic_Name,  0, Shift);
   HGI_TrendDn = iCustom(Symbol(),TFHGI,Indic_Name,  1, Shift);
   HGI_Wavy_G =  iCustom(Symbol(),TFHGI,Indic_Name,  6, Shift);
   HGI_Wavy_B =  iCustom(Symbol(),TFHGI,Indic_Name,  7, Shift);
    
}

bool BuySignal() 
   {
  ReadIndicatorValues();
 if (((HGI_Trend_UpArrow == true || 
      HGI_TrendUp > 0 ||
      HGI_Wavy_Blue == true ||   
      HGI_Wavy_B >0) && 
      (Close[1] > HGI_Wavy_B))
   && TimeCondition()) return(true);  return(false);
   }  
bool SellSignal() 
   {
  ReadIndicatorValues();
  if (((HGI_Trend_DownArrow == true || 
      HGI_TrendDn > 0 ||
      HGI_Wavy_Blue == true ||
      HGI_Wavy_B >0) &&
      (Close[1] < HGI_Wavy_B))
    && TimeCondition()) return(true);  return(false);
   }
bool BuyExitSignal()
   {
   ReadIndicatorValues();
  if (( ExitMode ==0 && (OrderType()==OP_BUY) &&
   ((HGI_Wavy_Gold == true && Close[1] < HGI_Wavy_G)|| (HGI_Wavy_Blue == true && Close[1] < HGI_Wavy_B)||(HGI_Trend_DownArrow == true))
     )|| !TimeCondition()) return(true);  return(false); 
   }
bool SellExitSignal()
   {
   ReadIndicatorValues();
  if  (( ExitMode ==0 && (OrderType()==OP_SELL) &&
   ((HGI_Wavy_Gold == true && Close[1] > HGI_Wavy_G)|| (HGI_Wavy_Blue == true && Close[1] > HGI_Wavy_B)||(HGI_Trend_UpArrow == true))
     )|| !TimeCondition()) return(true);  return(false); 
   }
Appreciate any help
Ray
they are no changes in the way you have to use iCustom calls between 16.04 and 16.09, the only thingy was that 16.09 not worked correct with latest 1010 builds together, when you not had enough bars that is now fixed and you should consider to test again the latest 16.09 version, attached to the first post of the HGI thread..


Cheers :)

Tommaso
Author:  traderduke [ Fri Sep 16, 2016 5:55 pm ]
Post subject:  HGI custom Call

Tommaso
Thanks or the quick response and information. I am using 1010, will try the latest 16.09.

Ray
Author:  BobbyT [ Mon Sep 19, 2016 9:41 pm ]
Post subject:  HGI custom Call

Ray,

Depending on what your lookback period for trading signals is going to be you may want to have a look at using the HGI library.

I found that when using iCustom the signals can degerate a certain distance into the past. I think this occurs as an iCustom call will store a snapshot of HGI in cache which is then not updated at a specific bar unless that shift is called again.

If you are interested in using the library, take a gander at the wrappedHGI indi I posted in NBs forum a while back or Renes library version of his HGI matrix (which I heavily pilfered from to create wrappedHGI).

Of course if you are only looking at bar0 and bar1 then all this is of little consequence to you.

Cheers,
BobbyT
Author:  renexxxx [ Mon Sep 19, 2016 9:55 pm ]
Post subject:  HGI custom Call

BobbyT » Tue Sep 20, 2016 7:41 am wrote: Of course if you are only looking at bar0 and bar1 then all this is of little consequence to you.
Even so, it is much preferable from a technical point to use the HGI Library. As a rule, I would encourage everyone to avoid using iCustom()-calls. There are situations where it is impractical to rewrite the underlying indicator (eg. if the time series definition is recursive and would need a long lead-up to converge to a value). However, in most cases you can convert the indicator to a function and your code will run much cleaner and leaner.
Author:  BobbyT [ Mon Sep 19, 2016 11:56 pm ]
Post subject:  HGI custom Call

renexxxx » Tue Sep 20, 2016 7:55 am wrote:
Even so, it is much preferable from a technical point to use the HGI Library. As a rule, I would encourage everyone to avoid using iCustom()-calls. There are situations where it is impractical to rewrite the underlying indicator (eg. if the time series definition is recursive and would need a long lead-up to converge to a value). However, in most cases you can convert the indicator to a function and your code will run much cleaner and leaner.
Rene, I can only agree with you there. I initially wrote wrappedHGI using iCustom calls and it was brutal. A single chart with minimal signals/tf enabled resulted in my 6700k locking up. Although it was odd because neither the CPU nor the 16gb of ram appeared to be terribly loaded.

I rewrote it with the library and there performance was infinitely better. To the point that the indi can paint trend arrows and wavies on 3 timeframes on 28 charts and only has a 1 second delay when switching between charts or timeframes. *Proud*

I wonder, does Empty4 have a stupidly small cap on the amount of resources it can draw. If so is there anyway to increase system allocation to the program (similar to what is doable in R/Rstudio)

Cheers,
BobbyT
Author:  traderduke [ Wed Sep 21, 2016 3:03 pm ]
Post subject:  HGI custom Call

Tommaso, Rene & BobbyT,
Thank you for your help, I believe the newer version of 16.09 has help a lot but as you can see it’s still missing some signals even at shift = 1. I looked at BobbyT’s wrapped and compared it to 16.09, It looks pretty much the same and I don’t see any data to read in the Data Window only myHGI shows. see attached Chart:
Here are the results SO far. I started at 0700 EDT, which is GMT-4. My broker FXChoice is at GMT +3.

The custom call & trade code is attached as is the charts to show the good & the bad;
I use 12 pr, all have Shift = 1.
I’ve had 9 pairs trading.
EU & UJ traded correctly
GU & UCad missed their exit
NU & GCad are awaiting their exit in this 4hr segment
AU & UChf are working good
EURJPY missed its short entry
GN, GA & GJ are correctly waiting for an entry, WHAT A set of winners I missed

Rene, “it is much preferable from a technical point to use the HGI Library”, what does using the HGI library call for I’m not sure if skilled enough to code it. I’ll check your matrix for some hints but any help would be appreciated.

Here is my Full trade code:

Code: Select all

void ReadIndicatorValues() //shift=1 is on
{
   // NEWEST CALL from Tommaso 3-1-2015; //coders hangout; custom call for 16.09
   // reset the signals
   HGI_Trend_UpArrow=false;
   HGI_Trend_DownArrow=false;
   HGI_Wavy_Gold=false;
   HGI_Wavy_Blue=false;

   HGI_Trend_Up = 0;
   HGI_Trend_Dn = 0;
   HGI_Wavy_G = 0;
   HGI_Wavy_B = 0;
  
   if (iCustom(Symbol(),TFHGI,Indic_Name,  0, Shift)!= EMPTY_VALUE) HGI_Trend_UpArrow=true;
   if (iCustom(Symbol(),TFHGI,Indic_Name,  1, Shift)!= EMPTY_VALUE) HGI_Trend_DownArrow=true;
   if (iCustom(Symbol(),TFHGI,Indic_Name,  6, Shift)!= EMPTY_VALUE) HGI_Wavy_Gold=true;
   if (iCustom(Symbol(),TFHGI,Indic_Name,  7, Shift)!= EMPTY_VALUE) HGI_Wavy_Blue=true;

   HGI_TrendUp = iCustom(Symbol(),TFHGI,Indic_Name,  0, Shift);
   HGI_TrendDn = iCustom(Symbol(),TFHGI,Indic_Name,  1, Shift);
   HGI_Wavy_G =  iCustom(Symbol(),TFHGI,Indic_Name,  6, Shift);
   HGI_Wavy_B =  iCustom(Symbol(),TFHGI,Indic_Name,  7, Shift);
}

bool BuySignal() 
   {
  ReadIndicatorValues();
 if ((HGI_Trend_UpArrow == true || 
   (HGI_Wavy_Blue == true && Close[1] > HGI_Wavy_B))
   && TimeCondition()) return(true);  return(false);
   }  
bool SellSignal() 
   {
  ReadIndicatorValues();
  if ((HGI_Trend_DownArrow == true || 
   (HGI_Wavy_Blue == true && Close[1] < HGI_Wavy_B))
     && TimeCondition()) return(true);  return(false);
   }
bool BuyExitSignal()
   {
   ReadIndicatorValues();
  if (( ExitMode ==0 && (OrderType()==OP_BUY) &&
   ((HGI_Wavy_Gold == true && Close[1] < HGI_Wavy_G)|| 
    (HGI_Wavy_Blue == true && Close[1] < HGI_Wavy_B)||
    (HGI_Trend_DownArrow == true))
     )|| !TimeCondition()) return(true);  return(false); 
   }
bool SellExitSignal()
   {
   ReadIndicatorValues();
  if  (( ExitMode ==0 && (OrderType()==OP_SELL) &&
   ((HGI_Wavy_Gold == true && Close[1] > HGI_Wavy_G)|| 
    (HGI_Wavy_Blue == true && Close[1] > HGI_Wavy_B)||
    (HGI_Trend_UpArrow == true))
     )|| !TimeCondition()) return(true);  return(false); 
   }
9-21-2016 9-13-21 AM-custom call v7-2.png
9-21-2016 9-13-21 AM-custom call v7-all-3.png
9-21-2016 10-18-55 AM-de30-wrapped.png
Thank you all for your past & I hope continued help

Ray
Author:  renexxxx [ Wed Sep 21, 2016 10:56 pm ]
Post subject:  HGI custom Call

traderduke » Thu Sep 22, 2016 1:03 am wrote: Rene, “it is much preferable from a technical point to use the HGI Library”, what does using the HGI library call for I’m not sure if skilled enough to code it. I’ll check your matrix for some hints but any help would be appreciated.
It is --in my opinion- much easier to get the signals from the HGI Library, than it is to fish them out of the buffers of the HGI indicator via the iCustom-call.

A comparison:

HGI-library;

Code: Select all

#include <hgi_lib.mqh>

SIGNAL mySignal = getHGISignal( _Symbol, _Period, shift );   // Returns the HGI Signal (i.e. ARROW) for the current symbol and period, on candle=shift

SLOPE mySlope = getHGISlope( _Symbol, _Period, shift );     // Returns the WAVEY Signal for the current symbol and period, on candle=shift.
There can be a signal and a wavey on the same candle. If there is no signal, for a given (symbol, timeframe, shift)-triplet, getHGISignal returns NONE (A predefined member of the SIGNAL enumeration type). Similarly, if there is no wavey for a given (symbol, timeframe, shift)-triplet, getHGISlope returns UNDEFINED. If you want to start looking for the most recent signal you do something like:

Code: Select all

#include <hgi_lib.mqh>

SIGNAL mySignal;
for(int shift=0; shift < MaxLookback; shift++) {
   mySignal = getHGISignal(_Symbol, _Period, shift);
   if ( mySignal != NONE ) break;
}
if ( mySignal != NONE ) { 
   // do something with the most recent signal
}
Similarly for the waves.

Compare the same with the iCustom-calls:

To get the signal for the current symbol and period and a given shift

Code: Select all

double indiValue;
SIGNAL mySignal = NONE;
int iBuffer;
for(iBuffer=0; iBuffer < 6; iBuffer++) {
   indiValue = iCustom( _Symbol, _Period, "HGI v16.09", true, iBuffer, shift );
   if ( indiValue != EMPTY_VALUE ) break;
}
if ( indiValue != EMPTY_VALUE ) {
   switch(iBuffer) {
      case 0  : mySignal = TRENDUP; break;
      case 1  : mySignal = TRENDDN; break;
      case 2  : mySignal = RANGEUP; break;
      case 3  : mySignal = RANGEDN; break;
      case 4  : mySignal = RADUP; break;
      case 5  : mySignal = RADDN; break;
   }
}
// Pffft.
In other words, you don't know in which buffer a possible signal is hiding ... that's why you need to check them all and translate the buffer number into the type of signal. Sounds like a roundabout way, doesn't it?

As for the waveys, using the iCustom-call, it gets even longer. The waveys are hiding in buffer 6 and 7, but to find out if it is a HIGH or a LOW wavey, we must compare the indiValue with the HIGH of the candle, like so:

Code: Select all

SLOPE mySlope = UNDEFINED;
int iBuffer;
for(iBuffer=6; iBuffer < 8; iBuffer++) {
   indiValue = iCustom( _Symbol, _Period, "HGI v16.09", true, iBuffer, shift );
   if ( indiValue != EMPTY_VALUE ) break;
}
if ( indiValue != EMPTY_VALUE ) {
   bool high = (iHigh( _Symbol, _Period, shift ) < indiValue)
   switch(iBuffer) {
      case 6 : mySlope = ( high ) ? RANGEABOVE : RANGEBELOW; break;
      case 7 : mySlope = ( high ) ? TRENDABOVE : TRENDBELOW; break;
   }
}
Incidentally, this is not tested code, this is just me typing away at warp speed, so beware! But hopefully, it clarifies this "mysterious, incomprehensible" HGI Library call.

To summarize the differences:
  • The HGI Library call is quicker (in terms of CPU) and leaner (in terms of memory consumption) as compared to the iCustom call
  • The HGI Library is arguably easier to use
  • BUT, there is a difference. Empty4 caches the indicator once it has been loaded using the iCustom() call. As long as the indicator is not re-loaded (and it is not, unless you unload the EA), SIGNALS and WAVEYS for past candles (i.e. those with a shift > 0) are not updated. In other words, the iCustom-call returns always the same information for shift>0. This is not the case with the HGI Library call, as each call results in a recalculation (inside the HGI Library) of the signals, and signals and/or waveys can repaint.
Author:  tomele [ Fri Sep 23, 2016 12:24 am ]
Post subject:  HGI custom Call

Rene,

a very good explanation. Even I understand it.
Author:  dap711 [ Sat Oct 15, 2016 5:32 am ]
Post subject:  HGI custom Call

renexxxx » To summarize the differences:
  • The HGI Library call is quicker (in terms of CPU) and leaner (in terms of memory consumption) as compared to the iCustom call
  • The HGI Library is arguably easier to use
  • BUT, there is a difference. Empty4 caches the indicator once it has been loaded using the iCustom() call. As long as the indicator is not re-loaded (and it is not, unless you unload the EA), SIGNALS and WAVEYS for past candles (i.e. those with a shift > 0) are not updated. In other words, the iCustom-call returns always the same information for shift>0. This is not the case with the HGI Library call, as each call results in a recalculation (inside the HGI Library) of the signals, and signals and/or waveys can repaint.

Thank you so much for the explanation Rene. I too have been battling missing signals from the iCustom call and will now rewrite my code to use the library. I would also like to contribute the idea of iterating the "for" statement in a descending direction instead of ascending. The benefit of doing so is the last call to iCustom is the most current candle. Here is what I have been using .. borrowed most of it from Steve's code in HGB'nD'nSS .. :)

Code: Select all

      if (UseHGI)
      {
         static datetime OldHtfHgiTime = 0;
        TrendTimeFrameStatus = hginotrend;
         LongTrendDetected =  false;
         ShortTrendDetected = false;
         LongBlueWaveDetected=false;
         ShortBlueWaveDetected=false;
         
        for (cc = TrendTimeFrameCandlesLookBack; cc > -1 ; cc--)
        {

            //Buffer 0 contains a large green trend up arrow
            val = GetHGI(Symbol(), TrendTimeFrame, 0, cc);
            if (!CloseEnough(val, EMPTY_VALUE) )
            {
                  TrendTimeFrameStatus = Trenduparrow;
                  TrendTimeFrameCandlesBack = cc;//For chart display
                  LongTrendDetected = true;
                  if( cc == 0)
                  {
                     BuySignal = true;
                  }
            }//if (!CloseEnough(val 0) )
       
            //Buffer 1 holds large red down trend arrow
            val = GetHGI(Symbol(), TrendTimeFrame, 1, cc);
            if (!CloseEnough(val, EMPTY_VALUE) )
            {
                  TrendTimeFrameStatus = Trenddownarrow;
                  TrendTimeFrameCandlesBack = cc;//For chart display
                  ShortTrendDetected = true;
                  if( cc == 0)
                  {
                     SellSignal = true;
                  }
            }//if (!CloseEnough(val 0) )

            //RAD signal tells us we are already in a trend.
            //We are looking for the retrace off the 1st or 7th sixth so we are looking for big arrows
            //Buffer 4 holds green Rad arrows
            val = GetHGI(Symbol(), TrendTimeFrame, 4, cc);
            if (!CloseEnough(val, EMPTY_VALUE) )
            {
               TrendTimeFrameStatus = Raduparrow;
               TrendTimeFrameCandlesBack = cc;//For chart display
               if( cc == 0)
               {
                  BuySignal = true;
               }
            }//if (!CloseEnough(val 0) )

            //Buffer 5 holds red Rad arrows
            val = GetHGI(Symbol(), TrendTimeFrame, 5, cc);
            if (!CloseEnough(val, EMPTY_VALUE) )
            {
               TrendTimeFrameStatus = Raddownarrow;
               TrendTimeFrameCandlesBack = cc;//For chart display
               ShortTrendDetected = true;
               if( cc == 0)
               {
                  SellSignal = true;
               }
            }//if (!CloseEnough(val 0) )


            //Buffer 6 holds a wavy range - yellow squiggle
            val = GetHGI(Symbol(), TrendTimeFrame, 6, cc);
            if (!CloseEnough(val, EMPTY_VALUE)  )
            {
               TrendTimeFrameStatus = Waverange;
               ShortTrendDetected = false;
               LongTrendDetected = false;
               TrendTimeFrameCandlesBack = cc;//For chart display
               if( cc == 0)
               {
                  SellCloseSignal = true;
                  BuyCloseSignal = true;
                  BuySignal = false;
                  SellSignal = false;
               }
            }//if (!CloseEnough(val 0) )  

           //Buffer 7 holds a wavy trend - blue squiggle
            val = GetHGI(Symbol(), TrendTimeFrame, 7, cc);
            if (!CloseEnough(val, EMPTY_VALUE) )
            {
               if (Bid > val)
               {
                  LongBlueWaveDetected=true;
                  TrendTimeFrameStatus = Wavebuytrend;
                  LongTrendDetected = true;
                  TrendTimeFrameCandlesBack = cc;//For chart display
                  if( cc == 0)
                  {
                     BuySignal = true;
                  }
               }//if (Bid > val)
               else
               {
                  ShortBlueWaveDetected=true;
                  TrendTimeFrameStatus = Waveselltrend;   
                  ShortTrendDetected = true;
                  TrendTimeFrameCandlesBack = cc;//For chart display
                  if( cc == 1)
                  {
                     SellSignal = true;
                  }
              }//else
               
            }//if (!CloseEnough(val 0) )  
                
         }//for (cc = 1; cc < iBars(Symbol(), TrendTimeFrame); cc++)
     
      }//if (UseHGI)
All times are UTC Page 1 of 2