VolumeVolatilityBounceSignals

Author: Scriptong
Indicators Used
Indicator of the average true range
Miscellaneous
It issuies visual alerts to the screenImplements a curve of type %1
0 Views
0 Downloads
0 Favorites
VolumeVolatilityBounceSignals
ÿþ#property copyright "Scriptong"

#property link      "http://advancetools.net"

#property description "Displays trade signals by volatility bounce method."



#property  strict



#property indicator_chart_window

#property indicator_buffers 2

#property indicator_color1 clrBlue

#property indicator_color2 clrRed



#property indicator_width1 1

#property indicator_width2 1



enum ENUM_YESNO

{

    YES,                                                                                           // Yes

    NO                                                                                             // No

};





input uint      i_volatilityAveragePeriod  = 24;           // Volatility average period

input ENUM_APPLIED_PRICE i_usePrice        = PRICE_TYPICAL;// Candle price

input double    i_highVolatilityRatio      = 3.0;          // Average volatility ratio

input ENUM_YESNO i_useAlert                = NO;           // Alert on signal?

input ENUM_YESNO i_usePush                 = NO;           // Notification on signal?

input int       i_indBarsCount             = 5000;         // Number of bars to display



double g_tickSize;



                                                                                                   

double g_buySignal[];

double g_sellSignal[];



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

//| Custom indicator initialization function                                                               |

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

int OnInit()

{

   g_tickSize = MarketInfo(Symbol(), MODE_TICKSIZE);

   

   if (!IsTuningParametersCorrect())                                                               

      return (INIT_FAILED);                                 

      

   if (!BuffersBind())

      return (INIT_FAILED);                                                   

      

   return (INIT_SUCCEEDED);

}

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

//| @>25@:0 :>@@5:B=>AB8 =0AB@>5G=KE ?0@0<5B@>2                                                           |

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

bool IsTuningParametersCorrect()

{

   string name = WindowExpertName();



   if (i_volatilityAveragePeriod == 0)

   {

      Alert(name, ":  volatility average period must be great than zero. Indicator is turned off.");

      return (false);

   }

   

   if (g_tickSize <= 0)

   {

      Alert(name, ": terminal fatal error - size of tick is nonpositive. Indicator is turned off.");

      return (false);

   }



   return (true);

}

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

//| Custom indicator deinitialization function                                                             |

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

void OnDeinit(const int reason)

{

}

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

//| !2O7K20=85 1CD5@>2 8=48:0B>@0 A <0AA820<8                                                              |

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

bool BuffersBind()

{

   string name = WindowExpertName();



   if (!SetIndexBuffer(0, g_buySignal)             ||

       !SetIndexBuffer(1, g_sellSignal))

   {

      Alert(name, ": buffers binding error N", GetLastError());

      return (false);

   }



   for (int i = 0; i < 2; i++)   

      SetIndexStyle(i, DRAW_ARROW);

      

   SetIndexArrow(0, SYMBOL_ARROWUP);

   SetIndexArrow(1, SYMBOL_ARROWDOWN);

   

   return (true);

}

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

//| =8F80;870F8O 1CD5@>2 8=48:0B>@0                                                                       |

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

void BuffersInitialize()

{

   ArrayInitialize(g_buySignal, EMPTY_VALUE);

   ArrayInitialize(g_sellSignal, EMPTY_VALUE);

}

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

//| ?@545;5=85 8=45:A0 10@0, A :>B>@>3> =5>1E>48<> ?@>872>48BL ?5@5@0AG5B                                 |

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

int GetRecalcIndex(int& total, const int ratesTotal, const int prevCalculated)

{

   total = ratesTotal - 4;                                                                         

                                                   

   if (i_indBarsCount > 0 && i_indBarsCount < total)

      total = MathMin(i_indBarsCount, total);                      

                                                   

   if (prevCalculated < ratesTotal - 1)                     

   {                                               

      BuffersInitialize();

      return (total);

   }

   

   return (MathMin(ratesTotal - prevCalculated, total));                            

}

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

//| >;CG5=85 A@54=59 F5=K A25G8                                                                           |

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

double GetPrice(int index)

{

   switch (i_usePrice)

   {

      case PRICE_CLOSE:    return (Close[index]);

      case PRICE_OPEN:     return (Open[index]);

      case PRICE_HIGH:     return (High[index]);

      case PRICE_LOW:      return (Low[index]);

      case PRICE_MEDIAN:   return ((High[index] + Low[index]) / 2);

      case PRICE_TYPICAL:  return ((High[index] + Low[index] + Close[index]) / 3);

      case PRICE_WEIGHTED: return ((High[index] + Low[index] + 2 * Close[index]) / 4);

   }

   

   return (Close[index]);

}

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

