EA with nested Indicators

MQL5 Indicadores Experts

Trabalho concluído

Tempo de execução 19 horas
Comentário do cliente
I was really happy with the result I got from Nguyen Nga. He is highly recommended 10/10 points to him!
Comentário do desenvolvedor
Nice customer, Thank you.

Termos de Referência

MetaTrader 5, Version: 5.00 build 1375, 15 Jul 2016

Hello, I have one Expert Advisor (EA) which loads 2 indicators. Indicator 1 is a moving average (IND_MA / top indicator) and Indicator 2 is a custom indicator (IND_CUSTOM / bottom indicator) which reads the information from the moving average indicator on every tick and output the values of IND_MA rounded to the third digit after the floating point, producing what you can see on the following image:

The EA needs the IND_CUSTOM for it's own functionality. So that's a requirement for it. It outputs the following on the Toolbox / Experts window:


My problem is that the EA works OK on the terminal but on the Strategy Tester (ST) the IND_CUSTOM doesn't get any value. as you can see on the following image:

I need the IND_CUSTOM gets the values on the ST, so I can do backtesting.

Below you have the code of the IND_CUSTOM and the EA. Please, try it on the terminal first to see how it works, then try it on the ST.

// File: ProblemIndicator.mq5

#property indicator_separate_window
#property indicator_buffers                             1
#property indicator_plots                               1
#property indicator_type1                               DRAW_LINE
#property indicator_color1                              clrBlue
#property indicator_style1                              STYLE_SOLID
#property indicator_width1                              1

input int handle_base;                                  // Handle of the base indicator
input int handle_base_buffer;                   // Buffer index of the base indicator

double buffer[];
double data_base[];

int OnInit() {

        be_aware_of_indicators_available();     // needed here at the beginning

        if (!is_valid_indicator_handle(handle_base)) {
                printf("The handle of the base indicator: %d, is invalid", handle_base);
                return -1;
        }

        ArraySetAsSeries(buffer, true);
        ArraySetAsSeries(data_base, true);

        IndicatorSetInteger(INDICATOR_DIGITS, _Digits + 1);

        PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, 0);
        SetIndexBuffer(0, buffer, INDICATOR_DATA);

        return 0;
}

int OnCalculate(const int rates_total,          // number of bars in history at the current tick
                                const int prev_calculated,      // number of bars calculated at previous call
                                const int begin, const double &price[]
        ) {
        int count = rates_total - prev_calculated;
        CopyBuffer(handle_base, handle_base_buffer, 0, count, data_base);

        for (int i = count - 1; i >= 0; i--)
                buffer[i] = MathRoundDecimals(data_base[i], 3);

        return rates_total;
}

void get_chart_indicators_handle(int &handles[]) {
        ArrayResize(handles, 0);
        int total = (int) ChartGetInteger(0, CHART_WINDOWS_TOTAL);
        for (int w = 0; w < total; w++) {
                for (int i = 0; i < ChartIndicatorsTotal(0, w); i++) {
                        string name = ChartIndicatorName(0, w, i);
                        ArrayResize(handles, ArraySize(handles) + 1);
                        handles[ArraySize(handles) - 1] = ChartIndicatorGet(0, w, name);
                }
        }
}

void be_aware_of_indicators_available() {
        int handles[];
        get_chart_indicators_handle(handles);
}

bool is_valid_indicator_handle(int handle) {
        ENUM_INDICATOR type;
        MqlParam parameters[];
        int result = IndicatorParameters(handle, type, parameters);
        if (MQL_TESTER && GetLastError() == ERR_FUNCTION_NOT_ALLOWED) // on ST "IndicatorParameters" is not allowed
                return true;
        else
                return (result != -1);
}

double MathRoundDecimals(double num, int decimals) {
        return MathRound(num * MathPow(10, decimals)) / MathPow(10, decimals);
}
// File: ProblemEA.mq5

int handle_1, handle_2;

