Add Custom Indicator to Expert Advisor

 

How can I add a custom indicator to an expert advisor and use the custom indicator for signals?

I have already read the following articles https://www.mql5.com/en/articles/1457 and https://www.mql5.com/en/articles/1456. My mind is a blank :) It seems that whoever wrote that, did a fine job of spending time on the articles, but it is WAY over my head. Why can't it be more simple? WOW! Ok, for those of you who are not at the point where you can successfully pop a custom indicator in an expert advisor, here is the solution... As an example, if you wanted to put the custom indicator Heiken Ashi in an expert advisor, you would simply write (or copy and paste) "double HeikenAshi1 = iCustom(NULL,0,"Heiken Ashi",Red,White,2,3);" and place that sh*t under "int start()" and the first "{" directly bellow.

example: // Yes, its that easy! I didn't need to write two articles on how to write a simple code! :) Cheers! Cheers! Clap! Clap! :) :)

int start()

{

double HeikenAshi1 = iCustom(NULL,0,"Heiken Ashi",Red,White,2,3);

}


Since I am using Heiken Ashi as an example, I will stick with that as the custom indicator I will be using for the EA to place a trade. (Trades are based on Heiken Ashi.) Are we clear? (yes)

Ok, here is where the poop hits the fan! I didn't know what to do next... SO, I simply copied and pasted the indicator code to the expert advisor template, EXACTLY where it used to be in the custom indicator (Heiken Ashi).

I clicked the Compile button... 0 error(s), 0 warning(s). :)

(read carefully. Here is where sh*t gets tricky!)

I copied the code "if (haOpen<haClose)" and used that for an OrderSend parameter... So, for example..

// below is the example :)

if (haOpen<haClose){ // basically my ordersend parameter :)

{

OrderSend(Symbol(),OP_SELL,1,Bid,30,Bid+500*Point,Bid-500*Point,"My order #WTF",54321,0,Red); // basically a sell order function... blah, blah.

}}


Ok. That was quite allot, but I am almost at the finish line of this post! Take a deep breath!

Here is the WONDERFUL (sarcasm) announcement I receive from the "journal",

"EA name blah blah, EURUSD H1: (here it is!) SetIndexBuffer function must be called from custom indicator only (wtf!)

I KNOW there are many traders out here that are stuck at the same spot as myself. So I will continue on our behalf. I am aware that Expert Advisors cannot use buffers (possibly right). When it all boils down, here is the QUESTION: "How can I use a custom indicator as an order signal to place orders?"

I need to create MT6 :) Vote for RunnerUp^bitch3s^ :)

Thank you, pips of blessings uppon you all!

 
WhooDoo22:

How can I add a custom indicator to an expert advisor and use the custom indicator for signals?


int start()

{

double HeikenAshi1 = iCustom(NULL,0,"Heiken Ashi",Red,White,2,3);

}


SO, I simply copied and pasted the indicator code to the expert advisor template, EXACTLY where it used to be in the custom indicator (Heiken Ashi).

I clicked the Compile button... 0 error(s), 0 warning(s). :)

(read carefully. Here is where sh*t gets tricky!)

I copied the code "if (haOpen<haClose)" and used that for an OrderSend parameter... So, for example..

// below is the example :)

if (haOpen<haClose){ // basically my ordersend parameter :)

{

OrderSend(Symbol(),OP_SELL,1,Bid,30,Bid+500*Point,Bid-500*Point,"My order #WTF",54321,0,Red); // basically a sell order function... blah, blah.

}}


"EA name blah blah, EURUSD H1: (here it is!) SetIndexBuffer function must be called from custom indicator only (wtf!)


So, you were doing fine until you pasted fully working indicator code into an EA. Just let the indicator do its thing and map all of its outputs into your EA using the iCustom function. That gives you the data for your tests. I can't seem to find that indicator on my system right now :-(

 
dabbler:

So, you were doing fine until you pasted fully working indicator code into an EA. Just let the indicator do its thing and map all of its outputs into your EA using the iCustom function. That gives you the data for your tests. I can't seem to find that indicator on my system right now :-(



Here comes santa clause :)


Thanks for your post!

Files:
 

What the f*ck? (Laughing at my ignorance) Map all of its outputs using the iCsutom function. I understand that you are saying that this gives me the data I need for my test. (don't really understand but who cares.) This is bigger than me. Many people don't understand this, so this is for all of us I suppose. Can you give me an example of how I could use the iCustom function to place an order? (using the format in the example bellow)

Example:

if (haOpen<haClose){ // Would I be using the iCustom function here?

{

OrderSend(Symbol(),OP_SELL,1,Bid,30,Bid+500*Point,Bid-500*Point,"My order #WTF",54321,0,Red);

}}


Thank you

 
WhooDoo22:

Here comes santa clause :)


