Last active
August 29, 2019 12:12
-
-
Save dpasca/1caf5ec871ed6430313d65e2b5b56292 to your computer and use it in GitHub Desktop.
Detects a strong price drop in a BTC/USD market.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//================================================================== | |
/// AUT_DumpDetect.h | |
/// | |
/// Created by Davide Pasca - 2019/08/25 | |
/// See the file "license.txt" that comes with this project for | |
/// copyright info. | |
//================================================================== | |
#ifndef AUT_DUMPDETECT_H | |
#define AUT_DUMPDETECT_H | |
#include "AlgoUtils.h" | |
#include "BTT_AUT_TATrend.h" | |
//================================================================== | |
class AUT_DumpDetect | |
{ | |
AUT_TATrend *mpTATask {}; | |
// average volume minute and body length | |
double mAvgMinVol = 0; | |
// reference Time Data count to see if we need to recalc averages | |
size_t mLastCalcTDsN = 0; | |
// 30 seconds trend of Trade Aggregates | |
static constexpr size_t TATREND_SECS_N = 60; | |
// reference scale of volume compared to average | |
static constexpr double REF_VOL_COE = 50; | |
// how many recent candles to skip, to have average values that are not | |
// already influenced by an ongoing dump | |
static constexpr size_t EXCLUDE_RECENT_TDS_N = 60 * 2; | |
// span of minutes to consider to calculate averages | |
static constexpr size_t AVG_SPAN_N = 60 * 2; | |
public: | |
AUT_DumpDetect( AlgoResources &res ) | |
{ | |
// Trade Aggregates indicator operating in the last 30 seconds | |
mpTATask = res.AllocTATrend( TATREND_SECS_N ); | |
} | |
// | |
bool IsDumpingDD( | |
const AlgoAnimPar &par, | |
const DVecView<TimeData> &tds, | |
const TradeAggListView &tas ) | |
{ | |
// update the avergae volume and average candle body length figures | |
updateAvgVals( tds ); | |
// have sme usable average volume ? | |
if NOT( mAvgMinVol ) | |
return false; | |
{ | |
// reference volume in scale of this TATrend | |
// (i.e. for TATrend of 30 secs we scale by 0.5, since avg vol is in minutes) | |
c_auto refVol = mAvgMinVol * REF_VOL_COE * (double)TATREND_SECS_N / 60; | |
// get a Trade Agg. indicator result if the current time span has volume | |
// activity that is at least 50 times that of the average volume | |
c_auto task = mpTATask->CalcTATEntry( tas, refVol ); | |
if NOT( task.IsValidEntry() ) | |
return false; | |
// trend must be down | |
if ( task.mAngDeg > 0 ) | |
return false; | |
} | |
// we passed all checks, we are in a major dump | |
return true; | |
} | |
private: | |
void updateAvgVals( const DVecView<TimeData> &tds ) | |
{ | |
// have new Time Datas ? (candle data) | |
if ( tds.size() == mLastCalcTDsN ) | |
return; | |
// start from 4 back (don't want recent minutes in it, because they | |
// could already be part of the drop and bias the average) | |
c_auto i2 = std::max( tds.size(), EXCLUDE_RECENT_TDS_N ) - EXCLUDE_RECENT_TDS_N; | |
c_auto i1 = std::max( i2, AVG_SPAN_N ) - AVG_SPAN_N; | |
// have the right amount of TDs ? | |
if ( (i2 - i1) != AVG_SPAN_N ) | |
{ | |
mAvgMinVol = 0; | |
return; | |
} | |
// calc average volume | |
mAvgMinVol = std::accumulate( tds.begin() + i1, tds.begin() + i2, 0.0, | |
[]( c_auto acc, c_auto &val ) | |
{ | |
return acc + val.volume_base; | |
}) / (double)AVG_SPAN_N; | |
} | |
}; | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment