Drawing lines from an EA

 

Is it possible to draw something like a Moving Average line from an Expert Advisor like you can and Indicator? Or do I need to make an Indicator that uses the same logic as the EA so I can have a visual of what is going on? Is there a good way of linking the two so for example the Indicator and the EA would draw from the same Global Variable? Thanks in advance for your help.

 

The usual and most straight forward way is to code an indicator for calculating and drawing the lines then use iCustom() in the EA to get the values from the indicator.

 
SDC:

The usual and most straight forward way is to code an indicator for calculating and drawing the lines then use iCustom() in the EA to get the values from the indicator.


Thanks for your direction. I found a good explanation of iCustom at, https://book.mql4.com/samples/shared.
 
  1. MisterDog:
    Is it possible to draw something like a Moving Average line from an Expert Advisor like you can and Indicator?
    My Polyline code does exactly that. It's easier to make CIs, but if you need to verify iCustom data in the EA or the values are generated in the EA, then PL works reasonable. I even use it to plot how it trailed the SL which can't be done in a CI.

  2. MisterDog:
    Thanks for your direction. I found a good explanation of iCustom at, https://book.mql4.com/samples/shared
    See also Detailed explanation of iCustom - MQL4 forum



 

I give up! What’s my trouble here with iCustom? My iCustom should return the price of some envelope bands but it does not. It returns the value, 2147483647.

I have read the Book and forum discussions on iCustom.

Here is what I have in the Indicator:

Indicator name:

“Pentaria-Ind-v1”

All external properties:

extern int MAPeriod = 20;

extern int SlopePeriod = 10;

extern double EnvSpread = 0.0005;

extern double BandPush = 3.5;

Indicator defined buffers:

SetIndexBuffer(0,MABuffer);

SetIndexBuffer(1,EnvTopBuffer);

SetIndexBuffer(2,EnvBotBuffer);

And a bit of code from the Indicator Start function:

TopBuf = (EnvSpread+(Delta*BandPush))+iMA(NULL,0,MAPeriod,0,MODE_SMMA,PRICE_MEDIAN,i);

BotBuf = (-EnvSpread+(Delta*BandPush))+iMA(NULL,0,MAPeriod,0,MODE_SMMA,PRICE_MEDIAN,i);

EnvTopBuffer[i] = TopBuf;

EnvBotBuffer[i] = BotBuf;

Alert ("Ind: High-",High[1]," EnvTopBuffer-",TopBuf," | Low-",Low[1]," EnvBotBuffer-",BotBuf);

Everything works fine with the indicator. It draws envelope bands and the values of the Alert are reasonable.

Here is what I am doing in the EA:

The relevant external EA properties are identical:

extern int MAPeriod = 20;

extern int SlopePeriod = 10;

extern double EnvSpread = 0.0005;

extern double BandPush = 3.5;

Here is the relevant code from the EA Start function:

double EnvTopB = iCustom(NULL,0,"Pentaria-Ind-v1", MAPeriod, SlopePeriod, EnvSpread, BandPush, 1, 0);

double EnvBotB = iCustom(NULL, 0, "Pentaria-Ind-v1", MAPeriod, SlopePeriod, EnvSpread, BandPush, 2, 0);

Alert (MAPeriod," - ",SlopePeriod," - ",EnvSpread," - ",BandPush);

Alert ("High-",High[1]," EnvTopB-",EnvTopB," | Low-",Low[1]," EnvBotB-",EnvBotB);

The first Alert returns reasonable values but in the second Alert, EnvTopB and EnvBotB both return the value, 2147483647. I am expecting a reasonable price from these variables.

I noticed in several examples that #define was used. I think this is optional.

Is there something obvious here?

--Thanks

 
MisterDog:

The first Alert returns reasonable values but in the second Alert, EnvTopB and EnvBotB both return the value, 2147483647.

--Thanks

That means that the value for that buffer for that candle is EMPTY . . . my guess is that the buffer in question is not drawing a line but arrows/dots/squares or some such "ARROW" . . .
 
MisterDog:

