Straight Lines indior

thread: Straight Lines indior

  1. #1

    Straight Lines indicator

    1 Attachment(s ) ) Hello!!

    There is some indior that draws straight lines every n bars???

    Thank you for your help.

  2. #2
    I attempt to code in MT4 but the indior doesn´t operate properly.


    #property indior_chart_window
    #property indior_buffers 1
    #property indior_plots 1
    //-- plot Section
    #property indior_label1 Section
    #property indior_type1 DRAW_SECTION
    #property indior_color1 clrRed
    #property indior_style1 STYLE_SOLID
    #property indior_width1 1
    //-- input parameter
    input int bars=5; // The length of sections in bars
    input int N=5; // The number of ticks to change the style of sections
    //-- An indior buffer for the plot
    double SectionBuffer[];
    //-- An auxiliary variable to calculate ends of sections
    int divider;
    //-- An array to store colors
    color colors[]=clrRed,clrBlue,clrGreen;
    //-- An array to store the line styles
    ENUM_LINE_STYLE styles[]=STYLE_SOLID,STYLE_DASH,STYLE_DOT,STYLE_DASHDOT,ST YLE_DASHDOTDOT;
    // ------------------------------------------------------------------
    //| Custom indior initialization function |
    // ------------------------------------------------------------------
    int OnInit()

    //-- Binding an array and an indior buffer
    SetIndexBuffer(0,SectionBuffer,INDICATOR_DATA);
    //-- The 0 (empty) value will mot participate in drawing
    PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0);
    //-- Check the indior parameter
    if(barslt;=0)

    PrintFormat(Invalid value of parameter bar=%d,bars);
    return(INIT_PARAMETERS_INCORRECT);

    else divider=2*bars;
    //--
    return(INIT_SUCCEEDED);

    // ------------------------------------------------------------------
    //| Custom indior 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[])

    static int ticks=0;
    //-- Calculate ticks to change the style, color and width of the line
    ticks ;
    //-- If a critical number of ticks has been accumulated
    if(ticksgt;=N)

    //-- The number of the bar from which the calculation of indior values starts
    int start=0;
    //-- If the indior has been calculated before, then set start on the previous bar
    if(prev_calculatedgt;0) start=prev_calculated-1;
    //-- Here are all the calculations of the indior values
    for(int I=start;ilt;rates_total;I )

    //-- Get a remainder of the division of the bar number by 2*bars
    int rest=I%divider;
    //-- If the bar number is divisible by 2*bars
    if(rest==0)

    //-- Set the end of the section at the High price of this bar
    SectionBuffer[I]=Close[I];

    //--If the Rest of the division is equal to bars,
    else

    //-- Set the end of the section at the High price of this bar
    if(rest==bars) SectionBuffer[I]=Close[I];
    //-- If nothing happened, ignore the bar - set 0
    else SectionBuffer[I]=0;


    //-- Return the prev_calculated value for the next call of the function
    return(rates_total);


  3. #3
    EDIT: nvm you already defined draw section at the beginning. It's quite hard to read code in this way.

  4. #4
    Solved.

    Currently the only issue I see, is that not refresh at last pub....
    https://www.cliqforex.com/attachment...1034885298.mq4

  5. #5
    For me personally, it's simpler to observe the market with this indior, less noise.

    Perhaps, some fantastic coder can address the issue which not mend properly the segments, add colors ( down or up ) etc

    Thanks for your attempts. .

  6. #6

  •