i_TrendSize_v1_0

Author: Copyright 2010-2019, Sergeev Mikhail
Price Data Components
0 Views
0 Downloads
0 Favorites
i_TrendSize_v1_0
ÿþ//+------------------------------------------------------------------+

//|                                                  i_TrendSize.mq5 |

//|                                  Copyright 2019, Sergeev Mikhail |

//|                    https://www.mql5.com/en/users/fastinvestments |

//+------------------------------------------------------------------+

#property copyright   "Copyright 2010-2019, Sergeev Mikhail"

#property link        "https://www.mql5.com/en/users/fastinvestments"

#property version     "1.0"

//--- >B@8A>2:0 8=48:0B>@0 2 >A=>2=>< >:=5

#property indicator_separate_window

#property indicator_maximum    3000

#property indicator_minimum    -3000

//--- 4;O @0AG5B0 8 >B@8A>2:8 8=48:0B>@0 8A?>;L7>20=> 420 1CD5@0

#property indicator_buffers 7

//--- 8A?>;L7>20=> 420 3@0D8G5A:8E ?>AB@>5=8O

#property indicator_plots   7

#property indicator_level1 1000

#property indicator_level2 -1000

#property indicator_level3 2000

#property indicator_level4 -2000

#property indicator_level5 3000

#property indicator_level6 -3000

//----

#property indicator_type1   DRAW_COLOR_HISTOGRAM

#property indicator_color1  clrGray, clrLime, clrRed, clrBlue, clrMagenta, clrWhite

#property indicator_width1  6

#property indicator_label1  "Size"

#property indicator_label2  "DnLine"

#property indicator_label3  "UpLine"

#property indicator_label4  "BarsTrend"

#property indicator_label5  "BigDnLine"

#property indicator_label6  "BigUpLine"

//--

input double Range = 24;

//--- >1JO2;5=85 48=0<8G5A:8E <0AA82>2, :>B>@K5 2 40;L=59H5< 1C4CB 8A?>;L7>20=K 2 :0G5AB25 8=48:0B>@=KE 1CD5@>2

double Buffer1[], ColorIndBuffer1[];

double SellBuffer1[], BuyBuffer1[], Trend[], SellBuffer2[], BuyBuffer2[];

//--- >1JO2;5=85 F5;>G8A;5==KE ?5@5<5==KE =0G0;0 >BAG5B0 40==KE

int min_rates_total, start;

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

void OnInit()

{

    //---

    SetIndexBuffer(0, Buffer1, INDICATOR_DATA);

    SetIndexBuffer(1, ColorIndBuffer1, INDICATOR_COLOR_INDEX);

    SetIndexBuffer(2, SellBuffer1, INDICATOR_DATA);

    SetIndexBuffer(3, BuyBuffer1, INDICATOR_DATA);

    SetIndexBuffer(4, Trend, INDICATOR_DATA);

    SetIndexBuffer(5, SellBuffer2, INDICATOR_DATA);

    SetIndexBuffer(6, BuyBuffer2, INDICATOR_DATA);

    //--- A>740=85 8<5=8 4;O >B>1@065=8O 2 >B45;L=>< ?>4>:=5 8 2> 2A?;K20NI59 ?>4A:07:5

    IndicatorSetString(INDICATOR_SHORTNAME, "");

    //--- >?@545;5=85 B>G=>AB8 >B>1@065=8O 7=0G5=89 8=48:0B>@0

    IndicatorSetInteger(INDICATOR_DIGITS, _Digits);

    //---

}

//+------------------------------------------------------------------+

//| Custom indicator iteration function                              |

//+------------------------------------------------------------------+

int OnCalculate(const int rates_total,    // :>;8G5AB2> 8AB>@88 2 10@0E =0 B5:CI5< B8:5

                const int prev_calculated,// :>;8G5AB2> 8AB>@88 2 10@0E =0 ?@54K4CI5< B8:5

                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[])

{

    //----

    ArraySetAsSeries(time, true);

    ArraySetAsSeries(open, true);

    ArraySetAsSeries(high, true);

    ArraySetAsSeries(low, true);

    ArraySetAsSeries(close, true);

    ArraySetAsSeries(Buffer1, true);

    ArraySetAsSeries(ColorIndBuffer1, true);

    ArraySetAsSeries(SellBuffer1, true);

    ArraySetAsSeries(BuyBuffer1, true);

    ArraySetAsSeries(Trend, true);

    ArraySetAsSeries(SellBuffer2, true);

    ArraySetAsSeries(BuyBuffer2, true);

    //----

    int counted_bars = prev_calculated, limit;

    if(counted_bars > 0)

    {

        counted_bars--;

    }

    if(counted_bars == 0)

    {

        limit = rates_total - 1002;

    }

    else

    {

        limit = rates_total - counted_bars;

    }

    //----

    for(int i = limit; i >= 0 && !IsStopped(); i--)

    {

        BuyBuffer1[i] = high[iHighest(NULL, PERIOD_CURRENT, MODE_HIGH, int(Range), i + 1)];

        SellBuffer1[i] = low[iLowest(NULL, PERIOD_CURRENT, MODE_LOW, int(Range), i + 1)];

        //---

        if(Trend[i + 1] < 0)

        {

            if(high[i] > BuyBuffer1[i])

            {

                Trend[i] = 1;

                SellBuffer2[i] = low[iLowest(NULL, PERIOD_CURRENT, MODE_LOW, int(-Trend[i + 1]), i + 1)];

                BuyBuffer2[i] = BuyBuffer2[i + 1];

            }

            else

            {

                Trend[i] = Trend[i + 1] - 1;

                SellBuffer2[i] = SellBuffer2[i + 1];

                BuyBuffer2[i] = BuyBuffer2[i + 1];

            }

            //---

        }

        else

        {

            if(low[i] < SellBuffer1[i])

            {

                Trend[i] = -1;

                SellBuffer2[i] = SellBuffer2[i + 1];

                BuyBuffer2[i] = high[iHighest(NULL, PERIOD_CURRENT, MODE_HIGH, int(Trend[i + 1]), i + 1)];

            }

            else

            {

                Trend[i] = Trend[i + 1] + 1;

                SellBuffer2[i] = SellBuffer2[i + 1];

                BuyBuffer2[i] = BuyBuffer2[i + 1];

            }

            //---

        }

        //---

        if(Trend[i] > 0) Buffer1[i] = (BuyBuffer1[i] - SellBuffer2[i]) / Point();

        if(Trend[i] < 0) Buffer1[i] = (SellBuffer1[i] - BuyBuffer2[i]) / Point();

        //---

        if(Buffer1[i] > 0)

        {

            ColorIndBuffer1[i] = 0;

            if(Buffer1[i] > 1000) ColorIndBuffer1[i] = 1;

            if(Buffer1[i] > 2000) ColorIndBuffer1[i] = 3;

            if(Buffer1[i] > 3000) ColorIndBuffer1[i] = 5;

            //if(pathern < 0) ColorIndBuffer1[i] = 0;

        }

        if(Buffer1[i] < 0)

        {

            ColorIndBuffer1[i] = 0;

            if(Buffer1[i] < -1000) ColorIndBuffer1[i] = 2;

            if(Buffer1[i] < -2000) ColorIndBuffer1[i] = 4;

            if(Buffer1[i] < -3000) ColorIndBuffer1[i] = 5;

            //if(pathern > 0) ColorIndBuffer1[i] = 0;

        }

        //else ColorIndBuffer1[i] = 0;

    }

    //---

    return(rates_total);

}



Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---