SadRe: Metatrader 5 Versions of indicators.

421
I've been trying to learn to code and ChatGPT has become more Dr. Jekyl and Mr. Hyde. I've asked it to generate renko indicator after renko indicator for mt5 and it has stopped updating the corresponding code and has told me that I am better off finding a developer.... So I am back on the forum to air my grievances and seek assistance. I asked to generate a PHD expert level .mq5 code for a renko indicator that tracks the basic elements available in every renko brick. I then asked for an indication of trending and range bound market states. I know my logic is sound for trading and people and i think i have come to a logical place where people have decided to keep certain things to themselves. This should all be comforting but I am really trying to develop the renko indicator without knowing how to code. the mt5 programming language seems much more complicated and functional than the mt4 language. I say that because ChatGPT says so :-D I have been to websites advertising similar functions as ChatGPT for coding but they seem like less attractive ideas the longer I work with ChatGPT. For those seasoned Chatters, yes, i used prompts and string type prompts into a dead end. I've opened new chats and started from scratch. I've asked to be taught to code which was also ineffective. The repetitive answers were reminiscent of high school curfew conversations. I don't think it's necessary to go into details on everything but if all the information is there the code could be generated and I could go back to self-aggrandizement. High school is rich with circumstance. Here is what I managed to get from my repeated attempts to persuade ChatGPT to let me stay out late and party.

Code: Select all

//+------------------------------------------------------------------+
//|                                              CustomRenko.mq5     |
//|                  Copyright 2023, Your Name                       |
//|                                            https://www.example.com|
//+------------------------------------------------------------------+
#property copyright "2023, Your Name"
#property link      "https://www.example.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
Plot(0, "Brick Size", clrGray);
Plot(1, "Total Trades", clrRed);
Plot(2, "Buy Trades", clrOrange);
Plot(3, "Sell Trades", clrYellow);
Plot(4, "Total Volume", clrGreen);
Plot(5, "Buy Volume", clrBlue);
Plot(6, "Sell Volume", clrViolet);
Plot(7, "Time Per Brick", clrLightBlue);

// Indicator input parameters
input double BrickSize = 10.0;  // Brick size multiplier based on spread

// Global variables
double BufferBrickSize[];
double BufferTotalTrades[];
double BufferBuyTrades[];
double BufferSellTrades[];
double BufferTotalVolume[];
double BufferBuyVolume[];
double BufferSellVolume[];
double BufferTimePerBrick[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
    // Set the indicator buffers
    SetIndexBuffer(0, BufferBrickSize, INDICATOR_CALCULATIONS);
    SetIndexBuffer(1, BufferTotalTrades, INDICATOR_CALCULATIONS);
    SetIndexBuffer(2, BufferBuyTrades, INDICATOR_CALCULATIONS);
    SetIndexBuffer(3, BufferSellTrades, INDICATOR_CALCULATIONS);
    SetIndexBuffer(4, BufferTotalVolume, INDICATOR_CALCULATIONS);
    SetIndexBuffer(5, BufferBuyVolume, INDICATOR_CALCULATIONS);
    SetIndexBuffer(6, BufferSellVolume, INDICATOR_CALCULATIONS);
    SetIndexBuffer(7, BufferTimePerBrick, INDICATOR_CALCULATIONS);

    // Set the indicator labels
    PlotIndexSetString(0, PLOT_LABEL, "Brick Size");
    PlotIndexSetString(1, PLOT_LABEL, "Total Trades");
    PlotIndexSetString(2, PLOT_LABEL, "Buy Trades");
    PlotIndexSetString(3, PLOT_LABEL, "Sell Trades");
    PlotIndexSetString(4, PLOT_LABEL, "Total Volume");
    PlotIndexSetString(5, PLOT_LABEL, "Buy Volume");
    PlotIndexSetString(6, PLOT_LABEL, "Sell Volume");
    PlotIndexSetString(7, PLOT_LABEL, "Time Per Brick");

    // Set the indicator styles
    SetIndexStyle(0, DRAW_LINE);
    SetIndexStyle(1, DRAW_LINE);
    SetIndexStyle(2, DRAW_LINE);
    SetIndexStyle(3, DRAW_LINE);
    SetIndexStyle(4, DRAW_LINE);
    SetIndexStyle(5, DRAW_LINE);
    SetIndexStyle(6, DRAW_LINE);
    SetIndexStyle(7, DRAW_LINE);

    return INIT_SUCCEEDED;
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
    int limit = rates_total - prev_calculated;

    // Loop through the price data to determine when to generate new Renko bricks
    for (int i = rates_total - 1; i >= limit; i--)
    {
        // Calculate the brick size based on the spread and the BrickSize multiplier
        double brickSize = spread[i] * BrickSize;

        // Calculate the number of bricks based on price change and brick size
        int brickCount = MathAbs(close[i] - close[i + 1]) / brickSize;

        // Generate new Renko bricks
        for (int j = 0; j < brickCount; j++)
        {
            // Set the values for each Renko brick
            int brickIndex = i + j;
            BufferBrickSize[brickIndex] = brickSize;
            BufferTotalTrades[brickIndex] = CalculateTotalTrades(brickIndex);
            BufferBuyTrades[brickIndex] = CalculateBuyTrades(brickIndex);
            BufferSellTrades[brickIndex] = CalculateSellTrades(brickIndex);
            BufferTotalVolume[brickIndex] = CalculateTotalVolume(brickIndex);
            BufferBuyVolume[brickIndex] = CalculateBuyVolume(brickIndex);
            BufferSellVolume[brickIndex] = CalculateSellVolume(brickIndex);
            BufferTimePerBrick[brickIndex] = CalculateTimePerBrick(brickIndex);
        }
    }

    return rates_total;
}

