Objective_v1

Author: Copyright © 2011, LeMan.
0 Views
0 Downloads
0 Favorites
Objective_v1
ÿþ//+------------------------------------------------------------------+

//|                                                    Objective.mq5 | 

//|                                         Copyright © 2011, LeMan. |

//|                                                 b-market@mail.ru |

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

#property copyright "Copyright © 2011, LeMan."

#property link      "b-market@mail.ru"

#property description "Objective"

//---- =><5@ 25@A88 8=48:0B>@0

#property version   "1.01"

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

#property indicator_chart_window 

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

//|  >1JO2;5=85 :>=AB0=B              |

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

#define LINES_TOTAL         8 // >=AB0=B0 4;O :>;8G5AB20 ;8=89 8=48:0B>@0

#define RESET               0 // >=AB0=B0 4;O 2>72@0B0 B5@<8=0;C :><0=4K =0 ?5@5AGQB 8=48:0B>@0

//---- :>;8G5AB2> 8=48:0B>@=KE 1CD5@>2

#property indicator_buffers LINES_TOTAL 

//---- 8A?>;L7>20=> 2A53> 3@0D8G5A:8E ?>AB@>5=89

#property indicator_plots   LINES_TOTAL



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

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

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

//---- >B@8A>2:0 8=48:0B>@>2 2 2845 ;8=89

#property indicator_type1   DRAW_LINE

#property indicator_type2   DRAW_LINE

#property indicator_type3   DRAW_LINE

#property indicator_type4   DRAW_LINE

#property indicator_type5   DRAW_LINE

#property indicator_type6   DRAW_LINE

#property indicator_type7   DRAW_LINE

#property indicator_type8   DRAW_LINE

//---- 2K1>@ F25B>2 ;8=89

#property indicator_color1  clrRed

#property indicator_color2  clrRed

#property indicator_color3  clrRed

#property indicator_color4  clrRed

#property indicator_color5  clrGreen

#property indicator_color6  clrGreen

#property indicator_color7  clrGreen

#property indicator_color8  clrGreen

//---- ;8=88 - HB@8E?C=:B8@=K5 :@82K5

#property indicator_style1 STYLE_DASHDOTDOT

#property indicator_style2 STYLE_DASHDOTDOT

#property indicator_style3 STYLE_DASHDOTDOT

#property indicator_style4 STYLE_DASHDOTDOT

#property indicator_style5 STYLE_DASHDOTDOT

#property indicator_style6 STYLE_DASHDOTDOT

#property indicator_style7 STYLE_DASHDOTDOT

#property indicator_style8 STYLE_DASHDOTDOT

//---- B>;I8=0 ;8=89 1

#property indicator_width1  1

#property indicator_width2  1

#property indicator_width3  1

#property indicator_width4  1

#property indicator_width5  1

#property indicator_width6  1

#property indicator_width7  1

#property indicator_width8  1

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

//|  %+  " + "      |

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

input uint Sample=20;

input uint Quartile_1 = 25;

input uint Quartile_2 = 50;

input uint Quartile_3 = 75;

input int Shift=0; // A4283 8=48:0B>@0 ?> 3>@87>=B0;8 2 10@0E

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

//---- >1JO2;5=85 3;>10;L=KE ?5@5<5==KE

int n0,n1,n2,n3;

double HOArray[],OLArray[];

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

int min_rates_total,N_;

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

//|  0AA82K ?5@5<5==KE 4;O A>740=8O 8=48:0B>@=KE 1CD5@>2            |

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

class CIndicatorsBuffers

  {

public: double    IndBuffer[];

  };

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

//| !>740=85 8=48:0B>@=KE 1CD5@>2                                    |

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

CIndicatorsBuffers Ind[LINES_TOTAL];

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

//|  0AA82K ?5@5<5==KE 4;O A>740=8O 8=48:0B>@=KE 1CD5@>2            |

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

int GetVelue(string InVelueName,int InVelue)

  {

//----

   if(InVelue>100)

     {

      Print("0@0<5B@ "+InVelueName+" =5 <>65B 1KBL 1>;LH5 100! C45B 8A?>;L7>20=> 7=0G5=85 ?> C<>;G0=8N, @02=>5 100!");

      return(100);

     }

   if(InVelue<0)

     {

      Print("0@0<5B@ "+InVelueName+" =5 <>65B 1KBL <5=LH5 0! C45B 8A?>;L7>20=> 7=0G5=85 ?> C<>;G0=8N, @02=>5 0!");

      return(0);

     }

//----

   return(InVelue);

  }

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

