last ...
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
|
||||
// © LonesomeTheBlue
|
||||
|
||||
//@version=4
|
||||
study("Cumulative Delta Volume", "CDV")
|
||||
linestyle = input(defval = 'Candle', title = "Style", options = ['Candle', 'Line'])
|
||||
hacandle = input(defval = true, title = "Heikin Ashi Candles?")
|
||||
showma1 = input(defval = false, title = "SMA 1", inline = "ma1")
|
||||
ma1len = input(defval = 50, title = "", minval = 1, inline = "ma1")
|
||||
ma1col = input(defval = color.lime, title = "", inline = "ma1")
|
||||
showma2 = input(defval = false, title = "SMA 2", inline = "ma2")
|
||||
ma2len = input(defval = 200, title = "", minval = 1, inline = "ma2")
|
||||
ma2col = input(defval = color.red, title = "", inline = "ma2")
|
||||
showema1 = input(defval = false, title = "EMA 1", inline = "ema1")
|
||||
ema1len = input(defval = 50, title = "", minval = 1, inline = "ema1")
|
||||
ema1col = input(defval = color.lime, title = "", inline = "ema1")
|
||||
showema2 = input(defval = false, title = "EMA 2", inline = "ema2")
|
||||
ema2len = input(defval = 200, title = "", minval = 1, inline = "ema2")
|
||||
ema2col = input(defval = color.red, title = "", inline = "ema2")
|
||||
colorup = input(defval = color.lime, title = "Body", inline = "bcol")
|
||||
colordown = input(defval = color.red, title = "", inline = "bcol")
|
||||
bcolup = input(defval = #74e05e, title = "Border", inline = "bocol")
|
||||
bcoldown = input(defval = #ffad7d, title = "", inline = "bocol")
|
||||
wcolup = input(defval = #b5b5b8, title = "Wicks", inline = "wcol")
|
||||
wcoldown = input(defval = #b5b5b8, title = "", inline = "wcol")
|
||||
|
||||
tw = high - max(open, close)
|
||||
bw = min(open, close) - low
|
||||
body = abs(close - open)
|
||||
|
||||
_rate(cond) =>
|
||||
ret = 0.5 * (tw + bw + (cond ? 2 * body : 0)) / (tw + bw + body)
|
||||
ret := nz(ret) == 0 ? 0.5 : ret
|
||||
ret
|
||||
|
||||
deltaup = volume * _rate(open <= close)
|
||||
deltadown = volume * _rate(open > close)
|
||||
delta = close >= open ? deltaup : -deltadown
|
||||
cumdelta = cum(delta)
|
||||
float ctl = na
|
||||
float o = na
|
||||
float h = na
|
||||
float l = na
|
||||
float c = na
|
||||
if linestyle == 'Candle'
|
||||
o := cumdelta[1]
|
||||
h := max(cumdelta, cumdelta[1])
|
||||
l := min(cumdelta, cumdelta[1])
|
||||
c := cumdelta
|
||||
ctl
|
||||
else
|
||||
ctl := cumdelta
|
||||
|
||||
plot(ctl, title = "CDV Line", color = color.blue, linewidth = 2)
|
||||
|
||||
float haclose = na
|
||||
float haopen = na
|
||||
float hahigh = na
|
||||
float halow = na
|
||||
haclose := (o + h + l + c) / 4
|
||||
haopen := na(haopen[1]) ? (o + c) / 2 : (haopen[1] + haclose[1]) / 2
|
||||
hahigh := max(h, max(haopen, haclose))
|
||||
halow := min(l, min(haopen, haclose))
|
||||
|
||||
c_ = hacandle ? haclose : c
|
||||
o_ = hacandle ? haopen : o
|
||||
h_ = hacandle ? hahigh : h
|
||||
l_ = hacandle ? halow : l
|
||||
|
||||
plotcandle(o_, h_, l_, c_, title='CDV Candles', color = o_ <= c_ ? colorup : colordown, bordercolor = o_ <= c_ ? bcolup : bcoldown, wickcolor = o_ <= c_ ? bcolup : bcoldown)
|
||||
|
||||
plot(showma1 and linestyle == "Candle" ? sma(c_, ma1len) : na, title = "SMA 1", color = ma1col)
|
||||
plot(showma2 and linestyle == "Candle" ? sma(c_, ma2len) : na, title = "SMA 2", color = ma2col)
|
||||
plot(showema1 and linestyle == "Candle" ? ema(c_, ema1len) : na, title = "EMA 1", color = ema1col)
|
||||
plot(showema2 and linestyle == "Candle" ? ema(c_, ema2len) : na, title = "EMA 2", color = ema2col)
|
||||
@@ -0,0 +1,37 @@
|
||||
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
|
||||
// © Ankit_1618
|
||||
|
||||
//@version=4
|
||||
study("Cumulative Volume Delta")
|
||||
|
||||
upper_wick = close>open ? high-close : high-open
|
||||
lower_wick = close>open ? open-low : close-low
|
||||
spread = high-low
|
||||
body_length = spread - (upper_wick + lower_wick)
|
||||
|
||||
percent_upper_wick = upper_wick/spread
|
||||
percent_lower_wick = lower_wick/spread
|
||||
percent_body_length = body_length/spread
|
||||
|
||||
|
||||
buying_volume = close>open ? (percent_body_length + (percent_upper_wick + percent_lower_wick)/2)*volume : ((percent_upper_wick + percent_lower_wick)/2) * volume
|
||||
selling_volume = close<open ? (percent_body_length + (percent_upper_wick + percent_lower_wick)/2)*volume : ((percent_upper_wick + percent_lower_wick)/2) * volume
|
||||
|
||||
cumulation_length = input(14)
|
||||
cumulative_buying_volume = ema(buying_volume,cumulation_length)
|
||||
cumulative_selling_volume = ema(selling_volume,cumulation_length)
|
||||
|
||||
fill_color = cumulative_buying_volume > cumulative_selling_volume ? color.green : cumulative_buying_volume < cumulative_selling_volume ? color.red : color.yellow
|
||||
|
||||
pb = plot(cumulative_buying_volume, color=color.green , transp=70)
|
||||
ps = plot(cumulative_selling_volume, color=color.red , transp=70)
|
||||
|
||||
fill(pb, ps, color = fill_color)
|
||||
|
||||
volume_strength_wave = cumulative_buying_volume > cumulative_selling_volume ? cumulative_buying_volume : cumulative_selling_volume
|
||||
ema_volume_strength_wave = ema(volume_strength_wave , cumulation_length)
|
||||
plot(ema_volume_strength_wave, color=color.gray, transp=80)
|
||||
|
||||
cumulative_volume_delta = cumulative_buying_volume - cumulative_selling_volume
|
||||
plot(cumulative_volume_delta, color= cumulative_volume_delta>0 ? color.green : color.red, style=plot.style_columns, transp=61)
|
||||
|
||||
@@ -0,0 +1,573 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Ocillator
|
||||
// -------------------------------------------------
|
||||
// Name: X121 XCDV
|
||||
// Description: Detect Comulative Delta Volume ...
|
||||
//
|
||||
//
|
||||
// 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 XCDV Ocillator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
#define ShortName "X121_XCDV"
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Makret ...
|
||||
input group "Market";
|
||||
input int maLength = 14; // Moving Averge Length
|
||||
input ENUM_X_PRICE maAppliedTo = X_PRICE_CLOSE; // Moving Averge Applied To
|
||||
input ENUM_X_MA_METHOD maMethod = X_MA_MODE_EMA; // Moving Averge Method
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
input group "Presentation";
|
||||
input int startCalculationForLastBars = 1000; // Calculate Last n Bars
|
||||
input bool showCDV = true; // Show Delta Line
|
||||
input bool showMA = true; // Show Delta Histogram
|
||||
|
||||
//
|
||||
// Buffers Props ...
|
||||
|
||||
//
|
||||
#property indicator_separate_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 10
|
||||
#property indicator_plots 2
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define bullishColorIDX 1
|
||||
#define bearishColorIDX 2
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#define openBufferIndex 0
|
||||
double openBuffer[];
|
||||
|
||||
//
|
||||
#define highBufferIndex 1
|
||||
double highBuffer[];
|
||||
|
||||
//
|
||||
#define lowBufferIndex 2
|
||||
double lowBuffer[];
|
||||
|
||||
//
|
||||
#define closeBufferIndex 3
|
||||
double closeBuffer[];
|
||||
|
||||
//
|
||||
#define colorBufferIndex 4
|
||||
double colorBuffer[];
|
||||
|
||||
//
|
||||
#define barBufferIndex 0
|
||||
#property indicator_label1 "X121 XCDV Open;X121 XCDV High;X121 XCDV Low;X121 XCDV Close"
|
||||
#property indicator_type1 DRAW_COLOR_CANDLES
|
||||
#property indicator_color1 CLR_NONE, clrLime, clrRed
|
||||
|
||||
//
|
||||
#define maBufferIndex 5
|
||||
double maBuffer[];
|
||||
|
||||
#property indicator_label2 "MA"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrYellow
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
#define mLastBufferIndex 5
|
||||
|
||||
#define priceBufferIndex mLastBufferIndex + 1
|
||||
double priceBuffer[];
|
||||
|
||||
#define deltaBufferIndex mLastBufferIndex + 2
|
||||
double deltaBuffer[];
|
||||
|
||||
#define cumulativeDeltaBufferIndex mLastBufferIndex + 3
|
||||
double cumulativeDeltaBuffer[];
|
||||
|
||||
//
|
||||
// Variables, Properties and etc ...
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
double lastCDV = 0.0;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
/**
|
||||
* Initialize Indicator ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Indicator Handlers ...
|
||||
|
||||
//
|
||||
// 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();
|
||||
IndicatorSetInteger(INDICATOR_DIGITS, 2);
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
/**
|
||||
* De Initialize Indicator ...
|
||||
*
|
||||
* @param reason: Integer, De Initialization Reason ...
|
||||
*/
|
||||
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
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Bars ...
|
||||
*
|
||||
* @param rates_total: Integer, Total Bars on Chart ...
|
||||
* @param prev_calculated: Integer, Total Calculated Bars on Charts ...
|
||||
* @param time: DateTime Array, History of Open Time ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param tick_volume: Long, History of Tick Volumes on Bar ...
|
||||
* @param volume: Long, History of Trade Volumes ...
|
||||
* @param spread: Double, History of Spread Price ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
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[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// 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);
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0)
|
||||
? rates_total
|
||||
: (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(
|
||||
//
|
||||
i,
|
||||
prev_calculated,
|
||||
rates_total,
|
||||
//
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tick_volume //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// Functions ...
|
||||
|
||||
/**
|
||||
* Validate Input Args for Initialization ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = maLength > 0 &&
|
||||
IsValid(maMethod) &&
|
||||
IsValid(maAppliedTo);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract Max Length of Inputs ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(0, maLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
*/
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Define Required Buffers ...
|
||||
*/
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// Plot Buffers ...
|
||||
|
||||
//
|
||||
// CDV ...
|
||||
|
||||
//
|
||||
// Raw Candles Color ...
|
||||
ArraySetAsSeries(colorBuffer, true);
|
||||
SetIndexBuffer(colorBufferIndex, colorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE barDrawType = showCDV ? DRAW_COLOR_CANDLES : DRAW_NONE;
|
||||
|
||||
//
|
||||
// Set EMPTY_VALUE on Candles Buffer ...
|
||||
PlotIndexSetDouble(barBufferIndex, PLOT_EMPTY_VALUE, 0.0);
|
||||
PlotIndexSetInteger(barBufferIndex, PLOT_SHOW_DATA, showCDV);
|
||||
PlotIndexSetInteger(barBufferIndex, PLOT_DRAW_TYPE, barDrawType);
|
||||
|
||||
//
|
||||
// Open ...
|
||||
ArraySetAsSeries(openBuffer, true);
|
||||
SetIndexBuffer(openBufferIndex, openBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
// High ...
|
||||
ArraySetAsSeries(highBuffer, true);
|
||||
SetIndexBuffer(highBufferIndex, highBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
// Close ...
|
||||
ArraySetAsSeries(closeBuffer, true);
|
||||
SetIndexBuffer(closeBufferIndex, closeBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
// Low ...
|
||||
ArraySetAsSeries(lowBuffer, true);
|
||||
SetIndexBuffer(lowBufferIndex, lowBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
// Ma ...
|
||||
ENUM_DRAW_TYPE maDrawType = showMA ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(maBuffer, true);
|
||||
SetIndexBuffer(maBufferIndex, maBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(maBufferIndex, PLOT_EMPTY_VALUE, 0);
|
||||
PlotIndexSetInteger(maBufferIndex, PLOT_SHOW_DATA, showMA);
|
||||
PlotIndexSetInteger(maBufferIndex, PLOT_DRAW_TYPE, maDrawType);
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(priceBuffer, true);
|
||||
SetIndexBuffer(priceBufferIndex, priceBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(deltaBuffer, true);
|
||||
SetIndexBuffer(deltaBufferIndex, deltaBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(cumulativeDeltaBuffer, true);
|
||||
SetIndexBuffer(cumulativeDeltaBufferIndex, cumulativeDeltaBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Custom Buffers ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param tickVolume: Long, History of Tick Volumes on Bar ...
|
||||
*/
|
||||
void CalculateBuffers(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
int barsLimit = startCalculationForLastBars > 0
|
||||
? startCalculationForLastBars
|
||||
: 0;
|
||||
//
|
||||
// bool canCalculate = true;
|
||||
bool canCalculate =
|
||||
barsLimit == 0 ||
|
||||
bar_index <= barsLimit;
|
||||
if (canCalculate)
|
||||
{
|
||||
//
|
||||
CalculateValues(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
FillBuffersZero(bar_index);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
|
||||
*
|
||||
* @param barIndex: Integer ...
|
||||
*/
|
||||
void FillBuffersZero(int barIndex)
|
||||
{
|
||||
//
|
||||
openBuffer[barIndex] = 0.0;
|
||||
highBuffer[barIndex] = 0.0;
|
||||
closeBuffer[barIndex] = 0.0;
|
||||
lowBuffer[barIndex] = 0.0;
|
||||
colorBuffer[barIndex] = hideColorIDX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Vales ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param tickVolume: Long, History of Tick Volumes on Bar ...
|
||||
*/
|
||||
void CalculateValues(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
XOHCL bar;
|
||||
bool has = bar.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index //
|
||||
);
|
||||
if (!has)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
double lowShadow = bar.GetLowShadow();
|
||||
double highShadow = bar.GetHighShadow();
|
||||
double body = bar.GetBody();
|
||||
bool isBullish = bar.IsBullish();
|
||||
bool hasDir = HasDirection(bar.GetDirection());
|
||||
|
||||
//
|
||||
double iRate = 0.5 * (highShadow + lowShadow + (hasDir ? 2 * body : 0)) / (highShadow + lowShadow + body);
|
||||
iRate = iRate <= 0
|
||||
? 0.5
|
||||
: iRate;
|
||||
|
||||
//
|
||||
double iVRate = tickVolume[bar_index] * iRate;
|
||||
double iDelta = isBullish
|
||||
? iVRate
|
||||
: -1 * iVRate;
|
||||
deltaBuffer[bar_index] = iDelta;
|
||||
|
||||
//
|
||||
double iCumulate = lastCDV + iDelta;
|
||||
cumulativeDeltaBuffer[bar_index] = iCumulate;
|
||||
lastCDV = iCumulate;
|
||||
|
||||
//
|
||||
bool isFirstBar =
|
||||
startCalculationForLastBars > 0
|
||||
? bar_index == startCalculationForLastBars
|
||||
: bar_index == ratesTotal;
|
||||
|
||||
//
|
||||
double iO = 0;
|
||||
double iH = 0;
|
||||
double iL = 0;
|
||||
double iC = 0;
|
||||
if (!isFirstBar)
|
||||
{
|
||||
//
|
||||
iO = cumulativeDeltaBuffer[bar_index + 1];
|
||||
iH = MathMax(cumulativeDeltaBuffer[bar_index], cumulativeDeltaBuffer[bar_index + 1]);
|
||||
iL = MathMin(cumulativeDeltaBuffer[bar_index], cumulativeDeltaBuffer[bar_index + 1]);
|
||||
iC = iCumulate;
|
||||
}
|
||||
|
||||
//
|
||||
double iClose = (iO + iH + iL + iC) / 4;
|
||||
double iOpen = isFirstBar
|
||||
? (iO + iC) / 2
|
||||
: (openBuffer[bar_index + 1] + closeBuffer[bar_index + 1]) / 2;
|
||||
double iLow = MathMin(iL, MathMin(iOpen, iClose));
|
||||
double iHigh = MathMax(iH, MathMax(iOpen, iClose));
|
||||
|
||||
//
|
||||
lowBuffer[bar_index] = iLow;
|
||||
openBuffer[bar_index] = iOpen;
|
||||
highBuffer[bar_index] = iHigh;
|
||||
closeBuffer[bar_index] = iClose;
|
||||
|
||||
//
|
||||
bool isCBullish = iOpen <= iClose;
|
||||
double iColor = isCBullish
|
||||
? bullishColorIDX
|
||||
: bearishColorIDX;
|
||||
colorBuffer[bar_index] = iColor;
|
||||
|
||||
//
|
||||
double iPrice = GetAppliedPrice(
|
||||
maAppliedTo,
|
||||
openBuffer,
|
||||
highBuffer,
|
||||
lowBuffer,
|
||||
closeBuffer,
|
||||
bar_index //
|
||||
);
|
||||
priceBuffer[bar_index] = iPrice;
|
||||
|
||||
//
|
||||
// Calculate Moving Averages ...
|
||||
int deltaMAsCount = iMAOnBuffer(
|
||||
ratesTotal,
|
||||
prevCalculated,
|
||||
bar_index,
|
||||
maLength,
|
||||
priceBuffer,
|
||||
maBuffer,
|
||||
maMethod //
|
||||
);
|
||||
|
||||
//
|
||||
bar.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
Reference in New Issue
Block a user