Thanks for your post!


If this is not the "Heiken Ashi" indicator please comment for me to upload the correct file "Heiken Ashi" indicator or upload the indicator yourself, if you wish.


Thank you

 

See these lines

   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexBuffer(3,ExtMapBuffer4);

These are the names of the lines on the chart.

Then they are filled

      haOpen=(ExtMapBuffer3[pos+1]+ExtMapBuffer4[pos+1])/2;
      haClose=(Open[pos]+High[pos]+Low[pos]+Close[pos])/4;
      haHigh=MathMax(High[pos], MathMax(haOpen, haClose));
      haLow=MathMin(Low[pos], MathMin(haOpen, haClose));
      if (haOpen<haClose) 
        {
         ExtMapBuffer1[pos]=haLow;
         ExtMapBuffer2[pos]=haHigh;
        } 
      else
        {
         ExtMapBuffer1[pos]=haHigh;
         ExtMapBuffer2[pos]=haLow;
        } 
      ExtMapBuffer3[pos]=haOpen;
      ExtMapBuffer4[pos]=haClose;

so for the last closed bar ExtMapBuffer3[1] will be haOpen.

That is the data you want, buffers 3 and 4 (which because of a bit of inconsistency will actually be indexed as 2 and 3.

In the iCustom function https://docs.mql4.com/indicators/icustom

you need to set the mode to the index buffer you want

haOpen = iCustom(NULL,0,"HeikenwAshi",Red,White,Red,White,2,1);
haClose = iCustom(NULL,0,"HeikenwAshi",Red,White,Red,White,3,1);

The name of the indicator has to exactly match the name of the mq4/ex4 indicator or it won't work.

 

Thank you,

I am hanging on for dear life here :) lol.

Yes, I see the lines of code. (I believe that those four lines of code are referring to the colors Red and White which are used in Heiken Ashi. The "color lines" are representig Open,Close,High, and Lows.) Is this true? Obviously I am generalizing this.

So, those 4 lines of code in the first box are the Names of the Lines on the Chart. Understood.

I don't understand how they are filled...

I believe I understand the format of the code, but I do not understand how I can use this to place a signal for an order. I am willing to learn and I enjoy the learning experience. I must stay on track to get the solution though. The faster i can get the solution, the faster other traders can solve this problem.

Could you give me an example of how I can use the iCustom() function to place a signal for a trade please? Using the example below-

Example:

if (haOpen<haClose){ // will i be using the iCustom() function here?

{

OrderSend(Symbol(),OP_SELL,1,Bid,30,Bid+500*Point,Bid-500*Point,"My order #WTF",54321,0,Red);

}}


Thank you

 
WhooDoo22:

I KNOW there are many traders out here that are stuck at the same spot as myself.

No, they probably read the Documentation and some of the Book first
 

Thank you for your post RaptorUK. I know we have had our discrepancies in the past, but time is too short for me to hold a grudge against you. I wish for peace. I hope you and I can create instead of destroy. This is my wish.

Thank you

 
dabbler:

See these lines

These are the names of the lines on the chart.

Then they are filled

so for the last closed bar ExtMapBuffer3[1] will be haOpen.

That is the data you want, buffers 3 and 4 (which because of a bit of inconsistency will actually be indexed as 2 and 3.

In the iCustom function https://docs.mql4.com/indicators/icustom

you need to set the mode to the index buffer you want

The name of the indicator has to exactly match the name of the mq4/ex4 indicator or it won't work.


Ok, this is what I am thinking folks...

// is this format correct according to you dabbler?

int start()

{

haOpen = iCustom(NULL,0,"HeikenwAshi",Red,White,Red,White,2,1);

haClose = iCustom(NULL,0,"HeikenwAshi",Red,White,Red,White,3,1);


if (haOpen[2] > haClose[1]) {

{

OrderSend(Symbol(),OP_SELL,1,Bid,30,Bid+500*Point,Bid-500*Point,"My order #WTF",54321,0,Red);

}}





 
WhooDoo22:

Ok, this is what I am thinking folks...

// is this format correct according to you dabbler?

int start()

{

double haOpen = iCustom(NULL,0,"HeikenwAshi",Red,White,Red,White,2,1);

double haClose = iCustom(NULL,0,"HeikenwAshi",Red,White,Red,White,3,1);


if (haOpen[2] > haClose[1]) {

{

OrderSend(Symbol(),OP_SELL,1,Bid,30,Bid+500*Point,Bid-500*Point,"My order #WTF",54321,0,Red);

}}





Reason: