如何在 ThinkOrSwim 平台中单步执行 thinkscript?
How do you step through thinkscript in ThinkOrSwim platform?
我正在 ThinkOrSwim 平台上玩 ThinkScript 代码。特别是 运行 这个工具在 MacOSX 上。我想知道是否有一种调试 ThinkScript 的方法,就像您附加调试器并逐行执行脚本一样。
没有内置调试器。但是,在编写自定义研究时,您可以使用 addchartbubble() 函数在每个柱上显示变量值。
如 所述,thinkScript 没有调试器工具。您可以按照 Gary 的建议使用 图表气泡 和 图表标签 .
Chart bubbles appear at a specified bar when a condition is met. Chart labels满足条件时出现在图表左上角
语法
备注:
- 带空格的参数标签需要双引号;没有空格的不需要引号。
- 如果提供了所有必需参数并且这些参数按预期顺序排列,则不需要参数标签。为了清楚起见,我在此语法描述中展示了它们。
- 参数不必出现在单独的行上。同样,为了清楚起见,我在语法描述中已经这样做了,所以我可以评论参数的含义。
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);
我正在 ThinkOrSwim 平台上玩 ThinkScript 代码。特别是 运行 这个工具在 MacOSX 上。我想知道是否有一种调试 ThinkScript 的方法,就像您附加调试器并逐行执行脚本一样。
没有内置调试器。但是,在编写自定义研究时,您可以使用 addchartbubble() 函数在每个柱上显示变量值。
如
Chart bubbles appear at a specified bar when a condition is met. Chart labels满足条件时出现在图表左上角
语法
备注:
- 带空格的参数标签需要双引号;没有空格的不需要引号。
- 如果提供了所有必需参数并且这些参数按预期顺序排列,则不需要参数标签。为了清楚起见,我在此语法描述中展示了它们。
- 参数不必出现在单独的行上。同样,为了清楚起见,我在语法描述中已经这样做了,所以我可以评论参数的含义。
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);