// Function to calculate the total trades for a Renko brick
int CalculateTotalTrades(int index)
{
    int totalTrades = 0;

    // Define the range of trades for the current brick
    int startTradeIndex = bufferStart[index];
    int endTradeIndex = bufferStart[index + 1];

    // Count the number of trades within the range
    for (int i = startTradeIndex; i < endTradeIndex; i++)
    {
        // Check the direction of the trade (buy or sell)
        if (bufferTradeType[i] == TRADE_TYPE_BUY || bufferTradeType[i] == TRADE_TYPE_SELL)
        {
            totalTrades++;
        }
    }

    return totalTrades;
}

// Function to calculate the buy trades for a Renko brick
int CalculateBuyTrades(int index)
{
    int buyTrades = 0;

    // Define the range of trades for the current brick
    int startTradeIndex = bufferStart[index];
    int endTradeIndex = bufferStart[index + 1];

    // Count the number of buy trades within the range
    for (int i = startTradeIndex; i < endTradeIndex; i++)
    {
        if (bufferTradeType[i] == TRADE_TYPE_BUY)
        {
            buyTrades++;
        }
    }

    return buyTrades;
}

// Function to calculate the sell trades for a Renko brick
int CalculateSellTrades(int index)
{
    int sellTrades = 0;

    // Define the range of trades for the current brick
    int startTradeIndex = bufferStart[index];
    int endTradeIndex = bufferStart[index + 1];

    // Count the number of sell trades within the range
    for (int i = startTradeIndex; i < endTradeIndex; i++)
    {
        if (bufferTradeType[i] == TRADE_TYPE_SELL)
        {
            sellTrades++;
        }
    }

    return sellTrades;
}

// Function to calculate the total volume for a Renko brick
double CalculateTotalVolume(int index)
{
    double totalVolume = 0.0;

    // Define the range of trades for the current brick
    int startTradeIndex = bufferStart[index];
    int endTradeIndex = bufferStart[index + 1];

    // Sum up the volumes of trades within the range
    for (int i = startTradeIndex; i < endTradeIndex; i++)
    {
        totalVolume += bufferVolume[i];
    }

    return totalVolume;
}

// Function to calculate the buy volume for a Renko brick
double CalculateBuyVolume(int index)
{
    double buyVolume = 0.0;

    // Define the range of trades for the current brick
    int startTradeIndex = bufferStart[index];
    int endTradeIndex = bufferStart[index + 1];

    // Sum up the volumes of buy trades within the range
    for (int i = startTradeIndex; i < endTradeIndex; i++)
    {
        if (bufferTradeType[i] == TRADE_TYPE_BUY)
        {
            buyVolume += bufferVolume[i];
        }
    }

    return buyVolume;
}

// Function to calculate the sell volume for a Renko brick
double CalculateSellVolume(int index)
{
    double sellVolume = 0.0;

    // Define the range of trades for the current brick
    int startTradeIndex = bufferStart[index];
    int endTradeIndex = bufferStart[index + 1];

    // Sum up the volumes of sell trades within the range
    for (int i = startTradeIndex; i < endTradeIndex; i++)
    {
        if (bufferTradeType[i] == TRADE_TYPE_SELL)
        {
            sellVolume += bufferVolume[i];
        }
    }

    return sellVolume;
}

// Function to calculate the time per brick for a Renko brick
int CalculateTimePerBrick(int index)
{
    int timePerBrick = 0;

    if (index > 0)
    {
        // Calculate the time difference between the current brick and the previous brick
        int timeDifference = time[index - 1] - time[index];
        timePerBrick = MathAbs(timeDifference);
    }

    return timePerBrick;
}


Also this:

Code: Select all

//+------------------------------------------------------------------+
//|                                                     YourIndicator |
//|                                         Copyright © 2023, YourName |
//|                                        https://www.yourwebsite.com |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 11
#property indicator_plots   11

