StochasticTransparentArrows

Author: Copyright 2021, MetaQuotes Software Corp.
Indicators Used
Stochastic oscillator
0 Views
0 Downloads
0 Favorites
StochasticTransparentArrows
ÿþ//+------------------------------------------------------------------+

//|                                  StochasticTransparentArrows.mq4 |

//|                        Copyright 2021, MetaQuotes Software Corp. |

//|                                             https://www.mql5.com |

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

#property copyright "Copyright 2021, MetaQuotes Software Corp."

#property link      "https://www.mql5.com"

#property version   "1.02"

#property strict

#property indicator_chart_window





extern int K=5;

extern int D=3;

extern int S=3;

extern ENUM_MA_METHOD M=MODE_SMA;

extern ENUM_STO_PRICE P=STO_LOWHIGH;

extern int L=20;  // 86=89 C@>25=L

extern uchar Opacity1=255; // 5?@>7@0G=>ABL =86=8E AB@5;>: 0-255

extern uchar Opacity2=100; // 5?@>7@0G=>ABL 25@E=8E AB@5;>: 0-255

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

  

   mup.Init(1,233,ANCHOR_UPPER,0,10,clrAqua,Opacity1);    

   mdn.Init(2,234,ANCHOR_LOWER,0,10,clrDeepPink,Opacity1);     

   

   lup.Init(3,233,ANCHOR_UPPER,0,16,clrRed,Opacity2);    

   ldn.Init(4,234,ANCHOR_LOWER,0,16,clrDodgerBlue,Opacity2);    

   

  

   return(INIT_SUCCEEDED);

  }

  

void OnDeinit(const int r)

  {  

   ObjectsDeleteAll(0,WindowExpertName());

   ChartRedraw(); 

}

  

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

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

  {



   int limit=rates_total-prev_calculated;



   if(prev_calculated==0){

      limit-=2;

   }



   for(int i=limit;i>=0;i--){

   

      double m0=iStochastic(NULL,0,K,D,S,M,P,0,i);

      double m1=iStochastic(NULL,0,K,D,S,M,P,0,i+1);      

      double s0=iStochastic(NULL,0,K,D,S,M,P,1,i);

      double s1=iStochastic(NULL,0,K,D,S,M,P,1,i+1);     

      

      string nm1=WindowExpertName()+"_mup_"+(string)(long)time[i];

      string nm2=WindowExpertName()+"_mdn_"+(string)(long)time[i];      

      string nm3=WindowExpertName()+"_lup_"+(string)(long)time[i];

      string nm4=WindowExpertName()+"_ldn_"+(string)(long)time[i];   

      

      ObjectDelete(0,nm1);

      ObjectDelete(0,nm2);      

      ObjectDelete(0,nm3);           

      ObjectDelete(0,nm4); 

           

      if(m0>s0 && m1<=s1){

         mup.Set(nm1,time[i],low[i]);

      }

      if(m0<s0 && m1>=s1){

         mdn.Set(nm2,time[i],high[i]);         

      }      

      

      if(m0>L && m1<=L){

         lup.Set(nm3,time[i],low[i]);

      }

      if(m0<(100-L) && m1>=(100-L)){

         ldn.Set(nm3,time[i],high[i]); 

      }      

      

      

   }



   ChartRedraw();



   return(rates_total);

  }

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





class CObj{

   protected:

      uint width,height,pixels[];   

      string arr, rname;

      ENUM_ANCHOR_POINT anc;

   public:   

   void Init(int id,uchar ArrowCode=233,ENUM_ANCHOR_POINT anchor=ANCHOR_UPPER,uint VShift=0, int FontSize=12,color Color=clrAqua,uchar Alpha=255){   

      width=FontSize*2;

      height=FontSize*2+VShift;

      arr=CharToStr(ArrowCode);      

      anc=anchor;

      rname="::resource_"+(string)id; 

      color col=((uchar(Alpha)<<24)|(uchar(Color&0x000000FF)<<16)|(uchar((Color>>8)&0x000000FF)<<8)|uchar((Color>>16)&0x000000FF));            

      ArrayResize(pixels,width*height);

      ArrayInitialize(pixels,((uchar(0)<<24)|(uchar(Color&0x000000FF)<<16)|(uchar((Color>>8)&0x000000FF)<<8)|uchar((Color>>16)&0x000000FF)));      

      TextSetFont("Wingdings",-FontSize*10,FW_NORMAL,0);           

      if(anc==ANCHOR_UPPER){

         TextOut(arr,width/2,VShift,TA_CENTER|TA_TOP,pixels,width,height,col,COLOR_FORMAT_ARGB_NORMALIZE); 

      }

      else{

         TextOut(arr,width/2,height-VShift,TA_CENTER|TA_BOTTOM,pixels,width,height,col,COLOR_FORMAT_ARGB_NORMALIZE);       

      }        

   } 

   void Set(string nm,datetime tm,double pr){   

      ObjectCreate(0,nm,OBJ_BITMAP,0,0,0);

      ObjectSetInteger(0,nm,OBJPROP_TIME,0,tm);

      ObjectSetDouble(0,nm,OBJPROP_PRICE,0,pr);    

      ObjectSetInteger(0,nm,OBJPROP_SELECTABLE,false);        

      ObjectSetInteger(0,nm,OBJPROP_ANCHOR,anc);    

      ObjectSetString(0,nm,OBJPROP_BMPFILE,rname);        

      ResourceCreate(rname,pixels,width,height,0,0,0,COLOR_FORMAT_ARGB_NORMALIZE);

   }  

};



CObj mup;

CObj mdn;



CObj lup;

CObj ldn;

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