• Home
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • User/Email: Password:
  • 12:26pm
Menu
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • 12:26pm
Sister Sites
  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Options

Bookmark Thread

First Page First Unread Last Page Last Post

Print Thread

Similar Threads

Metatrader 4 vs Metatrader 5! 22 replies

MetaTrader demo question 5 replies

Strategy tester queries 1 reply

Metatrader 5 is going to wipe out your Metatrader 4 indicators / systems 13 replies

iCustom and Time (2 unrelated queries) 16 replies

  • Platform Tech
  • /
  • Reply to Thread
  • Subscribe

Metatrader Queries

  • Post #1
  • Quote
  • First Post: Nov 19, 2008 4:15pm Nov 19, 2008 4:15pm
  •  RichyF
  • | Joined Nov 2008 | Status: Member | 23 Posts
Hi Guys
First post so please correct me if i have posted in the wrong place.
I am in the early stages of developing an EA and am struggling with some basic syntax basics.

I would like to use the Hull indicator but am struggling to reference it in my logic. I can find out what its figure is but thats not what I am after. I would like to know what its status is (Up trend, downtrend or Non-trending).

Is this easy to do?

Thanks for your help in advance.
Rich
  • Post #2
  • Quote
  • Nov 21, 2008 12:00pm Nov 21, 2008 12:00pm
  •  Zen_Leow
  • Joined Jun 2008 | Status: Programming for a better future. | 649 Posts
I'm not sure which hull indicator you're using, it helps if you post it up next time.

anyway, assuming you're using the same as mine, you should be using iCustom function to load this indi yes? Many indicators provide more than 1 value concurrently. This indicator has 3 modes for the 3 types of values it provides. Here's what I do. take note of the change in "mode".

Inserted Code
extern int     xPeriod=60; 
extern double  xSlope = 0.25;
 
double GetHullMAValue(int shift)
{
   iCustom(NULL, 0, "hull", xPeriod, xSlope, 0, shift));
}
 
double GetHullUpValue(int shift)
{
   iCustom(NULL, 0, "hull", xPeriod, xSlope, 1, shift));
}
 
double GetHullDownValue(int shift)
{
   iCustom(NULL, 0, "hull", xPeriod, xSlope, 2, shift));
}

Then I'll just use these functions GetHullMAValue, GetHullUpValue, GetHullDownValue to access the values I want.
Programming for a better future.
 
 
  • Post #3
  • Quote
  • Nov 21, 2008 12:10pm Nov 21, 2008 12:10pm
  •  Zen_Leow
  • Joined Jun 2008 | Status: Programming for a better future. | 649 Posts
if you wanna know whether its up or down at that particular candle,

just check the up and down value against the MA value.

e.g.

Inserted Code
bool HullIsUp(int shift)
{
   if (GetHullUpValue(shift) == GetHullMAValue(shift) && GetHullDownValue(shift) != GetHullMAValue(shift))
   {
      return (true);
   }
   return (false);
}
 
bool HullIsUp(int shift)
{
   if (GetHullUpValue(shift) != GetHullMAValue(shift) && GetHullDownValue(shift) == GetHullMAValue(shift))
   {
      return (true);
   }
   return (false);
}
 
bool HullIsNonTrending(int shift)
{
   if (GetHullUpValue(shift) != GetHullMAValue(shift) && GetHullDownValue(shift) != GetHullMAValue(shift))
   {
      return (true);
   }
   return (false);
}
Programming for a better future.
 
 
  • Post #4
  • Quote
  • Nov 23, 2008 6:07am Nov 23, 2008 6:07am
  •  RichyF
  • | Joined Nov 2008 | Status: Member | 23 Posts
Hi Zen Leow
Thanks for your help with this, looks exactly the info I was after, will try it out and let you know how it goes

Again, thanks very much

Rich
 
 
  • Post #5
  • Quote
  • Nov 23, 2008 6:52am Nov 23, 2008 6:52am
  •  RichyF
  • | Joined Nov 2008 | Status: Member | 23 Posts
Hi Guys
This has helped me understand much better how to reference Custom Indicators using the iCustom function. However i am unsure if i am able to achieve what it is im trying to do with this indicator.

The indicator i am using is the Hull THV one.
When i place the indicator on a chart it draws a line and colours the line according to its slope. Red for up, yellow for no-slope and green for down.

What i am trying to find out is what slope (Or what colour even) the line is at the last bar.

I have tried the different methods mentioned above and am able to get back the Hull parameters and values but not the colour or slope.

Any ideas?

Cheers

Rich
 
 
  • Post #6
  • Quote
  • Nov 24, 2008 11:39am Nov 24, 2008 11:39am
  •  Zen_Leow
  • Joined Jun 2008 | Status: Programming for a better future. | 649 Posts
first of all, you're most welcome.

secondly, again, it helps if you can post the codes for the indicator you're using, I need the mq4 file to know exactly what its doing so as to answer your queries.

without the codes I can only guess and attempt to answer your questions based on the hull indicator I have.

let me try to explain the basic concept of line indicators.

An array (aka buffer) of floating (double) numbers are calculated and constantly refreshed for each tick.

These floating numbers are used to plot the line you see on your indicator window. You can have many buffers, each buffer can be attached to 1 line and each line can only have 1 color.

if what appears to be a single line but having 3 colors, that is actually 3 lines. and they are drawn 1 on top of another.

how then does it overlap so nicely you might ask.

Now u must get aquainted with this convenient little constant variable known as "EMPTY_VALUE". any point in the buffer that's given the value of "EMPTY_VALUE" will not be drawn. don't worry, your line won't go distorted with a cutting down to 0, it'll merely be cut off and continue on at the next value within the array with a value other than "EMPTY_VALUE".