//| Custom indicator initialization function                         | 

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

void OnInit()

  {

//---- =8F80;870F8O :>=AB0=B

   double P1=GetVelue("Quartile_1",Quartile_1);

   double P2=GetVelue("Quartile_2",Quartile_2);

   double P3=GetVelue("Quartile_3",Quartile_3);



   N_=int(Sample);

   if(N_<3){N_=3; Print("0@0<5B@ Sample =5 <>65B 1KBL <5=LH5 3! C45B 8A?>;L7>20=> 7=0G5=85 ?> C<>;G0=8N, @02=>5 3!");}



   min_rates_total=N_;

   n0=N_-1;

   n1=int(MathRound(N_*P1/100)); if(!n1) n1=100;

   n2=int(MathRound(N_*P2/100)); if(!n2) n2=100;

   n3=int(MathRound(N_*P3/100)); if(!n3) n3=100;





//---- @0A?@545;5=85 ?0<OB8 ?>4 <0AA82K ?5@5<5==KE

   if(ArrayResize(HOArray,N_)<N_) Print("5 C40;>AL @0A?@545;8BL ?0<OBL ?>4 <0AA82 HOArray[]");

   if(ArrayResize(OLArray,N_)<N_) Print("5 C40;>AL @0A?@545;8BL ?0<OBL ?>4 <0AA82 OLArray[]");



//----

   for(int numb=0; numb<LINES_TOTAL; numb++)

     {

      string shortname="";

      StringConcatenate(shortname,"Ouartile ",numb+1,")");

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

      PlotIndexSetString(numb,PLOT_LABEL,shortname);

      //---- CAB0=>2:0 7=0G5=89 8=48:0B>@0, :>B>@K5 =5 1C4CB 2848<K =0 3@0D8:5

      PlotIndexSetDouble(numb,PLOT_EMPTY_VALUE,EMPTY_VALUE);

      //---- >ACI5AB2;5=85 A42830 =0G0;0 >BAGQB0 >B@8A>2:8 8=48:0B>@0

      PlotIndexSetInteger(numb,PLOT_DRAW_BEGIN,min_rates_total);

      //---- >ACI5AB2;5=85 A42830 8=48:0B>@0 1 ?> 3>@87>=B0;8 =0 Shift

      PlotIndexSetInteger(numb,PLOT_SHIFT,Shift);

      //---- ?@52@0I5=85 48=0<8G5A:8E <0AA82>2 2 8=48:0B>@=K5 1CD5@K

      SetIndexBuffer(numb,Ind[numb].IndBuffer,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,"Objective");



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

   IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);

//---- 7025@H5=85 8=8F80;870F88

  }

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

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

                )

  {

//---- ?@>25@:0 :>;8G5AB20 10@>2 =0 4>AB0B>G=>ABL 4;O @0AGQB0

   if(rates_total<min_rates_total) return(0);



//---- 1JO2;5=85 F5;KE ?5@5<5==KE

   int first,bar;

   double q[8];



//---- @0AGQB AB0@B>2>3> =><5@0 first 4;O F8:;0 ?5@5AGQB0 10@>2

   if(prev_calculated==0) // ?@>25@:0 =0 ?5@2K9 AB0@B @0AGQB0 8=48:0B>@0

     {

      first=min_rates_total-1; // AB0@B>2K9 =><5@ 4;O @0AGQB0 2A5E 10@>2

     }

   else // AB0@B>2K9 =><5@ 4;O @0AGQB0 =>2KE 10@>2

     {

      first=prev_calculated-1;

     }



//---- A=>2=>9 F8:; @0AGQB0

   for(bar=first; bar<rates_total; bar++)

     {

      for(int kkk=0; kkk<N_; kkk++) HOArray[kkk]=high[bar-kkk]-open[bar-kkk];

      for(int kkk=0; kkk<N_; kkk++) OLArray[kkk]=open[bar-kkk]-low [bar-kkk];



      ArraySort(HOArray);

      ArraySort(OLArray);



      q[0] = -OLArray[n1];

      q[1] = -OLArray[n2];

      q[2] = -OLArray[n3];

      q[3] = -OLArray[n0];

      q[4] = +HOArray[n1];

      q[5] = +HOArray[n2];

      q[6] = +HOArray[n3];

      q[7] = +HOArray[n0];



      for(int numb=0; numb<LINES_TOTAL; numb++) Ind[numb].IndBuffer[bar]=open[bar]+q[numb];

     }

//----    

   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 ---