Candle Body Size indicator request

 

Hello everyone!

I find this indicator on Trading view platform, and I want to convert this to MT4 indicator with same idea, indicator name is (Candle Body Size) that Plot bar size compared to SMA 50 bars back.

Anyone can help me.


 
//@version=4
// Candle body size by @Syamay 25/11/2020 11.01am
// Big Bar Size can be used as Support resistent level.
study("bar size", shorttitle="Bar Size v1", format=format.volume)

lengthMA=input(50)

saiz = abs(high-low)
body = abs(open-close)
sma1 = (sma(body, lengthMA) ) 
barcolor = if close < open
    color.red
else
    color.green
    
plot(body, color=barcolor, linewidth=10, style=plot.style_columns, histbase = 0.000)
plot(sma1, color=color.white, linewidth=2, title=" Average Size")
// plot(saiz, color=color.orange, linewidth=2, title=" Candle Size")

 

Your topic has been moved to the section: MQL4 e MetaTrader 4 — In the future, please consider which section is most appropriate for your query.

  • Usually people who cannot code do not receive free help on this forum.
  • If you show your attempts and describe your problem clearly, you will most probably receive an answer from the community. Use the CODE button (Alt-S) when inserting code.
  • If you do not want to learn to code, that is not a problem. You can either look at the Codebase if something free already exists, or in the Market for paid products (also sometimes free).
  • Finally, you also have the option to hire a programmer in the Freelance section.
 
input int lengthMA=50;

//Author: Yashar Seyyedin
#property copyright "Copyright 2022, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_plots   4
//--- plot body
#property indicator_label1  "body"
#property indicator_type1   DRAW_NONE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot BarRed
#property indicator_label2  "BarRed"
#property indicator_type2   DRAW_HISTOGRAM
#property indicator_color2  clrRed
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
//--- plot BarGreen
#property indicator_label3  "BarGreen"
#property indicator_type3   DRAW_HISTOGRAM
#property indicator_color3  clrGreen
#property indicator_style3  STYLE_SOLID
#property indicator_width3  1
//--- plot sma1
#property indicator_label4  "sma1"
#property indicator_type4   DRAW_LINE
#property indicator_color4  clrWhite
#property indicator_style4  STYLE_SOLID
#property indicator_width4  1
//--- indicator buffers
double         bodyBuffer[];
double         BarRedBuffer[];
double         BarGreenBuffer[];
double         sma1Buffer[];

int OnInit()
  {
   SetIndexBuffer(0,bodyBuffer);
   SetIndexBuffer(1,BarRedBuffer);
   SetIndexBuffer(2,BarGreenBuffer);
   SetIndexBuffer(3,sma1Buffer);
   return(INIT_SUCCEEDED);
  }

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 BARS=MathMax(Bars-IndicatorCounted()-lengthMA,1);
   for(int i=BARS;i>=0;i--)
   {
      double saiz = MathAbs(High[i]-Low[i]);
      bodyBuffer[i] = MathAbs(Open[i]-Close[i]);
      sma1Buffer[i] = pine_sma(bodyBuffer, i, lengthMA);
      BarRedBuffer[i]=EMPTY_VALUE;
      BarGreenBuffer[i]=EMPTY_VALUE;
      if(Close[i] < Open[i])
          BarRedBuffer[i]=bodyBuffer[i];
      else
          BarGreenBuffer[i]=bodyBuffer[i];
   }
   return(rates_total);
  }

double pine_sma(double &array[], int index, int length)
{
    double sum = 0.0;
    for(int i = index;i<index+length;i++)
        sum = sum + array[i] / length;
    return sum;
}

Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • 2023.06.14
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
 
Yashar Seyyedin #

Thank you very much for your efforts, I'm really appreciated. Thank you