I give up! What’s my trouble here with iCustom? My iCustom should return the price of some envelope bands but it does not. It returns the value, 2147483647.

I have read the Book and forum discussions on iCustom.

Here is what I have in the Indicator:

Indicator name:

“Pentaria-Ind-v1”

All external properties:

extern int MAPeriod = 20;

extern int SlopePeriod = 10;

extern double EnvSpread = 0.0005;

extern double BandPush = 3.5;

Indicator defined buffers:

SetIndexBuffer(0,MABuffer);

SetIndexBuffer(1,EnvTopBuffer);

SetIndexBuffer(2,EnvBotBuffer);

And a bit of code from the Indicator Start function:

TopBuf = (EnvSpread+(Delta*BandPush))+iMA(NULL,0,MAPeriod,0,MODE_SMMA,PRICE_MEDIAN,i);

BotBuf = (-EnvSpread+(Delta*BandPush))+iMA(NULL,0,MAPeriod,0,MODE_SMMA,PRICE_MEDIAN,i);

EnvTopBuffer[i] = TopBuf;

EnvBotBuffer[i] = BotBuf;

Alert ("Ind: High-",High[1]," EnvTopBuffer-",TopBuf," | Low-",Low[1]," EnvBotBuffer-",BotBuf);

Everything works fine with the indicator. It draws envelope bands and the values of the Alert are reasonable.

Here is what I am doing in the EA:

The relevant external EA properties are identical:

extern int MAPeriod = 20;

extern int SlopePeriod = 10;

extern double EnvSpread = 0.0005;

extern double BandPush = 3.5;

Here is the relevant code from the EA Start function:

double EnvTopB = iCustom(NULL,0,"Pentaria-Ind-v1", MAPeriod, SlopePeriod, EnvSpread, BandPush, 1, 0);

double EnvBotB = iCustom(NULL, 0, "Pentaria-Ind-v1", MAPeriod, SlopePeriod, EnvSpread, BandPush, 2, 0);

Alert (MAPeriod," - ",SlopePeriod," - ",EnvSpread," - ",BandPush);

Alert ("High-",High[1]," EnvTopB-",EnvTopB," | Low-",Low[1]," EnvBotB-",EnvBotB);

The first Alert returns reasonable values but in the second Alert, EnvTopB and EnvBotB both return the value, 2147483647. I am expecting a reasonable price from these variables.

I noticed in several examples that #define was used. I think this is optional.

Is there something obvious here?

--Thanks

Don't give up that easie. The day you born wasn't the day you walked. you had to learn that also..

2147483647 is same as EMPTY_VALUE the buffer has at bar 0 still this value

To know how iCustom works with your indicator you can make a helpEA or helpIndicator to check what is inside the buffers of the indicator

This way you learn the most about checking commands in MT4. Read here https://www.mql5.com/en/forum/138379

make something like that and you will learn how to use it..... in the EA's you wanna make

 
MisterDog:
I give up! What’s my trouble here with iCustom? My iCustom should return the price of some envelope bands but it does not. It returns the value, 2147483647.
I have read the Book and forum discussions on iCustom.
Here is what I have in the Indicator:

  1. Detailed explanation of iCustom - MQL4 forum
  2. deVries:
    2147483647 is same as empty value the buffer has at bar 0 still empty value
    2147483647 is the value EMPTY_VALUE not EMPTY. They are different
  3. If you were getting zero, I'd suggest that the iCustom was failing and ask what GetLastError() returned. But since you are getting EMPTY_VALUE I think the iCustom is working. The indicator doesn't update bar zero. Add the indicator to a chart, open the data window, mouse to bar zero and look at the data window to confirm.
 
Are you sure you set the correct buffers in iCustom() ? I see you called buffers 1 and 2. Like WHR said already, check the data window to make sure which buffers the indicator uses
 
Thanks for the help. The trouble is in the indicator. There is something wrong with my envelope buffers. When I replace the custom made envelopes with an ordinary moving average the iCustom works fine. I will go back and learn more about the buffers and fix the indicator. All your advice was really helpful.