// Define the indicator buffers
double BufferBrickSize[];
double BufferTrendType[];
double BufferTrendStrength[];
double BufferTrendLength[];
double BufferMomentum[];
double BufferConsolidation[];
double BufferConsolidationLength[];
double BufferReversalType[];
double BufferReversalLength[];
double BufferRange[];
double BufferRangeIntervals[];

// Global Variables
double BrickSize;  // Renko brick size
double AverageSpread;  // Average spread value
double CurrentSpread;  // Current spread value
double SpreadMultiplierAverage;  // Multiplier for average spread
double SpreadMultiplierCurrent;  // Multiplier for current spread
double ATRPeriod;  // Period for calculating ATR
double FixedBrickSize;  // Fixed brick size
// Define other global variables for tracking associated values
int TrendType;
double TrendStrength;
int TrendLength;
double Momentum;
bool Consolidation;
int ConsolidationLength;
int ReversalType;
int ReversalLength;
double Range;
double RangeIntervals;
// Add any additional global variables you need

// Custom Indicator Initialization
int OnInit()
{
    // Calculate the average spread
    double sumSpread = 0.0;
    for (int i = 0; i < rates_total; i++)
    {
        sumSpread += spread[i];
    }
    AverageSpread = sumSpread / rates_total;

    // Set the brick size based on your chosen calculation method
    // You can use any of the methods mentioned earlier (average spread, current spread, ATR, etc.)
    // Assign the calculated value to the BrickSize variable
    BrickSize = AverageSpread * SpreadMultiplierAverage;

    // Initialize the other global variables
    CurrentSpread = 0.0;
    SpreadMultiplierAverage = 1.0;
    SpreadMultiplierCurrent = 1.0;
    ATRPeriod = 14;
    FixedBrickSize = 10.0;  // Set your desired fixed brick size
    // Initialize the other global variables for tracking associated values
    TrendType = 0;
    TrendStrength = 0.0;
    TrendLength = 0;
    Momentum = 0.0;
    Consolidation = false;
    ConsolidationLength = 0;
    ReversalType = 0;
    ReversalLength = 0;
    Range = 0.0;
    RangeIntervals = 0.0;
    // Initialize any additional global variables

    // Define indicator properties
    IndicatorSetString(INDICATOR_SHORTNAME, "Your Indicator Name");  // Replace with your desired indicator name
    IndicatorSetInteger(INDICATOR_DIGITS, _Digits);

    // Assign buffer(s) to the indicator
    SetIndexBuffer(0, BufferBrickSize, INDICATOR_DATA);
    SetIndexBuffer(1, BufferTrendType, INDICATOR_DATA);
    SetIndexBuffer(2, BufferTrendStrength, INDICATOR_DATA);
    SetIndexBuffer(3, BufferTrendLength, INDICATOR_DATA);
    SetIndexBuffer(4, BufferMomentum, INDICATOR_DATA);
    SetIndexBuffer(5, BufferConsolidation, INDICATOR_DATA);
    SetIndexBuffer(6, BufferConsolidationLength, INDICATOR_DATA);
    SetIndexBuffer(7, BufferReversalType, INDICATOR_DATA);
    SetIndexBuffer(8, BufferReversalLength, INDICATOR_DATA);
    SetIndexBuffer(9, BufferRange, INDICATOR_DATA);
    SetIndexBuffer(10, BufferRangeIntervals, INDICATOR_DATA);
    
    // Configure indicator plot settings
    PlotIndexSetInteger(0, PLOT_DRAW_TYPE, DRAW_TYPE_NONE);
    PlotIndexSetInteger(1, PLOT_DRAW_TYPE, DRAW_HISTOGRAM);
    PlotIndexSetInteger(2, PLOT_DRAW_TYPE, DRAW_LINE);
    PlotIndexSetInteger(3, PLOT_DRAW_TYPE, DRAW_LINE);
    PlotIndexSetInteger(4, PLOT_DRAW_TYPE, DRAW_LINE);
    PlotIndexSetInteger(5, PLOT_DRAW_TYPE, DRAW_HISTOGRAM);
    PlotIndexSetInteger(6, PLOT_DRAW_TYPE, DRAW_LINE);
    PlotIndexSetInteger(7, PLOT_DRAW_TYPE, DRAW_HISTOGRAM);
    PlotIndexSetInteger(8, PLOT_DRAW_TYPE, DRAW_LINE);
    PlotIndexSetInteger(9, PLOT_DRAW_TYPE, DRAW_LINE);
    PlotIndexSetInteger(10, PLOT_DRAW_TYPE, DRAW_LINE);
    
    // Add any additional buffer configuration if required

    // Add any additional initialization code you need

    return(INIT_SUCCEEDED);
}