//|  0AG5B A@54=59 8 548=8G=>9 2>;0B8;L=>AB59, F5= B5:CI53> 8 ?@54K4CI53> 10@>2                            |

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

void CalcVolatilitysPricesAndVolumes(int barIndex, double& price[], double& volatilityUnit[], 

                                     long& volume[], double& volatilityAverage, double& highVolatilityAverage)

{

   volatilityAverage = iATR(NULL, 0, i_volatilityAveragePeriod, barIndex + 2);

   highVolatilityAverage = volatilityAverage * i_highVolatilityRatio;



   int index = barIndex + 1;

   for (int cnt = 0; cnt < 3; cnt++)

   {

      price[cnt] = GetPrice(index);

      volatilityUnit[cnt] = High[index] - Low[index];

      volume[cnt] = Volume[index];

      index++;

   }

}

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

//| B>1@065=85 >:=0 Alert                                                                                 |          

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

void SendAlert(string signalType)

{

   static datetime lastAlert = 0;

   if (lastAlert == Time[0])

      return;

      

   lastAlert = Time[0];

   

   string str = WindowExpertName() + " (" + Symbol() + "): signal " + signalType + ".";

   if (i_useAlert == YES)

      Alert(str);

      

   if (i_usePush == YES)

      SendNotification(str);

}

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

//| 5@2>5 G8A;> 1>;LH5 G5< 2B>@>5 (first > second)?                                                       |

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

bool IsFirstMoreThanSecond(double first, double second)

{

   return (first - second > Point / 10);

}

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

//| >;LH5 ;8 8;8 @02=> ?5@2>5 G8A;> ?> >B=>H5=8N :> 2B>@><C?                                              |

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

bool IsFirstEqualOrMoreThanSecond(double first, double second)

{

   return (first - second > - Point / 100);

}

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

//| 5=5@0F8O A83=0;0 >B:@KB8O A45;:8                                                                      |

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

void GenerateOpenSignal(int barIndex, double& price[], double& volatilityUnit[], long& volume[], 

                        double volatilityAverage, double highVolatilityAverage)

{

   if (IsFirstEqualOrMoreThanSecond(volatilityAverage, volatilityUnit[1]) || 

       IsFirstEqualOrMoreThanSecond(volatilityUnit[2], volatilityUnit[1]) ||

       IsFirstEqualOrMoreThanSecond(highVolatilityAverage, volatilityUnit[1]) ||

       volume[2] >= volume[1] || volume[0] >= volume[1])

      return;



   double delta = g_tickSize * 0.99;                                                               

   if (IsFirstMoreThanSecond(price[1], price[0] + delta) && 

       IsFirstMoreThanSecond(price[2], price[1] + delta))

   {

      g_buySignal[barIndex] = Low[barIndex] - iATR(NULL, 0, 14, barIndex); 

      if (barIndex == 0)

         SendAlert("?>:C?:8");

      return; 

   }



   if (IsFirstMoreThanSecond(price[0], price[1] + delta) && 

       IsFirstMoreThanSecond(price[1], price[2] + delta))

   {

      g_sellSignal[barIndex] = High[barIndex] + iATR(NULL, 0, 14, barIndex); 

      if (barIndex == 0)

         SendAlert("?@>4068");

   }

}

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

//| 1@01>B:0 40==KE >4=>3> 10@0                                                                           |

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

void ProcessOneBar(int barIndex)

{

   double price[3], volatilityUnit[3], volatilityAverage, highVolatilityAverage;

   long volume[3];

   CalcVolatilitysPricesAndVolumes(barIndex, price, volatilityUnit, volume, volatilityAverage, highVolatilityAverage);



   GenerateOpenSignal(barIndex, price, volatilityUnit, volume, volatilityAverage, highVolatilityAverage);

}

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

//| B>1@065=85 40==KE 8=48:0B>@0                                                                          |

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

void ShowIndicatorData(int limit, int total)

{

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

      ProcessOneBar(i);

}

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

//| 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 total;   

   int limit = GetRecalcIndex(total, rates_total, prev_calculated);                           



   ShowIndicatorData(limit, total);                                                           

   

   return(rates_total);

}

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