int OnInit() {

        ChartSetInteger(0, CHART_SCALE, 3);
        ChartSetInteger(0, CHART_MODE, CHART_CANDLES);

        int i = 0;

        MqlParam params_1[4];
        params_1[0].type = TYPE_INT;
        params_1[0].integer_value = 20;
        params_1[1].type = TYPE_INT;
        params_1[1].integer_value = 0;
        params_1[2].type = TYPE_INT;
        params_1[2].integer_value = MODE_SMA;
        params_1[3].type = TYPE_INT;
        params_1[3].integer_value = PRICE_CLOSE;
        handle_1 = IndicatorCreate(_Symbol, PERIOD_CURRENT, IND_MA, ArraySize(params_1), params_1);
        ChartIndicatorAdd(0, i, handle_1);

        MqlParam params_2[3];
        params_2[0].type = TYPE_STRING;
        params_2[0].string_value = "ProblemIndicator";
        params_2[1].type = TYPE_INT;
        params_2[1].integer_value = handle_1;
        params_2[2].type = TYPE_INT;
        params_2[2].integer_value = 0; // buffer index to use
        handle_2 = IndicatorCreate(_Symbol, PERIOD_CURRENT, IND_CUSTOM, ArraySize(params_2), params_2);
        ChartIndicatorAdd(0, ++i, handle_2);

        return (INIT_SUCCEEDED);
}

void OnTick() {
        double last_1 = get_last_indicator_value(handle_1);
        double last_2 = get_last_indicator_value(handle_2);
        printf("values: %f %f", last_1, last_2);
}

double get_last_indicator_value(int handle) { // just first buffer
        double values[1];
        int result = CopyBuffer(handle, 0, TimeCurrent(), 1, values);
        return values[0];
}

Any question, please let me know.

Regards, Cyberglassed.


Respondido

1
Desenvolvedor 1
Classificação
(253)
Projetos
358
49%
Arbitragem
24
25% / 50%
Expirado
80
22%
Livre
2
Desenvolvedor 2
Classificação
(28)
Projetos
36
17%
Arbitragem
5
20% / 40%
Expirado
17
47%
Livre
3
Desenvolvedor 3
Classificação
(1)
Projetos
1
0%
Arbitragem
1
0% / 100%
Expirado
0
Livre
Pedidos semelhantes
I have the mq5 file, I need a buffer adding to the indicator, so it appears in the data window so I can reference it later in an EA. As the below screenshot shows, there is a median ray line from yesterday (the dashed horizontal line) - I want this value in the data window called Median Ray. I want this to be a single value per day, so todays Median Ray would be 17868, and so on each day. So I want all the Developing
I would like to develop my own indicator on metatrader 4 and tradingview. We would start with a basic version that we would improve later. It is an indicator based on several analyses and which would provide several indications. I am looking for someone who can develop on MT4 and Mt5, initially I would like to do it on mt4 and then on mt5. If you have expertise in pinescript it is a plus because I would like to
I urgently require swift assistance to convert a complex indicator into a fully functional scanner, capable of automatically sending real-time data, alerts, and notifications via email, ensuring seamless integration and prompt delivery of critical information to facilitate informed decision-making and timely action
I need to improve the code of an indicator that is too heavy and slow when running and when used with iCustom in an EA. No other changes to the indicator are requested: the original features of the indicator should remain as theay are. I'll provide the indicator after job acceptance. I request final source code mq5 file. Thank you Regards
I have a mt5 indicator that is working perfectly but I will like to make it an expert advisor to have an automated trade. I will be glad if I can get a well experienced developer to execute this project. Thanks
O TRABALHO CONSISTE NA MUDANÇA DO HISTOGRAMA DO INDICADOR TREDN DIRECTION AND FORCE DSEMA SMOOTHED PARA O HISTOGRAMA DA FOTO ANEXA, OBEDECENDO AS TRES CORES VERDE (UP, VERMELHOR(DOWN) E CINZA(TREND). O MESMO TEM QUE ODECER O MESMO CALCULO E COLORIR DA MESMA FORMA POREM COM HISTOGRAMA DDE FORMATO DIFERENTE
If you are knowledgeable in hedging strategy we can chat. I created my simple EA using Fxdreema , so you only need to modify it for me. There are two parts of the EA , 1. Is the execution strategy 2. Is the money management strategy (hedging). I already created number 1 which is the execution of trades , I only need someone who can implement hedging in every orders the EA create. Additional Parameters needed. Trade
We are interested in a TradingView indicator that reads candlestick pattern shapes and shows the location of entry and exit points on a candlestick chart. What services do you provide related to this
Hello Im looking for professional trading developer who htf ready made trading with best and working strategy with low risk level with average of 30 to 60 percent profit margin, broker is not problem, any broker is welcomed and any trading pairs are welcomed as well
the sl doesnt work i want the tp logic to remain i need the trend direction fucntion tow ork i the trend is up then only buys if down only sells i need the fibo nacci fucntion to work as well and the flat zone function to work as well and i need the code to trade 1% of the balance //+------------------------------------------------------------------+ //| US500_EA.mq4 | //|

Informações sobre o projeto

Orçamento
15 - 100 USD
Desenvolvedor
13.5 - 90 USD
Prazo
de 1 para 5 dias