Use Supertrend in MQL4, EA

 

Hi everyone,

I want to use supertrend in expert advisor, but I can't understand how should I implement it.

I've downloaded supertrend indicator from earnforex, and then I use iCustom but I didn't understand how it work.

when I use indicator for a chart, it works perfectly but I can't get the information and values in EA.

How can I send Buy and Sell order in EA ?


int OnInit()
{
    return (0);
}

int period = 10;
double multiplier = 3.0;

void OnTick()
{

    double uptrend = iCustom(Symbol(), 0, "SPIndicator", period, multiplier, 0, 0);
    double downtrend = iCustom(Symbol(), 0, "SPIndicator", period, multiplier, 1, 0);

     if(???)
      {
         Print("Buy");
     }

     if( ??? ) {

           Print("Sell");

      }
}
 
Learn coding or hire a freelancer
 
amando #:
Learn coding or hire a freelancer

I know how to put condition but I don't know exactly about mql4 and using iCustom.

It works and it makes a draw on the chart. but there is some number is output of indicator that I don't know how can I manage them to find out if trend has changed.

 
Aref Rafei #:

I know how to put condition but I don't know exactly about mql4 and using iCustom.

It works and it makes a draw on the chart. but there is some number is output of indicator that I don't know how can I manage them to find out if trend has changed.

First, start with printing these values …
Uptrend DownTrend… to see if is any good how you have got them… then  if( UpTrend > DownTrend ) Buy… but I would say, start first to understand how to write …start with a script … print results … after that understand how these functions work inside of EA…there are plenty materials on YouTube from where you can start to  learn …
Free as well … 
 

The iCustom function allows you to get the values of the indicator lines that are displayed on the charts when you are adding this indicator on the chart. But remember that iCustom function won’t draw this indicator on your chart automatically – all calculations are made within the code of the function. So, if you expect that this function will show you any lines on the chart – it’s not the result here.

Instead, you get those values (uptrend and downtrend) – so those are values of the super trend indicator lines. If the uptrend value is zero (or empty value) – that means that this trend is not active at this moment. And the same for down trend. So it might be a condition that if (uptrend!=0) Print(“buy”); - but this will be on every candle with uptrend line.You might add some other conditions for example to find the moment of changing the trend or something like that.

Reason: