Author: TheXpert
Indicators Used
Larry William percent range indicator
0 Views
0 Downloads
0 Favorites
Toned_WPR
//+------------------------------------------------------------------+
//|                                                    Toned_WPR.mq5 |
//|                                               Copyright TheXpert |
//|                                           theforexpert@gmail.com |
//+------------------------------------------------------------------+
#property copyright "TheXpert"
#property link      "theforexpert@gmail.com"
#property version   "1.00"

#property indicator_separate_window

#property indicator_minimum -100
#property indicator_maximum 0

#property indicator_buffers 2
#property indicator_plots   1

#property indicator_type1   DRAW_COLOR_LINE

#define C Red
#property indicator_color1  C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C

#property indicator_width1  2

#include <Color.mqh>

input int WPRPeriod = 15;

input int ColorsCount = 63;

input color Lower = Red;
input color Higher = Blue;

double Values[];
double Color[];

int WPRHandle;

void OnInit()
{
   SetIndexBuffer(0, Values,           INDICATOR_DATA);
   SetIndexBuffer(1, Color,            INDICATOR_COLOR_INDEX);
   
   PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, WPRPeriod);
   FillColorTable(0, Lower, Higher, ColorsCount);

   IndicatorSetString(INDICATOR_SHORTNAME, "Toned WPR(" + string(WPRPeriod) + ")");
   
   PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, EMPTY_VALUE);
   PlotIndexSetInteger(0, PLOT_SHOW_DATA, false);

   WPRHandle = iWPR(NULL, 0, WPRPeriod);

   ArraySetAsSeries(Values, true);
   ArraySetAsSeries(Color, true);
}

int OnCalculate(
      const int         bars,
      const int         counted,
      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 copied = CopyBuffer(WPRHandle, 0, 0, bars, Values);
   int err = GetLastError();

   if (-1 == copied)
   {
      if (4806 == err)
      {
         for (int i = 0; i < 1000; ++i)
         {
            if (BarsCalculated(WPRHandle) > 0) break;
         }
         copied = CopyBuffer(WPRHandle, 0, 0, bars, Values);
         err = GetLastError();
      }
   }

   if (-1 == copied)
   {
      Print("Error when trying to get WPR values, last error is ", err, " bars ", bars);
      return 0;
   }
   
   int toCount = bars - (int)MathMax(counted - 1, 0);
   
   for (int i = toCount - 1; i >= 0; --i)
   {
      Color[i] = 0;
      
      if (Values[i] == EMPTY_VALUE) continue;
      
      int index = (int)((Values[i] + 100)/100*ColorsCount);
      if (index >= ColorsCount)   index = ColorsCount - 1;
      if (index < 0)    index = 0;
      
      Color[i] = index;
   }
   return(bars);
}

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