Author:
iStochTxt
Indicators Used
Stochastic oscillatorIndicator of the average true range
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
iStochTxt
//+------------------------------------------------------------------+
//|                                                    iStochTxt.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_width1 1
#property indicator_width2 1
//----
extern int k = 5, s = 3, l = 20;
extern color txtColor = Brown;
//----
int d=3;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0, DRAW_ARROW, STYLE_SOLID, 1);
   SetIndexArrow(0, 241);
   SetIndexBuffer(0, ExtMapBuffer1);
   SetIndexEmptyValue(0, 0.0);
   SetIndexStyle(1, DRAW_ARROW, STYLE_SOLID, 1);
   SetIndexArrow(1, 242);
   SetIndexBuffer(1, ExtMapBuffer2);
   SetIndexEmptyValue(1, 0.0);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   for(int i = 0; i < ObjectsTotal(); i++)
     {
       if(StringFind(ObjectName(i), "txt_", 0) == 0)
         {
           ObjectDelete(ObjectName(i));
           i--;
         }
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   string on;
   int limit;
	  int counted_bars = IndicatorCounted(); // îïðåäåëèì êîëè÷åñòâî ïðîñ÷èòàíûõ áàðîâ ó èíäèêàòîðà
	  if(counted_bars > 0)
	    {
	      counted_bars--;
	    }	
	  limit = Bars - counted_bars; // îïðåäåëÿåì ãðàíèöó äî êîòîðîé ðàññ÷èòûâàåì çíà÷åíèÿ èíäèêàòîðà
//----
	  for(int i = 0; i < limit; i++)
	    {
       double mc = iStochastic(NULL, 0, k, d, s, 0, 0, MODE_MAIN, i);
       double mp = iStochastic(NULL, 0, k, d, s, 0, 0, MODE_MAIN, i + 1);
       //----
       ExtMapBuffer1[i] = EMPTY_VALUE;
       ExtMapBuffer2[i] = EMPTY_VALUE;      
       //----
       if(mc > l && mp <= l)
         {
           ExtMapBuffer1[i] = Low[i] - iATR(NULL, 0, 14, i);
           on = "txt_" + Time[i];
           ObjectDelete(on);
           ObjectCreate(on, OBJ_TEXT, 0, Time[i], Low[i] - 1.5*iATR(NULL, 0, 14, i));
           ObjectSetText(on, DoubleToStr(Close[i], Digits) + " " + TimeToStr(Time[i], 
                         TIME_MINUTES), 8, "Arial", txtColor);
         }
       if(mc < 100 - l && mp >= 100 - l)
         {
           ExtMapBuffer2[i] = High[i] + iATR(NULL, 0, 14, i);         
           on = "txt_" + Time[i];
           ObjectDelete(on);
           ObjectCreate(on, OBJ_TEXT, 0, Time[i], High[i] + 2*iATR(NULL, 0, 14, i));
           ObjectSetText(on, DoubleToStr(Close[i], Digits) + " " + TimeToStr(Time[i], 
                         TIME_MINUTES), 8, "Arial", txtColor);
         }
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

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