EA with nested Indicators

MQL5 指标 专家

工作已完成

执行时间19 小时
客户反馈
I was really happy with the result I got from Nguyen Nga. He is highly recommended 10/10 points to him!
员工反馈
Nice customer, Thank you.

指定

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.


反馈

1
开发者 1
等级
(253)
项目
358
49%
仲裁
24
25% / 50%
逾期
80
22%
空闲
2
开发者 2
等级
(28)
项目
36
17%
仲裁
5
20% / 40%
逾期
17
47%
空闲
3
开发者 3
等级
(1)
项目
1
0%
仲裁
1
0% / 100%
逾期
0
空闲
相似订单
Hello, I purchased a TradingView script that works very well, but it doesn’t have any alerts. All I need are alerts programmed so I don’t have to sit behind the chart watching it all the time
Hi! Are you able to code an exact copy of an indicator for trading view? It must be exactly the same. if you are expert in doing this I am expecting your message in the comment session to share you with the indicator I want to duplicate. Looking forward to your positive response and the opportunity to collaborate with you on this project
Hello developers I hope this message finds you well. I am currently seeking a highly skilled developer for an important project. I need an exact copy of a TradingView indicator to be coded for the MetaTrader 4/5 platform. The indicator must be replicated with absolute precision, maintaining all its functionalities and features. Would you be able to take on this project? If so, I would appreciate discussing the
Hello Developers, I am looking for a highly skilled and experienced developer to code an exact copy of a specific indicator for TradingView. The indicator must be replicated with precise accuracy, maintaining all functionalities and features of the original. Requirements: Proficiency in Pine Script and experience with TradingView indicators. Demonstrated ability to replicate complex indicators with exact
MODIFICATION OF AND EXISTING EXPERT BY ADDING INDICATORS TO FUNCTION AS FILTERS, TRADE CLOSURE BY THE REVERSAL OF THE adx INDICATOR, LOOKING FOR TRADE BASED ON THE COLOR OF THE PERCENTAGE CHANGE INDICATOR (DPC) SELLING THE COLR IS RED AND DECREASING IN PERCENTAGE AND BUYING WHEN THE COLOR IS GREEN AND INCREASING IN PERCENTAGE . There is an EA I have been using which I splitted into long trading and short trading. It
I'm looking for very simple scanner dashboard based on Zigzag and I'm going to share more details to the right candidate. I want show some kinds of Signal when pattern match and when click from Dashboard it's opened new tab with chart and show that pattern. It should be use custom timeframe, Scan custom pair as well scan from Market Watch. Dashboard must be Responsive or adjust with any screen. It's based on Very
Looking for someone who can convert 130 Lines of Pinescript code to MT4/5 And I want extra input for scanning from Marketwatch and Custom Pairs. More details for the right candidate. And if you are high demand freelancer, please don't apply to this project. We're looking for someone who are individual and keep working with us. Thank you
i am looking for experienced programmer to create indicator for me. i am willing to pay for the service. and if it works amazingly like i expected. i will tip more money
I recently bought an indicator, that sends out notifications for trades i need to place, on the notification these and SL and TP, so i want an EA that would automate that for me
SMART MONEY 30 - 49 USD
--- Job Title: EA Programmer for Smart Money Concept (Urgent) Job Description: We are seeking an experienced EA programmer to finalize a project focused on implementing the Smart Money Concept. The progress is at 80%, and we need someone to complete the remaining tasks within a week. Project Requirements: - Liquidity, CHoCh, and Return to OrderBlock: Implement these key components effectively into the Expert Advisor

项目信息

预算
15 - 100 USD
开发人员
13.5 - 90 USD
截止日期
 1  5 天