简体   繁体   English

Pinescript 策略跨多个交易品种进出场

[英]Pinescript Strategy Entry and Exit Across Multiple Symbols

I'm new to Pine Script and I am building my first basic strategy.我是 Pine Script 的新手,正在构建我的第一个基本策略。 Is there any way to code a strategy that has a long entry in a certain symbol and else long exit in that symbol, and if not in that symbol then enter into a different symbol that is not on the chart?有没有什么方法可以编写一个策略,该策略在某个符号中有一个长入场,而在该符号中有一个长退出,如果不在该符号中,则输入不在图表上的不同符号? I am trying to code "under these conditons, enter into VTV. Otherwise, sell VTV and enter into VUG."我正在尝试编码“在这些条件下,进入 VTV。否则,出售 VTV 并进入 VUG。” However, I can't seem to find how to enter code that gives an entry point for another symbol that doesn't have bars on the chart.但是,我似乎无法找到如何输入代码,为图表上没有柱的另一个交易品种提供入口点。 Does anyone know if this is possible?有谁知道这是否可能? Thank you for any advice in advance感谢您提前提出任何建议

I did a bunch of reserach trying to find sources that show the answer, but I couldn't find any.我做了很多研究,试图找到显示答案的来源,但我找不到任何来源。 I currently have SPY open as my main symbol in the chart because it has one of the first condtions I want the entry point to ensure is there, but I can change it to either VTV or VUG as that is what I want to be buying and selling.我目前在图表中打开了 SPY 作为我的主要符号,因为它具有我希望入口点确保存在的首要条件之一,但我可以将其更改为 VTV 或 VUG,因为这是我想要购买的,并且卖。 However, if I did change it to either one, I still don't know if it is possible to enter and exit on a symbol not on the chart.但是,如果我确实将其更改为其中任何一个,我仍然不知道是否可以在图表上没有的交易品种上进场和退场。 This is my current code that inputs the variables:这是我当前输入变量的代码:

`// Create Indicators VTV = request.security(symbol = "BATS:VTV", timeframe = "D", expression = ta.sma(close, 260)) VUG = request.security(symbol = "BATS:VUG", timeframe = "D", expression = ta.sma(close, 10)) shorterMA = ta.sma(close, 10) //for SPY longerMA = ta.sma(close, 50) //for SPY `// 创建指标 VTV = request.security(symbol = "BATS:VTV", timeframe = "D", expression = ta.sma(close, 260)) VUG = request.security(symbol = "BATS:VUG", timeframe = "D", expression = ta.sma(close, 10)) shorterMA = ta.sma(close, 10) //用于 SPY longerMA = ta.sma(close, 50) //用于 SPY

// Specify crossover conditions longCondition = ta.crossover(shorterSMA, longerSMA) longCondition2 = ta.crossover(VUG, VTV)` // 指定交叉条件 longCondition = ta.crossover(shorterSMA, longerSMA) longCondition2 = ta.crossover(VUG, VTV)`

I plot them but I do not know how to say "buy VTV if these conditons met, otherwise sell and buy VUG"我 plot 他们但我不知道怎么说“如果满足这些条件则购买 VTV,否则出售和购买 VUG”

You can't place orders from a script that runs on one chart on another chart.您不能通过在一个图表上运行的脚本在另一个图表上下订单。

You can as you've mentioned, get data from another chart to your current chart, so you'll have to use this data and build 2 scripts - one for each chart from data you get from the other chart正如您所提到的,您可以从另一个图表获取数据到您当前的图表,因此您必须使用此数据并构建 2 个脚本 - 每个图表一个来自您从另一个图表获取的数据

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM