StochCandleOverBought-Sold

Author: Copyright � 2007, Christof Risch (iya)
Indicators Used
Stochastic oscillator
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
StochCandleOverBought-Sold
//+------------------------------------------------------------------+
//|                                 Stoch Candle OverBought-Sold.mq4 |
//|                      Copyright © 2006, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
//+------------------------------------------------------------------+
//|                                                 StochCandles.mq4 |
//| Colored Candles, based on Stochastic Signal.							|
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, Christof Risch (iya)"
#property link      "http://www.forexfactory.com/showthread.php?t=13321"
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Green
#property indicator_color2 Red
#property indicator_color3 Green
#property indicator_color4 Red
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 3
#property indicator_width4 3

//---- stoch settings
extern string note1 = "Stochastic settings";
extern double	Stoch_K			= 30.0,
					Stoch_D			= 10.0,
					Stoch_Slowing	= 10.0,
					Upper_Level		= 80,
					Lower_Level		= 20;

//---- input parameters
extern color	BarUp				= Green,
					BarDown			= Red,
					BullCandle		= Green,
					BearCandle		= Red;
extern int		BarWidth			= 1,
					CandleWidth		= 3,
					BarWidth2		= 1,
					CandleWidth2	= 3;

//---- buffers
double Buffer1[];
double Buffer2[];
double Buffer3[];
double Buffer4[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
	SetIndexStyle(0,DRAW_HISTOGRAM,0,BarWidth,BarUp);
	SetIndexStyle(1,DRAW_HISTOGRAM,0,BarWidth,BarDown);
	SetIndexStyle(2,DRAW_HISTOGRAM,0,CandleWidth,BullCandle);
	SetIndexStyle(3,DRAW_HISTOGRAM,0,CandleWidth,BearCandle);
	SetIndexBuffer(0, Buffer1);
	SetIndexBuffer(1, Buffer2);
	SetIndexBuffer(2, Buffer3);
	SetIndexBuffer(3, Buffer4);
	
	return(0);
}

//+------------------------------------------------------------------+
double Stoch_Main  	(int i = 0)	{return(iStochastic(NULL,0,Stoch_K,Stoch_D,Stoch_Slowing,MODE_SMA,0,MODE_MAIN,  i));}
//+------------------------------------------------------------------+
void SetBullCandle(int i = 0)
{
	Buffer1[i] = High[i];
	Buffer2[i] = Low[i];
	Buffer3[i] = MathMax(Open[i],Close[i]);
	Buffer4[i] = MathMin(Open[i],Close[i]);
}

//+------------------------------------------------------------------+
void SetBearCandle(int i = 0)
{
	Buffer1[i] = Low[i];
	Buffer2[i] = High[i];
	Buffer3[i] = MathMin(Open[i],Close[i]);
	Buffer4[i] = MathMax(Open[i],Close[i]);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   int limit=Bars-counted_bars;
   if(counted_bars==0) limit--;

   for(int i=limit; i>=0; i--)
	{
		double	stochMain	= Stoch_Main(i);
				
		bool		bull = (stochMain < Lower_Level),
				   bear = (stochMain > Upper_Level),
					Med =  ((stochMain < Upper_Level)&&(stochMain > 20));

		if(!bull && !bear && !Med)
		{
			bull = (stochMain < Lower_Level);
			bear = (stochMain > Upper_Level	);
			Med =  ((stochMain < Upper_Level	)&&(stochMain > Lower_Level));
		}

		if			(bull)					SetBullCandle(i);
		else if	(bear)					SetBearCandle(i);
	}

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