-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathauto_vbp_fixes.cpp
72 lines (55 loc) · 2.29 KB
/
auto_vbp_fixes.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "sierrachart.h"
SCDLLName("Frozen Tundra - Auto Volume by Price")
/*
Written by Malykubo and Frozen Tundra in FatCat's Discord Room
*/
SCSFExport scsf_AutoVbP(SCStudyInterfaceRef sc)
{
// helper object
SCString log_message;
// which study to reference
SCInputRef i_StudyRef = sc.Input[0];
// magic number multiplier that will determine the granularity of VP bars we'll see as we switch symbols
// the lower the number, the thicker and fewer bars there will be
// the higher the magic number, the thinner and more VP bars there will be
SCInputRef i_TickMultiplier = sc.Input[1];
SCInputRef useVap = sc.Input[2];
// Configuration
if (sc.SetDefaults)
{
sc.GraphRegion = 0;
i_StudyRef.Name = "Select Target Study";
i_StudyRef.SetStudyID(0);
i_TickMultiplier.Name = "Magic Number Multiplier";
i_TickMultiplier.SetFloat(1.3);
useVap.Name = "Use VAP instead of magic";
useVap.SetYesNo(0);
return;
}
int studyId = i_StudyRef.GetStudyID();
// VbP Ticks Per Volume Bar is input 32, ID 31
int inputIdx = 31;
if (useVap.GetInt() == 1) {
sc.SetChartStudyInputInt(sc.ChartNumber, studyId, inputIdx, sc.VolumeAtPriceMultiplier);
return;
}
float vHigh, vLow, vDiff;
float vMultiplier = i_TickMultiplier.GetFloat();
// fetch the graph's price scale's high and low value so we can automate the Ticks setting on VbP
sc.GetMainGraphVisibleHighAndLow(vHigh, vLow);
// calc the range of visible prices
vDiff = (vHigh - vLow);
// divide range by magic number to get the desired VbP Ticks Per Bar value
int targetTicksPerBar = max(sc.Round(vDiff / vMultiplier), 1);
int prevValue;
sc.GetChartStudyInputInt(sc.ChartNumber, studyId, inputIdx, prevValue);
// require at least a 20% change before updating the VbP study
if (abs(prevValue - targetTicksPerBar) > (targetTicksPerBar * 0.20)) {
// don't allow a Ticks Per Bar value of less than 1
if (targetTicksPerBar < 1) {
targetTicksPerBar = 1;
}
sc.SetChartStudyInputInt(sc.ChartNumber, studyId, inputIdx, targetTicksPerBar);
sc.RecalculateChart(sc.ChartNumber);
}
}