我想在 quantstrat 中添加自定义指标,但此指标不是根据价格系列计算的。例如:
# Get SPY from Yahoo Finance
getSymbols("SPY", from = "2016-01-01", to = "2016-01-31", src = "yahoo", adjust = TRUE)
SPY <- SPY[,1:4]
#Create Indicator
set.seed(123)
indicator <- sample(seq(from = 0, to = 100, by = 5), size = nrow(SPY), replace = TRUE)
如何将该指标添加到我的策略中并从中生成信号?我所发现的只是添加指标的基本符号,但是是否可以添加已计算的指标?
# Add a 5-day simple moving average indicator to your strategy
add.indicator(strategy = strategy.st,
# Add the SMA function
name = "SMA",
# Create a lookback period
arguments = list(x = quote(Cl(mktdata)), n = 5),
# Label your indicator SMA5
label = "SMA5")
答案 0 :(得分:2)
我喜欢使用“ifelse”功能
<asp:Panel ID="contLine13" runat="server" CssClass="simexContainers" BorderWidth="1px" Style="position: relative">
<asp:Panel ID="LINEA13" runat="server" CssClass="simexTitles">
<asp:Label ID="lblLine1" runat="server" Text="Linea 1" />
</asp:Panel>
<div id="jednatrecina" style="width: 33%; float: left; margin-top: 100px;">
<asp:Button ID="btn17" runat="server" CssClass="stolovi" OnClick="buttons_click" AccessKey="5" />
<asp:Button ID="btn18" runat="server" CssClass="stolovi" OnClick="buttons_click" AccessKey="5" />
<asp:Button ID="btn19" runat="server" CssClass="stolovi" OnClick="buttons_click" AccessKey="5" />
<asp:Button ID="btn20" runat="server" CssClass="stolovi" OnClick="buttons_click" AccessKey="5" />
</div>
<div id="dvetrecine" style="width: 66%; float: right;">
<span class="KoferceCircle">
<asp:Button ID="btn1" runat="server" CssClass="KoferceBox" OnClick="buttons_click" AccessKey="1" />
</span>
<span class="KoferceCircle">
<asp:Button ID="btn9" runat="server" CssClass="KoferceBox" OnClick="buttons_click" AccessKey="1" />
</span>
<br />
<hr style="width: 75%;" />
<span class="KoferceKruzic">
<asp:Button ID="btn2" runat="server" CssClass="KoferceKruzicBox" OnClick="buttons_click" AccessKey="2" />
</span>
<span class="KoferceKruzic">
<asp:Button ID="btn10" runat="server" CssClass="KoferceKruzicBox" OnClick="buttons_click" AccessKey="2" />
</span>
<br />
<span class="KoferceKruzic">
<asp:Button ID="btn3" runat="server" CssClass="KoferceKruzicBox" OnClick="buttons_click" AccessKey="2" />
</span>
<span class="KoferceKruzic">
<asp:Button ID="btn11" runat="server" CssClass="KoferceKruzicBox" OnClick="buttons_click" AccessKey="2" />
</span>
<br />
<span class="KoferceKruzic">
<asp:Button ID="btn4" runat="server" CssClass="KoferceKruzicBox" OnClick="buttons_click" AccessKey="2" />
</span>
<span class="KoferceKruzic">
<asp:Button ID="btn12" runat="server" CssClass="KoferceKruzicBox" OnClick="buttons_click" AccessKey="2" />
</span>
<br />
<span class="KoferceKruzic">
<asp:Button ID="btn5" runat="server" CssClass="KoferceKruzicBox" OnClick="buttons_click" AccessKey="2" />
</span>
<span class="KoferceKruzic">
<asp:Button ID="btn13" runat="server" CssClass="KoferceKruzicBox" OnClick="buttons_click" AccessKey="2" />
</span>
<br />
<span class="KoferceCircle">
<asp:Button ID="btn6" runat="server" CssClass="KoferceBox" OnClick="buttons_click" AccessKey="3" />
</span>
<span class="KoferceKruzic">
<asp:Button ID="btn14" runat="server" CssClass="KoferceKruzicBox" OnClick="buttons_click" AccessKey="2" />
</span>
<br />
<hr style="width: 75%;" />
<span class="KoferceCircle">
<asp:Button ID="btn7" runat="server" CssClass="KoferceBox" OnClick="buttons_click" AccessKey="4" />
</span>
<span class="KoferceCircle">
<asp:Button ID="btn15" runat="server" CssClass="KoferceBox" OnClick="buttons_click" AccessKey="3" />
</span>
<br />
<span class="KoferceCircle">
<asp:Button ID="btn8" runat="server" CssClass="KoferceBox" OnClick="buttons_click" />
</span>
<span class="KoferceCircle">
<asp:Button ID="btn16" runat="server" CssClass="KoferceBox" OnClick="buttons_click" />
</span>
</div>
</asp:Panel>
这将为您提供SMA和一列,您可以使用1作为买入信号或-1作为卖出信号。