我在 ThinkOrSwim 平台上玩 ThinkScript 代码。专门在 MacOSX 上运行此工具。我想知道是否有一种方法来调试 ThinkScript,就像您附加调试器并逐行执行脚本一样。
问问题
562 次
2 回答
1
There is no built-in debugger. However, while writing a custom study, you can use the addchartbubble() function to display variables’ values at each bar.
于 2020-12-13T02:21:55.373 回答
0
正如@Gary所指出的,thinkScript 没有调试器工具。您可以按照 Gary 的建议使用图表气泡和图表标签。
满足条件时,图表气泡会出现在指定的柱上。满足条件时,图表标签会出现在图表的左上方。
句法
笔记:
- 带空格的参数标签需要双引号;那些没有空格的不需要引号。
- 当提供了所有必需的参数并且这些参数按预期顺序排列时,不需要参数标签。为了清楚起见,我在这个语法描述中展示了它们。
- 参数不必出现在单独的行上。同样,为了清楚起见,我已经在此语法描述中做到了这一点,因此我可以评论参数的含义。
AddChartBubble("time condition", # condition defining bar where bubble should appear
"price location", # which price should bubble point at (eg, high, low)
text, # text to display in bubble
color, # bubble color
up # display bubble above price (yes) or below it (no)
);
AddLabel(visible, # condition defining whether the label should appear; yes means always
text, # text to display in label
color # label color
);
作为旁注,#hint: ....
当您单击选择列表中的问号时,会显示代码的“帮助”消息。此外,\n
在提示文本中在该点放置一个“换行符”字符。
示例代码:
#hint: Counts a value using an if statement, recursive variable type statement, and a CompoundValue statement.\nDemonstrates using chart bubbles and labels for debugging.
def TrueRange;
if BarNumber() == 1 {
TrueRange = ATR(14)[1];
} else {
TrueRange = TrueRange[1];
}
def tr_rec = if BarNumber() == 1 then tr_rec[1] + 1 else tr_rec[1];
def tr_cmpd = CompoundValue(1, if BarNumber() == 1 then ATR(14)[1] else tr_cmpd[1], Double.NaN);
# plot Data = close; # not req'd if doing only labels and/or bubbles
def numBars = HighestAll(BarNumber());
def halfwayBar = numBars / 2;
# bubble to test a value
AddChartBubble("time condition"=BarNumber() == halfwayBar,
"price location"=high,
text="Bar Number " + BarNumber() + "\n is the halfwayBar (" + halfwayBar + ")",
color=Color.YELLOW,
up=no);
# labels to test values
AddLabel(yes, "# Bars on Chart: " + numBars, Color.YELLOW);
AddLabel(yes, "TrueRange @ bar 1: " + GetValue(TrueRange, numBars - 1), Color.ORANGE);
AddLabel(yes, "TrueRange @ bar " + numBars + ": " + TrueRange, Color.ORANGE);
AddLabel(yes, "tr_rec @ bar 1: " + GetValue(tr_rec, numBars - 1), Color.LIGHT_ORANGE);
AddLabel(yes, "tr_rec @ bar " + numBars + ": " + tr_rec, Color.LIGHT_ORANGE);
AddLabel(yes, "tr_cmpd @ bar 1: " + GetValue(tr_cmpd, numBars - 1), Color.LIGHT_GREEN);
AddLabel(yes, "tr_cmpd @ bar " + numBars + ": " + tr_cmpd, Color.LIGHT_GREEN);
于 2021-03-26T18:13:03.180 回答