CandleStop_Cloud

Author: Copyright © 2009, CrushD
0 Views
0 Downloads
0 Favorites
CandleStop_Cloud
ÿþ//+------------------------------------------------------------------+

//|                                             CandleStop_Cloud.mq5 |

//|                                         Copyright © 2009, CrushD |

//|                                                                  |

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

#property copyright "Copyright © 2009, CrushD"

#property link "CrushD"

#property description "=48:0B>@ 4;O ?>4BO3820=8O B@59;8=AB>?>2 A F25B>2K< D>=>2K< 70?>;=5=85< :0=0;0 8 A >B>1@065=85< ?>A;54=8E 7=0G5=89 2 2845 F5=>2KE <5B>:"

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

#property version   "1.00"

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

#property indicator_chart_window 

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

#property indicator_buffers 7 

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

#property indicator_plots   5

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

//|  0@0<5B@K >B@8A>2:8 >1;0:0                  |

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

//---- >B@8A>2:0 8=48:0B>@0 2 2845 F25B=>3> >1;0:0

#property indicator_type1   DRAW_FILLING

//---- 2 :0G5AB25 F25B0 >1;0:0 8A?>;L7>20=

#property indicator_color1  clrAquamarine

//---- >B>1@065=85 <5B:8 8=48:0B>@0

#property indicator_label1  "Upper Cloud"

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

//|  0@0<5B@K >B@8A>2:8 >1;0:0                  |

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

//---- >B@8A>2:0 8=48:0B>@0 2 2845 F25B=>3> >1;0:0

#property indicator_type2   DRAW_FILLING

//---- 2 :0G5AB25 F25B0 >1;0:0 8A?>;L7>20=

#property indicator_color2  clrLightPink

//---- >B>1@065=85 <5B:8 8=48:0B>@0

#property indicator_label2  "Lower Cloud"

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

//|  0@0<5B@K >B@8A>2:8 F5=B@0;L=>9 ;8=88     |

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

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

#property indicator_type3   DRAW_LINE

//---- 2 :0G5AB25 F25B0 ;8=88 8=48:0B>@0 8A?>;L7>20= SlateBlue F25B

#property indicator_color3 clrSlateBlue

//---- ;8=8O 8=48:0B>@0 - =5?@5@K2=0O :@820O

#property indicator_style3  STYLE_DASHDOTDOT

//---- B>;I8=0 ;8=88 8=48:0B>@0 @02=0 1

#property indicator_width3  1

//---- >B>1@065=85 ;M91K 8=48:0B>@0

#property indicator_label3  "Middle Candle Stop"



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

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

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

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

#property indicator_type4   DRAW_LINE

#property indicator_type5   DRAW_LINE

//---- 22K1>@ F25B>2 C@>2=59

#property indicator_color4  clrLimeGreen

#property indicator_color5  clrDeepPink

//---- C@>2=8 - =5?@5@K2=K5 :@82K5

#property indicator_style4 STYLE_SOLID

#property indicator_style5 STYLE_SOLID

//---- B>;I8=0 C@>2=59 @02=0 1

#property indicator_width4  1

#property indicator_width5  1

//---- >B>1@065=85 <5B>: C@>2=59

#property indicator_label4  "Upper Trail Stop"

#property indicator_label5  "Lower Trail Stop"



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

//|  %+  " + "      |

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

input uint UpTrailPeriods=5; //5@8>4 ?>8A:0 4;O E0O               

input uint DnTrailPeriods=5; //5@8>4 ?>8A:0 4;O ;>C

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

//---- F25B0 F5=>2KE <5B>:

input color  Middle_color=clrBlue;

input color  Upper_color=clrMediumSeaGreen;

input color  Lower_color=clrRed;

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



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

double ExtLineBuffer0[],ExtLineBuffer1[],ExtLineBuffer2[],ExtLineBuffer3[],ExtLineBuffer4[],ExtLineBuffer5[],ExtLineBuffer6[];



//---- 1JO2;5=85 ?5@5<5==>9 7=0G5=8O 25@B8:0;L=>3> A42830 <C28=30

double dPriceShift;

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

int min_rates_total;

//---- 1JO2;5=85 AB@8=3>2 4;O B5:AB>2KE <5B>:

string upper_name,middle_name,lower_name;

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

//| CandleStop initialization function                               | 

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