usually a base line is drawn first. Gray color in my case. that is the one with all the values set nicely without any "EMPTY_VALUE" line up in its buffer.
e.g. the 10 values I set here.

main_buffer[0] = 2.456
main_buffer[1] = 2.567
main_buffer[2] = 2.839
main_buffer[3] = 2.910
main_buffer[4] = 2.736
main_buffer[5] = 2.736
main_buffer[6] = 2.736
main_buffer[7] = 2.645
main_buffer[8] = 2.432
main_buffer[9] = 2.144

then I will draw the up line using my up_buffer[] by checking the main_buffer[], if its an increment, I give the same value as the main line, if its a decrement or equal, I give it an "EMPTY_VALUE". remember, in MQL, candle shift goes backwards. the bigger the index number the more far back it is on chart. 0 is the current value. That means the indicator will usually always start looking from the largest index value towards the smallest index value, which means looking from past to present. in this case, from 9 to 0.

up_buffer[0] = EMPTY_VALUE
up_buffer[1] = EMPTY_VALUE
up_buffer[2] = EMPTY_VALUE
up_buffer[3] = 2.910
up_buffer[4] = EMPTY_VALUE
up_buffer[5] = EMPTY_VALUE
up_buffer[6] = 2.736
up_buffer[7] = 2.645
up_buffer[8] = 2.432
up_buffer[9] = 2.144

now draw the down line. basically the same except in the opposite fashion.

down_buffer[0] = 2.456
down_buffer[1] = 2.567
down_buffer[2] = 2.839
down_buffer[3] = EMPTY_VALUE
down_buffer[4] = EMPTY_VALUE
down_buffer[5] = EMPTY_VALUE
down_buffer[6] = EMPTY_VALUE
down_buffer[7] = EMPTY_VALUE
down_buffer[8] = EMPTY_VALUE
down_buffer[9] = 2.144 // nothing in the past to check with.

assuming the indicator draws a gray line using the main buffer. draws a green line using the up buffer, draws a red line using the down buffer. you will get a single line with all 3 colors showing the up and the down and the non-trending.

all it takes for an EA or another indicator to know if at a certain point in time, is the line a up or a down, simply check at that point in time, if the up buffer has a value other than EMPTY_VALUE, it is an up trend. if the down buffer has a value other than EMPTY_VALUE, it is a down trend. if both down and up buffers have EMPTY_VALUE, it is a non-trending period.

I've posted the codes necessary to do all these in my previous post. this one is just to help you understand what its doing.

let me know if you need help. again... POST THE INDICATOR'S CODES!!! =)

regards,
Zen
Programming for a better future.
 
 
  • Post #7
  • Quote
  • Last Post: Nov 26, 2008 4:37pm Nov 26, 2008 4:37pm
  •  RichyF
  • | Joined Nov 2008 | Status: Member | 23 Posts
Hi Zen
Thanks very much for the reply, a very imformative post which I hope to understand in more depth as I move forward with this.

Here is the indicator I have been using. I found it on this forum along with a few others but have found it extremely useful. Would like to use it in my EA but cannot understand it enough to be able to work reference it. (Hope its ok to post other peoples code etc, not sure on the etiqute etc but have left all the commenting in. Please let me know if i have done wrong by posting this.

Again, Many Thanks

Code:
Inserted Code
//+------------------------------------------------------------------+
//|                     Indicator:           Hull moving average.mq4 |
//|                       Version:                             0.002 |
//|                     Copyright:              Rabbit Traders Group |
//|                        E-mail:       [email protected] |
//|        Modified by Cobraforex for THV System, www.cobraforex.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, Rabbit Traders Group"
#property link      "www.artattica.net"

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Yellow
#property indicator_width1 3
#property indicator_color2 FireBrick
#property indicator_width2 3
#property indicator_color3 Green
#property indicator_width3 3

extern int     xPeriod=55; 
extern double  xSlope = 2.0;

double HMA[],up[],dn[];

int init()  {
   
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,HMA);
SetIndexLabel(0,"HMA " + xPeriod + " , " + xSlope) ;
 
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,up);

SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(2,dn);

return(0);

}

int deinit()  {return(0); }

int start()  {

double sqrt = MathRound ( MathSqrt( xPeriod ) );

for(int i=Bars;i>=0;i--) {   
   double sum = 0;
   int wma_sum = 0;
   for(int j=0; j < sqrt; j++) {      
      double val = 2*iMA(NULL, 0, MathRound(xPeriod/2), 0, MODE_LWMA, PRICE_MEDIAN, i+j)- iMA(NULL, 0, xPeriod, 0, MODE_LWMA, PRICE_MEDIAN, i+j); 
      sum = sum + val*(sqrt-j);
      wma_sum = wma_sum + (sqrt-j);   
   } 
   HMA[i] = sum/wma_sum;
  
   if(HMA[i]>HMA[i+1]+xSlope*Point) up[i]=HMA[i];
   if(HMA[i]<HMA[i+1]-xSlope*Point) dn[i]=HMA[i];
}


return(0);  
 
}
 
 
  • Platform Tech
  • /
  • Metatrader Queries
  • Reply to Thread
0 traders viewing now
Top of Page
Forex Factory Blog Updated: Alerting All Members
  • Facebook
  • Twitter
About FF
  • Mission
  • Products
  • User Guide
  • Media Kit
  • Blog
  • Contact
FF Products
  • Forums
  • Trades
  • Calendar
  • News
  • Market
  • Brokers
  • Trade Explorer
FF Website
  • Homepage
  • Search
  • Members
  • Report a Bug
Follow FF
  • Facebook
  • Twitter

FF Sister Sites:

  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Forex Factory® is a brand of Fair Economy, Inc.

Terms of Service / ©2022