StochTxt(komposter)2007

Author: Copyright � 2007, komposter
StochTxt(komposter)2007
Indicators Used
Stochastic oscillatorIndicator of the average true range
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screen
1 Views
0 Downloads
0 Favorites
StochTxt(komposter)2007
//+------------------------------------------------------------------+
//|                                     iStochTxt(komposter)2007.mq4 |
//|                                      Copyright © 2007, komposter |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, komposter"
//----
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_color2 Red
#property indicator_width1 1
#property indicator_width2 1
//----
extern int        k                = 5;
extern int        s                = 3;
extern double    up_l            = 80;
extern double    dn_l            = 20;
extern bool        text            = false;
extern color    text_color    = Yellow;
extern bool        alert            = false;
//----
double BuyBuffer[], SellBuffer[];
int pre_signal = 0;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init()
  {
      IndicatorShortName("iStochTxt");
//----
      SetIndexBuffer(0, BuyBuffer);
      SetIndexLabel(0, "Buy");
      SetIndexStyle(0, DRAW_ARROW, STYLE_SOLID, 1);
      SetIndexArrow(0, 241);
//----
      SetIndexBuffer(1, SellBuffer);
      SetIndexLabel(1, "Sell");
      SetIndexStyle(1, DRAW_ARROW, STYLE_SOLID, 1);
      SetIndexArrow(1, 242);
//----
      return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int deinit()
  {
      if(text)
        {
             for(int i = 0; i < ObjectsTotal(); i++)
               {
                    if(StringFind( ObjectName(i), "txt_", 0 ) == 0)
                      {
                           ObjectDelete(ObjectName(i));
                           i--;
                      }
               }
        }
      return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
      int counted_bars = IndicatorCounted();
//----
      if(counted_bars < 0) 
        { 
          Print("Indicator Error (Counted bars < 0)!"); 
          return(-1); 
        }
//----
      if(Bars < 17) 
        { 
          Print("Indicator Error (Bars < 12)!" ); 
          return(-1); 
        }
   int limit = Bars - 17;
//----
   if(counted_bars > 17) 
     { 
       limit = Bars - counted_bars; 
     }
//----
      for(int i = limit; i >= 0; i --)
        {
             BuyBuffer[i] = EMPTY_VALUE;
             SellBuffer[i] = EMPTY_VALUE;      
             //----
                double mc = iStochastic(NULL, 0, k, 3, s, 0, 0, MODE_MAIN, i);
                 double mp = iStochastic(NULL, 0, k, 3, s, 0, 0, MODE_MAIN, i+1);
             //----
           if(mc > dn_l && mp <= dn_l)
               {
                    BuyBuffer[i] = Low[i] - iATR(NULL, 0, 14, i);
                    if(text) 
                      { 
                        create_text(i, Low[i] - 1.5*iATR(NULL, 0, 14, i )); 
                      }
               }
             if(mc < up_l && mp >= up_l)
               {
                    SellBuffer[i] = High[i] + iATR(NULL, 0, 14, i);         
                    if(text) 
                      { 
                        create_text(i, High[i] + 1.5*iATR( NULL, 0, 14, i)); 
                      }
               }
        }
      if(alert)
        {
             if(pre_signal <= 0 && BuyBuffer [1] != EMPTY_VALUE) 
               { 
                 Alert("iStochTxt( ", Symbol(), ", ", Period(), " ) - BUY!"); 
                 pre_signal =  1; 
               }
             if(pre_signal >= 0 && SellBuffer[1] != EMPTY_VALUE) 
               { 
                 Alert("iStochTxt( ", Symbol(), ", ", Period(), " ) - SELL!"); 
                 pre_signal = -1; 
               }
        }
      return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void create_text(int u, double p)
  {
      string name = "txt_" + Time[u];
      ObjectDelete(name);
      ObjectCreate(name, OBJ_TEXT, 0, Time[u], p);
      ObjectSetText(name, DoubleToStr( Close[u], Digits ) + " " + TimeToStr( Time[u], 
                    TIME_MINUTES), 8, "Arial", text_color);
  }
//+------------------------------------------------------------------+

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