Download MetaTrader 5
To add comments, please log in or register
Download MetaTrader 5 for iPad and trade anywhere!
lupo.busca
1033
lupo.busca 2014.12.03 16:33 

Hi all,

and thanks in advance for everyone who's givin' up his time supportin' the community...!!!

My problem:

I got the Supertrend-Indicator

https://www.mql5.com/en/code/576

and I wanna work with his indicator data. But when I try to use it in an EA via iCustom() I don't get the right values...!?

I tested it in Strategy Tester & checked, that the indicator itself produce the correct data - I can see it in the data window. But for an unkown reason it didn't pass it correctly to my EA.

So I set up an EA which does nothing except printing the actuell value to the journal. I guess it's just a "beginner fault" - can you please make my day & give me a good advice?!?! Thx...

Attached is the EA...

Greetings

Lupo

//+------------------------------------------------------------------+
//|                                                 Supertrend Check |
//|                                                 Marc             |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Marc"
#property link      ""
#property description "Supertrend_Check v0.1"

//+------------------------------------------------------------------+
//|Global variables                                                  |
//+------------------------------------------------------------------+
int      SuperTrendHandle;           //handle
double   Supertrend[];               //dynamic array to store the indicator values

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
  //--- Get handle for SuperTrend indicator
  SuperTrendHandle=iCustom(NULL,0,"supertrend",10,3,false);
  return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
      //--- Supertrend START
      //--- check for errors
      if(SuperTrendHandle<0)
        {
         Alert("Error Creating Handles for SuperTrend - error: ",GetLastError(),"!!");
        }
      //--- filling arrays with current values of iCustom
      //--- Copying elements
      CopyBuffer(SuperTrendHandle,0,0,20,Supertrend);
      //--- set indexing of elements as series
      ArraySetAsSeries(Supertrend,true);
      //--- SuperTrend END

      //--- for debugging
      Print("Supertrend: ",Supertrend[0]);
 }
 
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---Indicator  release
   IndicatorRelease(SuperTrendHandle);

  }
//+------------------------------------------------------------------+


SuperTrend
SuperTrend
  • votes: 16
  • 2011.10.18
  • FxGeek
  • www.mql5.com
SuperTrend indicator.
Alain Verleyen
Moderator
30635
Alain Verleyen 2014.12.06 12:30  
lupo.busca:

Hi all,

and thanks in advance for everyone who's givin' up his time supportin' the community...!!!

My problem:

I got the Supertrend-Indicator

https://www.mql5.com/en/code/576

and I wanna work with his indicator data. But when I try to use it in an EA via iCustom() I don't get the right values...!?

I tested it in Strategy Tester & checked, that the indicator itself produce the correct data - I can see it in the data window. But for an unkown reason it didn't pass it correctly to my EA.

So I set up an EA which does nothing except printing the actuell value to the journal. I guess it's just a "beginner fault" - can you please make my day & give me a good advice?!?! Thx...

Attached is the EA...

Greetings

Lupo

     CopyBuffer(SuperTrendHandle,2,0,20,Supertrend);

You also need to add error checking when using CopyBuffer().

lupo.busca
1033
lupo.busca 2014.12.12 13:06  
angevoyageur:

You also need to add error checking when using CopyBuffer().

Hi angevoyageur,

sorry for the delay, was hooked up in another project.

And MANY THANKS for the solution!

After getting your reply this morrning - for some reason I don't get a notification... - I thought:"Ok, that is a typical beginners fault..."

Thanks again & have a nice weekend!

Lupo

Alain Verleyen
Moderator
30635
Alain Verleyen 2014.12.12 13:12  
lupo.busca:

Hi angevoyageur,

sorry for the delay, was hooked up in another project.

And MANY THANKS for the solution!

After getting your reply this morrning - for some reason I don't get a notification... - I thought:"Ok, that is a typical beginners fault..."

Thanks again & have a nice weekend!

Lupo

No worries, you are welcome.
lupo.busca
1033
lupo.busca 2014.12.17 11:26  

Hi angavoygeur or anybody else who can help me!!!

I thought I got it, but there are new questions... ;-)


When I put in the EA just a 

Print("Supertrend(1): ",Supertrend[1]);


he gives me values like

2014.12.17 10:50:37.342    2014.12.03 20:00:00   Supertrend(1): 9.881312916824931e-324

but in debugging I can see that Supertrend[1] gives correct values. And also if i print directly from the indicator in tester the values he shows the correct values, e.g.:

2014.12.17 11:11:42.046    2014.12.03 05:13:40   Supertrend[11851]: 1.240622

And the EA is working after the changes provided by angevoyageur!??


I had written another custom indicator to see if I can catch it by my own. Just a

Middle=((high[i]+low[i])/2)

When I call him plain from an EA, print the values to the journal I got crap like above - when I print it from the indicator directly the values are ok...


And last question - for now! ;-) - , which I also don't get:

when I test ANY indicator from 2014-12-01 until  2014-12-16 on e.g. EURUSD oer also USDJPY he just test until the 2014-12-08!!?? I sdid it with the supertrend, with other custom indicators of mine & also with the the build-in BBs!? Never experienced this! Can anybody confirm...


I dont't understand the above!!! Can somebody help me see clearer - BIG THANKS IN ADVANCE!

Lupo

Alain Verleyen
Moderator
30635
Alain Verleyen 2014.12.17 12:01  
lupo.busca:

Hi angavoygeur or anybody else who can help me!!!

I thought I got it, but there are new questions... ;-)


When I put in the EA just a 

Print("Supertrend(1): ",Supertrend[1]);


he gives me values like

but in debugging I can see that Supertrend[1] gives correct values. And also if i print directly from the indicator in tester the values he shows the correct values, e.g.:

And the EA is working after the changes provided by angevoyageur!??


I had written another custom indicator to see if I can catch it by my own. Just a

Middle=((high[i]+low[i])/2)

When I call him plain from an EA, print the values to the journal I got crap like above - when I print it from the indicator directly the values are ok...


And last question - for now! ;-) - , which I also don't get:

when I test ANY indicator from 2014-12-01 until  2014-12-16 on e.g. EURUSD oer also USDJPY he just test until the 2014-12-08!!?? I sdid it with the supertrend, with other custom indicators of mine & also with the the build-in BBs!? Never experienced this! Can anybody confirm...


I dont't understand the above!!! Can somebody help me see clearer - BIG THANKS IN ADVANCE!

Lupo

Please show your last EA code, at least the part where you get the Supertrend values.
lupo.busca
1033
lupo.busca 2014.12.17 12:40  

Hi!

THANKS! After reviewing my code I have found the error...damn (incorrect) templates of mine! ;-)

Now I got  the right values in the journal...


...but still I am not able to test indicators from beginning december 'til now?

That is nothing what is an actual problem for me, but I didn't understand it!

So maybe you can enlight me with this?

Lupo


EDIT:

After testing an EA I found the same: the backtest stops...


13:01:36.006    Trade    2014.12.08 23:59:59   position closed due end of test at 1.23185 [sell 0.10 EURUSD 1.23106]

/
To add comments, please log in or register