// Custom Indicator Calculation
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
    // Add your Renko brick calculation logic here

    // Loop through the price data to determine when to generate new Renko bricks
    for (int i = prev_calculated; i < rates_total; i++)
    {
        // Implement your Renko brick generation logic using the BrickSize variable
        // Compare price values to decide if a new brick should be formed

        // Track associated values such as trend type, trend strength, momentum, etc.
        // based on your desired calculations and conditions

        // Assign the calculated values to the respective indicator buffers
        BufferBrickSize[i] = // Calculate the brick size value
        BufferTrendType[i] = // Calculate the trend type value
        BufferTrendStrength[i] = // Calculate the trend strength value
        BufferTrendLength[i] = // Calculate the trend length value
        BufferMomentum[i] = // Calculate the momentum value
        BufferConsolidation[i] = // Calculate the consolidation value
        BufferConsolidationLength[i] = // Calculate the consolidation length value
        BufferReversalType[i] = // Calculate the reversal type value
        BufferReversalLength[i] = // Calculate the reversal length value
        BufferRange[i] = // Calculate the range value
        BufferRangeIntervals[i] = // Calculate the range intervals value

        // Update the values of the custom indicator buffers
        // based on the generated Renko bricks and associated values
        Buffer[i] = // Assign the calculated value to the main buffer
    }

    return(rates_total);
}
I'm hoping someone here is more forgiving than high school was and can integrate these two codes into a working indicator like we all tried to do in high school ;-)

Sincerely (If not inspired to humor)

RauHer


SadRe: Metatrader 5 Versions of indicators.

422
I've just returned from another excursion into the ChatGPT realms and have been bested again. I attempted to code a renko indicator and use it as a base for an expert advisor... which is not taking any trades currently. I'm pretty sure the problem is with me at this point and not with Chat or the members of GPT. It shouldn't take too much of any ones time to fix this indicator (I think) because I compiled it with no errors. Some of the logic I intended for the indicator was rebuked by Chat and GPT with no explanation given so I have returned to the forum seeking assistance. I don't need three or four renko bar countdown timers for example but that is what I was given. Nothing displays on the chart when I attach the indicator so I'm pretty sure there are some issues with defining plots. There are 24 total indicator buffers with the likes of moving averages, absolute range, tick strength, and supertrend to name a few. Some of the variables would make good buffers as well like high, low, and others in the code. I think it's a good start to a comprehensive renko indicator. Can anyone help me? Thank you

Sincerely (If not inspired to humor)

RauHer


Re: Metatrader 5 Versions of indicators.

426
Musariri Ndlovu wrote: Sun Oct 01, 2023 3:05 pm Anyone with mt5 version of ZzNrpAa indicator please help or who can convert it please help
From mql5.com:
“[A]s we know, there are known knowns—there are things we know we know. We also know there are known unknowns—that is to say we know there are some things we do not know. But there are also unknown unknowns—the ones we don’t know we don’t know.”—Donald Rumsfeld, 2002

Re: Metatrader 5 Versions of indicators

427
Correction: Upon my inspection of its code, the original zz-nrp-aa-indicator for MT4 does not use fractals.
For a direct element by element conversion of that MT4 indicator to MT5, see attached.
“[A]s we know, there are known knowns—there are things we know we know. We also know there are known unknowns—that is to say we know there are some things we do not know. But there are also unknown unknowns—the ones we don’t know we don’t know.”—Donald Rumsfeld, 2002

Re: Metatrader 5 Versions of indicators

428
Another correction: I found operational errors after compiling in version 1.
An array out of range and broken alerts have been fixed in version 2, attached.
“[A]s we know, there are known knowns—there are things we know we know. We also know there are known unknowns—that is to say we know there are some things we do not know. But there are also unknown unknowns—the ones we don’t know we don’t know.”—Donald Rumsfeld, 2002

Re: Metatrader 5 Versions of indicators

430
Ugh... This is the toughest indicator code that I have ever converted. Each version has worked in the IDE debugger but a few ticks arrived last night in my demo platform showing errors again. I had to reorganize the MQL4 code's compound nested code blocks and then compare my MQL5 code to it element by element again and fix nested code. In this version 4, the arrows look ok but the NRP zigzag line has a distorted point in history and runs into the future. Unfortunately, I can't test while the market is closed during the holiday. I'll retest it later this week.

Merry Christmas and Happy Holidays.
These users thanked the author JohnnyRy for the post:
josi
“[A]s we know, there are known knowns—there are things we know we know. We also know there are known unknowns—that is to say we know there are some things we do not know. But there are also unknown unknowns—the ones we don’t know we don’t know.”—Donald Rumsfeld, 2002


Who is online

Users browsing this forum: IBM oBot [Bot], kvak and 11 guests