Hello everyone, today we will learn about this short-term absolute sniping—small-cap QMT strategy Tongdaxin DLL indicator formula source code algorithm. Note:This indicator source code is used for Tongdaxin.The model algorithm in this article is for academic discussion only, and the indicator formula is shared as knowledge for free, “academic deduction based on open-source datasets,” and is only for learning and communication.
01 Indicator Formula Legend
Figure 1
Figure 202 Learning Tongdaxin DLL Code
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
using namespace std;
struct StockData {
double open;
double high;
double low;
double close;
double volume;
};
// Utility functions for short-term low absorption absolute sniping
vector<double> EMA(const vector<double>& data, int period) {
vector<double> ema(data.size());
double multiplier = 2.0 / (period + 1);
// First EMA is just the first data point
ema[0] = data[0];
for (size_t i = 1; i < data.size(); i++) {
ema[i] = (data[i] - ema[i-1]) * multiplier + ema[i-1];
}
return ema;
}
double SMA(const vector<double>& data, int start, int end) {
double sum = 0.0;
for (int i = start; i <= end; i++) {
sum += data[i];
}
return sum / (end - start + 1);
}
double LLV(const vector<double>& low, int start, int period) {
double min_val = low[start];
for (int i = start; i > start - period && i >= 0; i--) {
if (low[i] < min_val) min_val = low[i];
}
return min_val;
}
double HHV(const vector<double>& high, int start, int period) {
double max_val = high[start];
for (int i = start; i > start - period && i >= 0; i--) {
if (high[i] > max_val) max_val = high[i];
}
return max_val;
}
// Main indicator calculation function
void calculateIndicators(const vector<StockData>& data) {
vector<double> close_prices, high_prices, low_prices, volumes;
for (const auto& d : data) {
close_prices.push_back(d.close);
high_prices.push_back(d.high);
low_prices.push_back(d.low);
volumes.push_back(d.volume);
}
int n = data.size();
if (n < 34) {
cout << "Not enough data points (minimum 34 required)" << endl;
return;
}
// Calculate LIJINX indicators
vector<double> lijinx2(n), lijinx3(n), lijinx4(n);
for (int i = 33; i < n; i++) {
lijinx2[i] = LLV(low_prices, i, 33);
if (i >= 20) {
lijinx3[i] = HHV(high_prices, i, 21);
if (lijinx3[i] != lijinx2[i]) {
lijinx4[i] = EMA(vector<double>{
(close_prices[i] - lijinx2[i]) / (lijinx3[i] - lijinx2[i]) * 100
}, 20)[0] * 0.998;
} else {
lijinx4[i] = 0;
}
}
}
// Current safety degree
vector<double> current_safety(n);
for (int i = 1; i < n; i++) {
double ema_input = 0.667 * lijinx4[i-1] + 0.333 * lijinx4[i];
current_safety[i] = 100 - EMA(vector<double>{ema_input}, 1)[0];
}
// A, B, D indicators
vector<double> A(n), B(n), D(n);
for (int i = 33; i < n; i++) {
double hhv_34 = HHV(high_prices, i, 34);
double llv_34 = LLV(low_prices, i, 34);
A[i] = SMA(vector<double>{
-100 * (hhv_34 - close_prices[i]) / (hhv_34 - llv_34)
}, i-18, i)[0];
double hhv_14 = HHV(high_prices, i, 14);
double llv_14 = LLV(low_prices, i, 14);
B[i] = -100 * (hhv_14 - close_prices[i]) / (hhv_14 - llv_14);
D[i] = EMA(vector<double>{
-100 * (hhv_34 - close_prices[i]) / (hhv_34 - llv_34)
}, 4)[0];
}
// Long line, short line, main line
vector<double> long_line(n), short_line(n), main_line(n);
for (int i = 0; i < n; i++) {
long_line[i] = A[i] + 100;
short_line[i] = B[i] + 100;
main_line[i] = D[i] + 100;
}
// Top signals
vector<bool> top_signal(n, false), top_region(n, false);
for (int i = 1; i < n; i++) {
bool condition1 = (main_line[i-1] > 85 && short_line[i-1] > 85 && long_line[i-1] > 65);
bool condition2 = (long_line[i] > short_line[i]);
top_signal[i] = condition1 && condition2;
bool condition3 = (main_line[i] < main_line[i-1] && main_line[i-1] > 80);
bool condition4 = (short_line[i-1] > 95 || (i >= 2 && short_line[i-2] > 95));
bool condition5 = long_line[i] > 60 && short_line[i] < 83.5;
bool condition6 = short_line[i] < main_line[i] && short_line[i] < long_line[i] + 4;
top_region[i] = condition3 && condition4 && condition5 && condition6;
}
// Trading advisor signals
vector<bool> trading_advisor(n, false);
for (int i = 1; i < n; i++) {
bool condition1 = (long_line[i] < 12 && main_line[i] < 8 &&
(short_line[i] < 7.2 || (i >= 1 && short_line[i-1] < 5)) &&&
(main_line[i] > main_line[i-1] || short_line[i] > short_line[i-1]);
bool condition2 = (long_line[i] < 8 && main_line[i] < 7 && short_line[i] < 15 &&
short_line[i] > short_line[i-1]);
bool condition3 = (long_line[i] < 10 && main_line[i] < 7 && short_line[i] < 1);
trading_advisor[i] = condition1 || condition2 || condition3;
}
// Long-short advisor
vector<bool> long_short_advisor(n, false);
for (int i = 1; i < n; i++) {
bool condition1 = (long_line[i] < 15 && long_line[i-1] < 15 && main_line[i] < 18);
bool condition2 = (short_line[i] > short_line[i-1] && short_line[i] > long_line[i]);
bool condition3 = (short_line[i-1] < 5 || (i >= 2 && short_line[i-2] < 5));
bool condition4 = (main_line[i] >= long_line[i] || short_line[i-1] < 1);
long_short_advisor[i] = condition1 && condition2 && condition3 && condition4;
}
// LIJINXR1 - RSI-like indicator
vector<double> lijinxr1(n);
for (int i = 1; i < n; i++) {
double up = max(close_prices[i] - close_prices[i-1], 0.0);
double down = abs(close_prices[i] - close_prices[i-1]);
double up_sma = SMA(vector<double>{up}, i-5, i)[0];
double down_sma = SMA(vector<double>{down}, i-5, i)[0];
if (down_sma != 0) {
lijinxr1[i] = up_sma / down_sma * 100;
} else {
lijinxr1[i] = 0;
}
}
// Breakout signals
vector<bool> breakout_signal(n, false);
vector<double> ma5(n), ma10(n), ma20(n), ma60(n), ma120(n);
for (int i = 0; i < n; i++) {
ma5[i] = SMA(close_prices, max(i-4, 0), i)[0];
ma10[i] = SMA(close_prices, max(i-9, 0), i)[0];
ma20[i] = SMA(close_prices, max(i-19, 0), i)[0];
ma60[i] = SMA(close_prices, max(i-59, 0), i)[0];
ma120[i] = SMA(close_prices, max(i-119, 0), i)[0];
}
for (int i = 1; i < n; i++) {
// Find the last time ma60 > ma20 and (ma20 == ma10 or ma20 > ma10)
int aa1 = 0;
for (int j = i-1; j >= 0; j--) {
if (ma60[j] > ma20[j] && (ma20[j] == ma10[j] || ma20[j] > ma10[j])) {
aa1 = i - j;
break;
}
}
// Check if all closes in this period were below ma60
bool bb1 = true;
for (int j = i-aa1; j < i; j++) {
if (j >= 0 && close_prices[j] >= ma60[j]) {
bb1 = false;
break;
}
}
bool cc1 = (close_prices[i] > ma60[i]) &&
(volumes[i] > SMA(volumes, max(i-4, 0), i)[0]) &&
((close_prices[i] - close_prices[i-1]) / close_prices[i-1] * 100 > 3);
breakout_signal[i] = bb1 && cc1;
}
Risk Warning: This indicator is for technical research and learning communication purposes only. The market has a high degree of uncertainty, and any decisions based on this indicator are at your own risk and do not constitute any investment advice.03 Small-Cap Automated Strategy
def trade(ContextInfo):
#get_rank(C,g.code_list) Short-term absolute sniping—small-cap QMT strategy
# Get the 50 stocks with the lowest market capitalization
target_num = 50
target_list = get_rank(ContextInfo,g.code_list)[:target_num]
print(target_list)
# Get position information
holdings = get_trade_detail_data(ContextInfo.acct, ContextInfo.acct_type, 'position')
# Get a dictionary of stock codes and the number of shares held
holdings = {i.m_strInstrumentID + '.' + i.m_strExchangeID : i.m_nCanUseVolume for i in holdings}
.......

Go with the trend, persist long-term, and do swing trading.


Learning and Sharing
Academic Exchange: We focus on academic exchange and research in the market, includingself-used indicators, zero-lag moving averages, the fastest curves, and automated programquantitativelearning.
Sharing Knowledge: Tian Du Marshal, respect the gods, love others as oneself, I am for everyone, be kind to others, share happiness!
