Chandelier Exit MT5 code into ProRealTime code

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #109188 quote
    sulimastersulimaster
    Participant
    Average

    Hi Can you please help translating the below to ProRealTime code. Thanks

    #property indicator_chart_window
    #property indicator_buffers 8
    #property indicator_plots   8
    #property indicator_type1   DRAW_LINE
    #property indicator_color1  clrDeepSkyBlue
    #property indicator_style1  STYLE_DOT
    #property indicator_type2   DRAW_LINE
    #property indicator_style2  STYLE_DOT
    #property indicator_color2  clrPaleVioletRed
    #property indicator_type3   DRAW_LINE
    #property indicator_color3  clrDeepSkyBlue
    #property indicator_type4   DRAW_LINE
    #property indicator_color4  clrPaleVioletRed
    #property indicator_type5   DRAW_ARROW
    #property indicator_color5  clrDeepSkyBlue
    #property indicator_type6   DRAW_ARROW
    #property indicator_color6  clrPaleVioletRed
    #property indicator_type7   DRAW_ARROW
    #property indicator_color7  clrDeepSkyBlue
    #property indicator_type8   DRAW_ARROW
    #property indicator_color8  clrPaleVioletRed

    //— input parameters

    input int     AtrPeriod      =  22; // Atr period
    input double  AtrMultiplier1 = 3.0; // Atr 1st multiplier
    input double  AtrMultiplier2 = 4.5; // Atr 2nd multiplier
    input int     LookBackPeriod =  22; // Look-back period

    double UplBuffer1[],UpdBuffer1[],DnlBuffer1[],DndBuffer1[],UplBuffer2[],UpdBuffer2[],DnlBuffer2[],DndBuffer2[];
    //+——————————————————————+
    //| Custom indicator initialization function                         |
    //+——————————————————————+
    int OnInit()
    {
    //— indicator buffers mapping
    SetIndexBuffer(0,UplBuffer1,INDICATOR_DATA);
    SetIndexBuffer(1,DnlBuffer1,INDICATOR_DATA);
    SetIndexBuffer(2,UplBuffer2,INDICATOR_DATA);
    SetIndexBuffer(3,DnlBuffer2,INDICATOR_DATA);
    SetIndexBuffer(4,UpdBuffer1,INDICATOR_DATA); PlotIndexSetInteger(4,PLOT_ARROW,159);
    SetIndexBuffer(5,DndBuffer1,INDICATOR_DATA); PlotIndexSetInteger(5,PLOT_ARROW,159);
    SetIndexBuffer(6,UpdBuffer2,INDICATOR_DATA); PlotIndexSetInteger(6,PLOT_ARROW,159);
    SetIndexBuffer(7,DndBuffer2,INDICATOR_DATA); PlotIndexSetInteger(7,PLOT_ARROW,159);
    return (INIT_SUCCEEDED);
    }
    //
    //
    //
    void OnDeinit(const int reason)
    {
    }
    //+——————————————————————+
    //| Work array                                                       |
    //+——————————————————————+
    double  work[][6];
    #define _hi1    0
    #define _lo1    1
    #define _hi2    2
    #define _lo2    3
    #define _trend1 4
    #define _trend2 5
    //+——————————————————————+
    //| 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[])
    {
    if(Bars(_Symbol,_Period)<rates_total) return(prev_calculated);
    if(ArrayRange(work,0)!=rates_total) ArrayResize(work,rates_total);

    int i=(int)MathMax(prev_calculated-1,1); for(; i<rates_total && !_StopFlag; i++)
    {
    UplBuffer1[i] = UpdBuffer1[i] = DnlBuffer1[i] = DndBuffer1[i] = EMPTY_VALUE;
    UplBuffer2[i] = UpdBuffer2[i] = DnlBuffer2[i] = DndBuffer2[i] = EMPTY_VALUE;

    //
    //——————-
    //

    int  _start = MathMax(i-LookBackPeriod,0);
    double _atr = 0; for(int k=1; k<=AtrPeriod && (i-k-1)>=0; k++) _atr += MathMax(high[i-k],close[MathMax(i-k-1,0)])- MathMin(low[i-k],close[MathMax(i-k-1,0)]); _atr/=(double)AtrPeriod;
    double _max = high[ArrayMaximum(high,_start,LookBackPeriod)];
    double _min = low [ArrayMinimum(low ,_start,LookBackPeriod)];

    work[i][_hi1]    = _max-AtrMultiplier1*_atr;
    work[i][_lo1]    = _min+AtrMultiplier1*_atr;
    work[i][_hi2]    = _max-AtrMultiplier2*_atr;
    work[i][_lo2]    = _min+AtrMultiplier2*_atr;
    work[i][_trend1] = (i>0) ? work[i-1][_trend1] : 0;
    work[i][_trend2] = (i>0) ? work[i-1][_trend2] : 0;
    if(i>0)
    {
    if(close[i] > work[i-1][_lo1]) work[i][_trend1]=  1;
    if(close[i] < work[i-1][_hi1]) work[i][_trend1]= –1;
    if(close[i] > work[i-1][_lo2]) work[i][_trend2]=  1;
    if(close[i] < work[i-1][_hi2]) work[i][_trend2]= –1;

    if(AtrMultiplier1>0 && work[i][_trend1] ==  1) { if(work[i][_hi1]<work[i-1][_hi1]) work[i][_hi1]=work[i-1][_hi1]; UplBuffer1[i] = work[i][_hi1]; if(UplBuffer1[i-1]==EMPTY_VALUE) UpdBuffer1[i]=UplBuffer1[i];}
    if(AtrMultiplier1>0 && work[i][_trend1] == –1) { if(work[i][_lo1]>work[i-1][_lo1]) work[i][_lo1]=work[i-1][_lo1]; DnlBuffer1[i] = work[i][_lo1]; if(DnlBuffer1[i-1]==EMPTY_VALUE) DndBuffer1[i]=DnlBuffer1[i];}
    if(AtrMultiplier2>0 && work[i][_trend2] ==  1) { if(work[i][_hi2]<work[i-1][_hi2]) work[i][_hi2]=work[i-1][_hi2]; UplBuffer2[i] = work[i][_hi2]; if(UplBuffer2[i-1]==EMPTY_VALUE) UpdBuffer2[i]=UplBuffer2[i];}
    if(AtrMultiplier2>0 && work[i][_trend2] == –1) { if(work[i][_lo2]>work[i-1][_lo2]) work[i][_lo2]=work[i-1][_lo2]; DnlBuffer2[i] = work[i][_lo2]; if(DnlBuffer2[i-1]==EMPTY_VALUE) DndBuffer2[i]=DnlBuffer2[i];}
    }
    }
    return (i);
    }
    //+——————————————————————+

    #109229 quote
    NicolasNicolas
    Keymaster
    Legend

    Please use the form on this page and follow the instructions when asking for a code translation: Ask for a free code conversion

    #192528 quote
    NicolasNicolas
    Keymaster
    Legend

    That’s a chandelier exit, PRT version is located here: https://www.prorealcode.com/prorealtime-indicators/another-atr-trailing-stop/

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Chandelier Exit MT5 code into ProRealTime code


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
sulimaster @sulimaster Participant
Summary

This topic contains 2 replies,
has 1 voice, and was last updated by NicolasNicolas
4 years, 5 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 10/03/2019
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...