Thinkscript 概率统计研究 - 需要帮助完成

问题描述

我试图计算出如果一只股票在开盘时上涨 0.05 的概率,那么它上涨 0.50 的可能性有多大?遇到了一些小问题。

这个想法来自外汇交易员“TheRumpledOne”。他称之为“Buyzone”。如果你不认识他,就去看看他。将其视为基于概率的开仓范围。

加载代码后,您可以看到数字不应超过“barsago”的长度。

编辑: 想通了。在代码添加了“上面的十字架”。虽然一定有更好、更“干净”的方式?还在这部分代码添加了“...var 和...”,如果确实需要,请确认。

def countsells = Sum( var and var1,barsago);

编辑 2: 这是我当前的问题。 别的东西还是不行。数字好像不对。现在他们看起来很低。我预计有些股票在超过 70% 的时间内会达到开盘价 + .50,但该指标的说法有所不同。

# (Probabilty of XYZ FROM THE LAST / PAST XYZ BARS )
# Original/base code By XeoNoX via Usethinkscript.com
# Idea by TheRumpledOne
# By Prison Mike
input barsago = 100;
input buy= .05;
def buyzone= (open + buy);
def var = close crosses above buyzone;
def count = Sum(var,barsago);
AddLabel (yes,"COUNT " +  (count)  );
def pct= round(count/barsago)*100;
AddLabel (yes,"BuyZone " +  (pct)  );

input Sell= .50;
def sellzone= (open + sell);
def var1 =close crosses above  sellzone;
def countsells = Sum(var and var1,"COUNT " +  (countsells)  );
def pct2=round (countsells/barsago)*100;
AddLabel (yes,"SellZone " +  (pct2)  );

解决方法

修改:它计算显示图表中有多少条柱(注意:TheRumpledOne 的算法是为日内交易设计的)。当开盘价上涨 5 美分时,它会在价格图表上放置一个橙色向上箭头;它会在价格上涨 50 美分的地方放置一个绿色箭头。然后它会显示用于计算百分比值的带有计数、百分比和条形数量(highestBar 值)的标签。

而且,我同意:在 AAPL 图表上,计算大约 360 个 15 分钟的柱线,我得到了 30% 以上的 5 美分,只有大约 3% 的价格上涨了 50 美分。这与条形总数无关;然而,当我添加部分来计算销售数量的百分比时,我仍然只有大约 8%。不在 TheRumpledOne's Stockfetcher post 中建议的数字附近。

注意:我用来测试的图表包括非营业时间柱。也许如果我排除非工作时间,数字看起来会更好?考虑到我在哪里得到箭头,我不这么认为......

修改后的脚本如下:

#hint: from SO: https://stackoverflow.com/q/66232117/1107226\nThinkscript Probabilty Statistics Study- Need help finishing

def highestBar = HighestAll(BarNumber());

### buy zone ###
input buy = .05;
def buyzone = (open + buy);
plot hitBuyZone = close >= buyzone;
hitBuyZone.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
hitBuyZone.setDefaultColor( Color.ORANGE );

def count = if hitBuyZone then count[1] + 1 else count[1];
AddLabel (yes," BUY COUNT: " + count + " ",Color.YELLOW );
def pct = Round(count / highestBar) * 100;
AddLabel (yes," BuyZone %: " + (pct) + " ",Color.YELLOW );

### sell zone ###
input Sell = .50;
def sellzone = (open + Sell);
plot hitSellZone = close >= sellzone;
hitSellZone.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
hitSellZone.SetDefaultColor( Color.GREEN );

def countsells = if hitSellZone then countsells[1] + 1 else countsells[1];
AddLabel (yes," SELL COUNT: " +  (countsells) + " ",Color.YELLOW );
def pct2 = Round (countsells / highestBar) * 100;
AddLabel (yes," SellZone %: " +  (pct2) + " ",Color.YELLOW );

### percent of buy count that made it to the full buyzone cents ###
def pctOfBuyCount = Round (countsells / count) * 100;
AddLabel (yes," Buy Count % of Sell Count: " +  (pctOfBuyCount) + " ",Color.YELLOW );

### show bar count ###
AddLabel(BarNumber() == highestBar," Bars Counted for %: " + BarNumber() + " ",Color.ORANGE);