void OnInit()

  {

//---- =8F80;870F8O ?5@5<5==KE =0G0;0 >BAGQB0 40==KE

   min_rates_total=int(MathMax(UpTrailPeriods,DnTrailPeriods));

//---- =8F80;870F8O AB@8=3>2

   upper_name="CandleStop_Cloud Upper text lable";

   middle_name="CandleStop_Cloud middle text lable";

   lower_name="CandleStop_Cloud lower text lable";

//---- 8=8F80;870F8O 8=48:0B>@=KE 1CD5@>2   

   BufferInit(0,ExtLineBuffer0);

   BufferInit(1,ExtLineBuffer1);

   BufferInit(2,ExtLineBuffer2);

   BufferInit(3,ExtLineBuffer3);

   BufferInit(4,ExtLineBuffer4);

   BufferInit(5,ExtLineBuffer5);

   BufferInit(6,ExtLineBuffer6);

//---- 8=8F80;870F8O 8=48:0B>@>2   

   IndInit(0,EMPTY_VALUE,min_rates_total,Shift);

   IndInit(1,EMPTY_VALUE,min_rates_total,Shift);

   IndInit(2,EMPTY_VALUE,min_rates_total,Shift);

   IndInit(3,EMPTY_VALUE,min_rates_total,Shift);

   IndInit(4,EMPTY_VALUE,min_rates_total,Shift);



//--- 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,"CandleStop_Cloud");



//--- >?@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 deinitialization function                       |

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

void OnDeinit(const int reason)

  {

//----

   ObjectDelete(0,upper_name);

   ObjectDelete(0,middle_name);

   ObjectDelete(0,lower_name);

//----

  }

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

//| =8F80;870F8O 8=48:0B>@=>3> 1CD5@0                               |

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

void BufferInit(int Number,double &Buffer[])

  {

//--- ?@52@0I5=85 48=0<8G5A:>3> <0AA820 2 8=48:0B>@=K9 1CD5@

   SetIndexBuffer(Number,Buffer,INDICATOR_DATA);

//--- 8=45:A0F8O M;5<5=B>2 2 1CD5@5 :0: 2 B09<A5@88

   ArraySetAsSeries(Buffer,true);

  }

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

//| =8F80;870F8O 8=48:0B>@0                                         |

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

void IndInit(int Number,double Empty_Value,int Draw_Begin,int nShift)

  {

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

   PlotIndexSetInteger(Number,PLOT_DRAW_BEGIN,Draw_Begin);

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

   PlotIndexSetDouble(Number,PLOT_EMPTY_VALUE,Empty_Value);

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

   PlotIndexSetInteger(Number,PLOT_SHIFT,nShift);

  }

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

//| CandleStop 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 ?5@5<5==KE A ?;020NI59 B>G:>9  

   double HH,LL,HL;

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

   int limit,bar;



//---- 8=45:A0F8O M;5<5=B>2 2 <0AA820E, :0: 2 B09<A5@8OE  

   ArraySetAsSeries(low,true);

   ArraySetAsSeries(high,true);

   ArraySetAsSeries(time,true);



//---- @0AG5B AB0@B>2>3> =><5@0 limit 4;O F8:;0 ?5@5AG5B0 10@>2

   if(prev_calculated>rates_total || prev_calculated<=0) // ?@>25@:0 =0 ?5@2K9 AB0@B @0AG5B0 8=48:0B>@0

     {

      limit=rates_total-min_rates_total-1;               // AB0@B>2K9 =><5@ 4;O @0AG5B0 2A5E 10@>2

     }

   else

     {

      limit=rates_total-prev_calculated;                 // AB0@B>2K9 =><5@ 4;O @0AG5B0 =>2KE 10@>2

     }



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

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

     {

      HH=high[ArrayMaximum(high,bar,UpTrailPeriods)];

      LL=low [ArrayMinimum(low, bar,DnTrailPeriods)];

      HL=(HH+LL)/2.0;    

      

      ExtLineBuffer0[bar]=ExtLineBuffer5[bar]=HH;

      ExtLineBuffer1[bar]=ExtLineBuffer2[bar]=ExtLineBuffer4[bar]=HL;

      ExtLineBuffer3[bar]=ExtLineBuffer6[bar]=LL;

     }

     

   SetRightPrice(0,middle_name,0,time[0],ExtLineBuffer1[0],Middle_color,"Georgia");

   SetRightPrice(0,upper_name,0,time[0],ExtLineBuffer0[0],Upper_color,"Georgia");

   SetRightPrice(0,lower_name,0,time[0],ExtLineBuffer3[0],Lower_color,"Georgia");

//----  

   return(rates_total);

  }

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

//|  RightPrice creation                                             |

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

void CreateRightPrice(long chart_id,// chart ID

                      string   name,              // object name

                      int      nwin,              // window index

                      datetime time,              // price level time

                      double   price,             // price level

                      color    Color,             // Text color

                      string   Font               // Text font

                      )

//---- 

  {

//----

   ObjectCreate(chart_id,name,OBJ_ARROW_RIGHT_PRICE,nwin,time,price);

   ObjectSetInteger(chart_id,name,OBJPROP_COLOR,Color);

   ObjectSetString(chart_id,name,OBJPROP_FONT,Font);

   ObjectSetInteger(chart_id,name,OBJPROP_BACK,true);

   ObjectSetInteger(chart_id,name,OBJPROP_WIDTH,2);

//----

  }

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

//|  RightPrice reinstallation                                       |

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

void SetRightPrice(long chart_id,// chart ID

                   string   name,              // object name

                   int      nwin,              // window index

                   datetime time,              // price level time

                   double   price,             // price level

                   color    Color,             // Text color

                   string   Font               // Text font

                   )

//---- 

  {

//----

   if(ObjectFind(chart_id,name)==-1) CreateRightPrice(chart_id,name,nwin,time,price,Color,Font);

   else ObjectMove(chart_id,name,0,time,price);

//----

  }

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

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