Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
Dots_v1
ÿþ//+------------------------------------------------------------------+

//|Based on NonLagDOT.mq4 by TrendLaboratory                         |

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



#property version   "1.02"

#property strict



#property description "Uses price curve angle calculations to come up with simple price indication."

#property description "Simple strategy: enter when 2 dots of same color appear; exit, when different color dot appears."



#property indicator_chart_window

#property indicator_buffers 2

#property indicator_color1 clrRoyalBlue

#property indicator_width1 2

#property indicator_color2 clrRed

#property indicator_width2 2



//---- input parameters

extern int    Length       = 10;

extern ENUM_APPLIED_PRICE AppliedPrice = PRICE_CLOSE;

extern int    Filter       = 0;

extern double Deviation    = 0;

extern int    Shift        = 0;



//---- indicator buffers

double UpBuffer[];

double DnBuffer[];



//---- global variables

double Cycle = 4;



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

//| Custom indicator initialization function                         |

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

int init()

{

   SetIndexStyle(0, DRAW_ARROW);

   SetIndexBuffer(0, UpBuffer);

   SetIndexStyle(1, DRAW_ARROW);

   SetIndexBuffer(1, DnBuffer);

   

   SetIndexEmptyValue(0, EMPTY_VALUE);

   SetIndexEmptyValue(1, EMPTY_VALUE);



   SetIndexArrow(0, 159);

   SetIndexArrow(1, 159);



   SetIndexLabel(0, "Up");

   SetIndexLabel(1, "Dn");



   SetIndexShift(0, Shift);

   SetIndexShift(1, Shift);

   

   SetIndexDrawBegin(0, Length * Cycle + Length);

   SetIndexDrawBegin(1, Length * Cycle + Length);



   IndicatorShortName("Dots("+Length+")");

   IndicatorDigits(MarketInfo(Symbol(), MODE_DIGITS));



   return(0);

}



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

//| Dots                                                             |

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

int start()

{

   int    i, shift, counted_bars = IndicatorCounted(), limit, trend = 0;

   double alfa, beta, t, Sum, Weight, g, price, MABuffer_prev = 0, MABuffer = 0;

   double pi = 3.1415926535;    



   double Coeff = 3 * pi;

   double Phase = Length - 1;

   int Len = Length * Cycle + Phase;

   

   if (counted_bars < 0) return(0);

   if (counted_bars > 0) limit = Bars - counted_bars;

   else limit = Bars - Len - 1; 

   

   for (shift = limit; shift >= 0; shift--) 

   {	

      Weight = 0; Sum = 0; t = 0;

       

      for (i = 0; i <= Len - 1; i++)

	   {

         g = 1.0 / (Coeff * t + 1);   

         if (t <= 0.5 ) g = 1;

         beta = MathCos(pi * t);

         alfa = g * beta;

         price = iMA(NULL, 0, 1, 0, MODE_SMA, AppliedPrice, shift + i); 

         Sum += alfa * price;

         Weight += alfa;

         if (t < 1) t += 1.0 / (Phase - 1); 

         else if (t < Len - 1) t += (2 * Cycle - 1) / (Cycle * Length - 1);

      }

      

      if (DnBuffer[shift + 1] != EMPTY_VALUE) MABuffer_prev = DnBuffer[shift + 1];

      else MABuffer_prev = UpBuffer[shift + 1];

      

      if (Weight > 0) MABuffer = (1.0 + Deviation / 100) * Sum / Weight;

   

      if (Filter > 0)

         if (MathAbs(MABuffer - MABuffer_prev) < Filter * Point) MABuffer = MABuffer_prev;

      

      if (MABuffer - MABuffer_prev > Filter * Point) trend = 1; 

      else if (MABuffer_prev - MABuffer > Filter * Point) trend = -1; 



      if (trend > 0)

      {

         UpBuffer[shift] = MABuffer;

         DnBuffer[shift] = EMPTY_VALUE;

      }

      else if (trend < 0)

      {

         DnBuffer[shift] = MABuffer;

         UpBuffer[shift] = EMPTY_VALUE;

      }

      else

      {

         DnBuffer[shift] = DnBuffer[shift + 1];

         UpBuffer[shift] = UpBuffer[shift + 1];

      }

   }



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