last ...
This commit is contained in:
@@ -0,0 +1,192 @@
|
|||||||
|
//+------------------------------------------------------------------+
|
||||||
|
//| SuperTrend.mq5 |
|
||||||
|
//| Copyright 2011, FxGeek |
|
||||||
|
//| http://www.mql5.com |
|
||||||
|
//+------------------------------------------------------------------+
|
||||||
|
#property copyright "Copyright 2011, FxGeek"
|
||||||
|
#property link " http://www.mql5.com"
|
||||||
|
#property version "1.00"
|
||||||
|
#property indicator_chart_window
|
||||||
|
#property indicator_buffers 9
|
||||||
|
#property indicator_plots 2
|
||||||
|
|
||||||
|
#property indicator_label1 "Filling"
|
||||||
|
#property indicator_type1 DRAW_FILLING
|
||||||
|
#property indicator_color1 clrBisque, clrPaleGreen
|
||||||
|
|
||||||
|
#property indicator_label2 "SuperTrend"
|
||||||
|
#property indicator_type2 DRAW_COLOR_LINE
|
||||||
|
#property indicator_color2 clrGreen, clrRed
|
||||||
|
|
||||||
|
input int Periode=10;
|
||||||
|
input double Multiplier=3;
|
||||||
|
input bool Show_Filling=true; // Show as DRAW_FILLING
|
||||||
|
|
||||||
|
double Filled_a[];
|
||||||
|
double Filled_b[];
|
||||||
|
double SuperTrend[];
|
||||||
|
double ColorBuffer[];
|
||||||
|
double Atr[];
|
||||||
|
double Up[];
|
||||||
|
double Down[];
|
||||||
|
double Middle[];
|
||||||
|
double trend[];
|
||||||
|
|
||||||
|
int atrHandle;
|
||||||
|
int changeOfTrend;
|
||||||
|
int flag;
|
||||||
|
int flagh;
|
||||||
|
//+------------------------------------------------------------------+
|
||||||
|
//| Custom indicator initialization function |
|
||||||
|
//+------------------------------------------------------------------+
|
||||||
|
int OnInit()
|
||||||
|
{
|
||||||
|
//--- indicator buffers mapping
|
||||||
|
SetIndexBuffer(0,Filled_a,INDICATOR_DATA);
|
||||||
|
SetIndexBuffer(1,Filled_b,INDICATOR_DATA);
|
||||||
|
SetIndexBuffer(2,SuperTrend,INDICATOR_DATA);
|
||||||
|
SetIndexBuffer(3,ColorBuffer,INDICATOR_COLOR_INDEX);
|
||||||
|
SetIndexBuffer(4,Atr,INDICATOR_CALCULATIONS);
|
||||||
|
SetIndexBuffer(5,Up,INDICATOR_CALCULATIONS);
|
||||||
|
SetIndexBuffer(6,Down,INDICATOR_CALCULATIONS);
|
||||||
|
SetIndexBuffer(7,Middle,INDICATOR_CALCULATIONS);
|
||||||
|
SetIndexBuffer(8,trend,INDICATOR_CALCULATIONS);
|
||||||
|
|
||||||
|
atrHandle=iATR(_Symbol,_Period,Periode);
|
||||||
|
//---
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
//+------------------------------------------------------------------+
|
||||||
|
//| 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 to_copy;
|
||||||
|
if(prev_calculated>rates_total || prev_calculated<0) to_copy=rates_total;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
to_copy=rates_total-prev_calculated;
|
||||||
|
if(prev_calculated>0) to_copy++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(IsStopped()) return(0); //Checking for stop flag
|
||||||
|
if(CopyBuffer(atrHandle,0,0,to_copy,Atr)<=0)
|
||||||
|
{
|
||||||
|
Print("Getting Atr is failed! Error",GetLastError());
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int first;
|
||||||
|
if(prev_calculated>rates_total || prev_calculated<=0) // checking for the first start of calculation of an indicator
|
||||||
|
{
|
||||||
|
first=Periode; // starting index for calculation of all bars
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
first=prev_calculated-1; // starting number for calculation of new bars
|
||||||
|
}
|
||||||
|
for(int i=first; i<rates_total && !IsStopped(); i++)
|
||||||
|
{
|
||||||
|
Middle[i]=(high[i]+low[i])/2;
|
||||||
|
Up[i] = Middle[i] +(Multiplier*Atr[i]);
|
||||||
|
Down[i]= Middle[i] -(Multiplier*Atr[i]);
|
||||||
|
|
||||||
|
if(close[i]>Up[i-1])
|
||||||
|
{
|
||||||
|
trend[i]=1;
|
||||||
|
if(trend[i-1]==-1) changeOfTrend=1;
|
||||||
|
|
||||||
|
}
|
||||||
|
else if(close[i]<Down[i-1])
|
||||||
|
{
|
||||||
|
trend[i]=-1;
|
||||||
|
if(trend[i-1]==1) changeOfTrend=1;
|
||||||
|
}
|
||||||
|
else if(trend[i-1]==1)
|
||||||
|
{
|
||||||
|
trend[i]=1;
|
||||||
|
changeOfTrend=0;
|
||||||
|
}
|
||||||
|
else if(trend[i-1]==-1)
|
||||||
|
{
|
||||||
|
trend[i]=-1;
|
||||||
|
changeOfTrend=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(trend[i]<0 && trend[i-1]>0)
|
||||||
|
{
|
||||||
|
flag=1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
flag=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(trend[i]>0 && trend[i-1]<0)
|
||||||
|
{
|
||||||
|
flagh=1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
flagh=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(trend[i]>0 && Down[i]<Down[i-1])
|
||||||
|
Down[i]=Down[i-1];
|
||||||
|
|
||||||
|
if(trend[i]<0 && Up[i]>Up[i-1])
|
||||||
|
Up[i]=Up[i-1];
|
||||||
|
|
||||||
|
if(flag==1)
|
||||||
|
Up[i]=Middle[i]+(Multiplier*Atr[i]);
|
||||||
|
|
||||||
|
if(flagh==1)
|
||||||
|
Down[i]=Middle[i]-(Multiplier*Atr[i]);
|
||||||
|
|
||||||
|
//-- Draw the indicator
|
||||||
|
if(trend[i]==1)
|
||||||
|
{
|
||||||
|
SuperTrend[i]=Down[i];
|
||||||
|
if(changeOfTrend==1)
|
||||||
|
{
|
||||||
|
SuperTrend[i-1]=SuperTrend[i-2];
|
||||||
|
changeOfTrend=0;
|
||||||
|
}
|
||||||
|
ColorBuffer[i]=0.0;
|
||||||
|
}
|
||||||
|
else if(trend[i]==-1)
|
||||||
|
{
|
||||||
|
SuperTrend[i]=Up[i];
|
||||||
|
if(changeOfTrend==1)
|
||||||
|
{
|
||||||
|
SuperTrend[i-1]= SuperTrend[i-2];
|
||||||
|
changeOfTrend = 0;
|
||||||
|
}
|
||||||
|
ColorBuffer[i]=1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(Show_Filling)
|
||||||
|
{
|
||||||
|
Filled_a[i]= SuperTrend[i];
|
||||||
|
Filled_b[i]= close[i];
|
||||||
|
}else{
|
||||||
|
Filled_a[i]= EMPTY_VALUE;
|
||||||
|
Filled_b[i]= EMPTY_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//--- return value of prev_calculated for next call
|
||||||
|
return(rates_total);
|
||||||
|
}
|
||||||
|
//+------------------------------------------------------------------+
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
//+------------------------------------------------------------------+
|
||||||
|
//| ATR.mq5 |
|
||||||
|
//| Copyright 2009, MetaQuotes Software Corp. |
|
||||||
|
//| http://www.mql5.com |
|
||||||
|
//+------------------------------------------------------------------+
|
||||||
|
#property copyright "2009, MetaQuotes Software Corp."
|
||||||
|
#property link "http://www.mql5.com"
|
||||||
|
#property description "Average True Range"
|
||||||
|
//--- indicator settings
|
||||||
|
#property indicator_separate_window
|
||||||
|
#property indicator_buffers 2
|
||||||
|
#property indicator_plots 1
|
||||||
|
#property indicator_type1 DRAW_LINE
|
||||||
|
#property indicator_color1 DodgerBlue
|
||||||
|
#property indicator_label1 "ATR"
|
||||||
|
//--- input parameters
|
||||||
|
input int InpAtrPeriod=14; // ATR period
|
||||||
|
//--- indicator buffers
|
||||||
|
double ExtATRBuffer[];
|
||||||
|
double ExtTRBuffer[];
|
||||||
|
//--- global variable
|
||||||
|
int ExtPeriodATR;
|
||||||
|
//+------------------------------------------------------------------+
|
||||||
|
//| Custom indicator initialization function |
|
||||||
|
//+------------------------------------------------------------------+
|
||||||
|
void OnInit()
|
||||||
|
{
|
||||||
|
//--- check for input value
|
||||||
|
if(InpAtrPeriod<=0)
|
||||||
|
{
|
||||||
|
ExtPeriodATR=14;
|
||||||
|
printf("Incorrect input parameter InpAtrPeriod = %d. Indicator will use value %d for calculations.",InpAtrPeriod,ExtPeriodATR);
|
||||||
|
}
|
||||||
|
else ExtPeriodATR=InpAtrPeriod;
|
||||||
|
//--- indicator buffers mapping
|
||||||
|
SetIndexBuffer(0,ExtATRBuffer,INDICATOR_DATA);
|
||||||
|
SetIndexBuffer(1,ExtTRBuffer,INDICATOR_CALCULATIONS);
|
||||||
|
//---
|
||||||
|
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
|
||||||
|
//--- sets first bar from what index will be drawn
|
||||||
|
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpAtrPeriod);
|
||||||
|
//--- name for DataWindow and indicator subwindow label
|
||||||
|
string short_name="ATR("+string(ExtPeriodATR)+")";
|
||||||
|
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
|
||||||
|
PlotIndexSetString(0,PLOT_LABEL,short_name);
|
||||||
|
//--- initialization done
|
||||||
|
}
|
||||||
|
//+------------------------------------------------------------------+
|
||||||
|
//| Average True Range |
|
||||||
|
//+------------------------------------------------------------------+
|
||||||
|
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 &TickVolume[],
|
||||||
|
const long &Volume[],
|
||||||
|
const int &Spread[])
|
||||||
|
{
|
||||||
|
int i,limit;
|
||||||
|
//--- check for bars count
|
||||||
|
if(rates_total<=ExtPeriodATR)
|
||||||
|
return(0); // not enough bars for calculation
|
||||||
|
//--- preliminary calculations
|
||||||
|
if(prev_calculated==0)
|
||||||
|
{
|
||||||
|
ExtTRBuffer[0]=0.0;
|
||||||
|
ExtATRBuffer[0]=0.0;
|
||||||
|
//--- filling out the array of True Range values for each period
|
||||||
|
for(i=1;i<rates_total && !IsStopped();i++)
|
||||||
|
ExtTRBuffer[i]=MathMax(High[i],Close[i-1])-MathMin(Low[i],Close[i-1]);
|
||||||
|
//--- first AtrPeriod values of the indicator are not calculated
|
||||||
|
double firstValue=0.0;
|
||||||
|
for(i=1;i<=ExtPeriodATR;i++)
|
||||||
|
{
|
||||||
|
ExtATRBuffer[i]=0.0;
|
||||||
|
firstValue+=ExtTRBuffer[i];
|
||||||
|
}
|
||||||
|
//--- calculating the first value of the indicator
|
||||||
|
firstValue/=ExtPeriodATR;
|
||||||
|
ExtATRBuffer[ExtPeriodATR]=firstValue;
|
||||||
|
limit=ExtPeriodATR+1;
|
||||||
|
}
|
||||||
|
else limit=prev_calculated-1;
|
||||||
|
//--- the main loop of calculations
|
||||||
|
for(i=limit;i<rates_total && !IsStopped();i++)
|
||||||
|
{
|
||||||
|
ExtTRBuffer[i]=MathMax(High[i],Close[i-1])-MathMin(Low[i],Close[i-1]);
|
||||||
|
ExtATRBuffer[i]=ExtATRBuffer[i-1]+(ExtTRBuffer[i]-ExtTRBuffer[i-ExtPeriodATR])/ExtPeriodATR;
|
||||||
|
}
|
||||||
|
//--- return value of prev_calculated for next call
|
||||||
|
return(rates_total);
|
||||||
|
}
|
||||||
|
//+------------------------------------------------------------------+
|
||||||
Binary file not shown.
@@ -0,0 +1,361 @@
|
|||||||
|
//////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// SaherElm IT Center MQL5 Indicator
|
||||||
|
// ---------------------------------------------
|
||||||
|
// Name: X121_XSTR
|
||||||
|
// Description: Super Trend Indicator ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Maintainer:
|
||||||
|
// ------------
|
||||||
|
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||||
|
//
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Global Properties ...
|
||||||
|
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||||
|
#property link "https://saherelm.ir"
|
||||||
|
#property version "1.00"
|
||||||
|
#property description "SaherElm X121_XAMA Indicator"
|
||||||
|
#property strict
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Constants ...
|
||||||
|
//
|
||||||
|
|
||||||
|
#define ShortName "X121_XSTR"
|
||||||
|
|
||||||
|
//
|
||||||
|
// END Constants ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Inputs ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Market ...
|
||||||
|
input group "ATR";
|
||||||
|
input int atrLength = 14; // Length
|
||||||
|
input double atrMultiplier = 3.0; // Multiplier
|
||||||
|
|
||||||
|
//
|
||||||
|
// Presentation ...
|
||||||
|
input group "Presentation";
|
||||||
|
input bool showTrueRange = true; // Show True Range
|
||||||
|
input bool showAverageTrueRange = true; // Show Average True Range
|
||||||
|
|
||||||
|
//
|
||||||
|
// END Inputs ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Includes Common Library ...
|
||||||
|
#include <MovingAverages.mqh>
|
||||||
|
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Buffers ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_separate_window
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_buffers 4
|
||||||
|
#property indicator_plots 4
|
||||||
|
|
||||||
|
//
|
||||||
|
#define atrBUfferIndex 0
|
||||||
|
double atrBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#define atrColorBUfferIndex 1
|
||||||
|
double atrColorBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_label1 "X121_XSTR ATR"
|
||||||
|
#property indicator_type1 DRAW_COLOR_LINE
|
||||||
|
#property indicator_color1 clrGreen, CLR_NONE
|
||||||
|
#property indicator_style1 STYLE_DOT
|
||||||
|
|
||||||
|
//
|
||||||
|
#define trBUfferIndex 2
|
||||||
|
double trBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#define trColorBUfferIndex 3
|
||||||
|
double trColorBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_label2 "X121_XSTR TR"
|
||||||
|
#property indicator_type2 DRAW_COLOR_LINE
|
||||||
|
#property indicator_color2 clrGainsboro, CLR_NONE
|
||||||
|
#property indicator_style2 STYLE_DOT
|
||||||
|
|
||||||
|
//
|
||||||
|
// END Buffers ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Global Definitions: Variables, Properties and etc ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
int maxLength;
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// END Global Definitions: Variables, Properties and etc ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Event Handlers ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Initialization ...
|
||||||
|
int OnInit()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate Inputs ...
|
||||||
|
if (!ValidateInputs())
|
||||||
|
{
|
||||||
|
return INIT_PARAMETERS_INCORRECT;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// because in some cases we may have more than one input for
|
||||||
|
// calculation and we must prevent any calculation
|
||||||
|
// untill we pass the biggest input length, here we get max Input length
|
||||||
|
// and then wait until pass it ...
|
||||||
|
maxLength = ExtractMaxLengthOfInputs();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Define Index Buffers ...
|
||||||
|
DefineBuffers();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Set Indicator ShortName ...
|
||||||
|
SetIndicatorName();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Init Succeed ...
|
||||||
|
return INIT_SUCCEEDED;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// DeInitialization ...
|
||||||
|
void OnDeinit(const int reason)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||||
|
// REASON_REMOVE 1 Program removed from a chart
|
||||||
|
// REASON_RECOMPILE 2 Program recompiled
|
||||||
|
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||||
|
// REASON_CHARTCLOSE 4 Chart closed
|
||||||
|
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||||
|
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||||
|
// REASON_TEMPLATE 7 Another chart template applied
|
||||||
|
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||||
|
// REASON_CLOSE 9 Terminal closed
|
||||||
|
|
||||||
|
//
|
||||||
|
// Here we can handle De Initialization Reasons ...
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculating what we want ...
|
||||||
|
int OnCalculate(
|
||||||
|
//
|
||||||
|
// total Candles on chart ...
|
||||||
|
const int rates_total,
|
||||||
|
//
|
||||||
|
// total calculated Candles on charts ...
|
||||||
|
const int prev_calculated,
|
||||||
|
//
|
||||||
|
// history of Candles Open Time ...
|
||||||
|
const datetime &time[],
|
||||||
|
//
|
||||||
|
// history of Candles Open Price ...
|
||||||
|
const double &open[],
|
||||||
|
//
|
||||||
|
// history of Candles High Price ...
|
||||||
|
const double &high[],
|
||||||
|
//
|
||||||
|
// history of Candles Low Price ...
|
||||||
|
const double &low[],
|
||||||
|
//
|
||||||
|
// history of Candles Close Price ...
|
||||||
|
const double &close[],
|
||||||
|
//
|
||||||
|
// history of Tick Volumes on Candle ...
|
||||||
|
const long &tick_volume[],
|
||||||
|
//
|
||||||
|
// history of Trade Volumes ...
|
||||||
|
const long &volume[],
|
||||||
|
//
|
||||||
|
// history of Candles Spread Price ...
|
||||||
|
const int &spread[])
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Prepare Buffers ...
|
||||||
|
// ArraySetAsSeries(time, true);
|
||||||
|
// ArraySetAsSeries(open, true);
|
||||||
|
// ArraySetAsSeries(high, true);
|
||||||
|
// ArraySetAsSeries(low, true);
|
||||||
|
// ArraySetAsSeries(close, true);
|
||||||
|
// ArraySetAsSeries(tick_volume, true);
|
||||||
|
// ArraySetAsSeries(volume, true);
|
||||||
|
// ArraySetAsSeries(spread, true);
|
||||||
|
|
||||||
|
//
|
||||||
|
// this counts Available Bars ...
|
||||||
|
int limit;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (rates_total <= maxLength)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
if (prev_calculated == 0)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
trBuffer[0] = 0.0;
|
||||||
|
|
||||||
|
//
|
||||||
|
for (int i = 1; i < rates_total && !IsStopped(); i++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
double iTr = MathMax(high[i], close[i - 1]) - MathMin(low[i], close[i - 1]);
|
||||||
|
trBuffer[i] = iTr;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculate First ATR Value ...
|
||||||
|
double firstATRValue = 0.0;
|
||||||
|
for (int i = 1; i < atrLength; i++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
atrBuffer[i] = 0.0;
|
||||||
|
firstATRValue += trBuffer[i];
|
||||||
|
}
|
||||||
|
firstATRValue /= atrLength;
|
||||||
|
atrBuffer[atrLength] = firstATRValue;
|
||||||
|
|
||||||
|
//
|
||||||
|
limit = atrLength + 1;
|
||||||
|
} else {
|
||||||
|
limit = prev_calculated -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Main Loop ...
|
||||||
|
for (int i = limit; i <rates_total && !IsStopped(); i++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Do Buffers Calculation ...
|
||||||
|
|
||||||
|
//
|
||||||
|
trBuffer[i] = MathMax(high[i], close[i - 1]) - MathMin(low[i], close[i - 1]);
|
||||||
|
atrBuffer[i] = atrBuffer[i - 1] + (trBuffer[i] - trBuffer[i - atrLength]) / atrLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return rates_total;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// END Event Handlers ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Functions ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate Input Args for Initialization ...
|
||||||
|
bool ValidateInputs()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate Args ...
|
||||||
|
result =
|
||||||
|
//
|
||||||
|
atrLength >= 2
|
||||||
|
//
|
||||||
|
;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Retrieve all Exists Input Max Length ...
|
||||||
|
// use for Start Of Drawing ...
|
||||||
|
int ExtractMaxLengthOfInputs()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
result = atrLength;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||||
|
void SetIndicatorName()
|
||||||
|
{
|
||||||
|
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Define Indexes and Styles ...
|
||||||
|
void DefineBuffers()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// PLOT Buffers ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// AVERAGETRUERANGE ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Buffer ...
|
||||||
|
// ArraySetAsSeries(atrBuffer, true);
|
||||||
|
SetIndexBuffer(atrBUfferIndex, atrBuffer, INDICATOR_DATA);
|
||||||
|
PlotIndexSetInteger(atrBUfferIndex, PLOT_SHOW_DATA, showAverageTrueRange);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Color ...
|
||||||
|
// ArraySetAsSeries(atrColorBuffer, true);
|
||||||
|
SetIndexBuffer(atrColorBUfferIndex, atrColorBuffer, INDICATOR_COLOR_INDEX);
|
||||||
|
|
||||||
|
//
|
||||||
|
// TRUERANGE ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Buffer ...
|
||||||
|
// ArraySetAsSeries(trBuffer, true);
|
||||||
|
SetIndexBuffer(trBUfferIndex, trBuffer, INDICATOR_DATA);
|
||||||
|
PlotIndexSetInteger(trBUfferIndex, PLOT_SHOW_DATA, showTrueRange);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Color ...
|
||||||
|
// ArraySetAsSeries(trColorBuffer, true);
|
||||||
|
SetIndexBuffer(trColorBUfferIndex, trColorBuffer, INDICATOR_COLOR_INDEX);
|
||||||
|
|
||||||
|
//
|
||||||
|
// DATA Buffers ...
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// END Functions ...
|
||||||
|
//
|
||||||
Reference in New Issue
Block a user