获取Pine脚本的确切入口价格
如何获取订单的确切入口价格。在TradingView策略测试人员中,我看到订单价格与该策略所捕获的订单价格不同,该策略导致对停止损失和替代组织进行了错误的计算。
if (longCondition)
strategy.entry("MACrossLE", strategy.long, comment="LE")
entryPos := nz(pos[1]) == 0 and longCondition
entry_price := entryPos ? open : entry_price
tp_level_long := entry_price * (1 + tpl/100)
sl_level_long := entry_price * (1 - sll/100)
tp_exit := nz(pos[1]) == 1 and (ta.crossover(low, tp_level_long))
sl_exit := nz(pos[1]) == 1 and (ta.crossunder(high, sl_level_long))
if(tp_exit)
strategy.exit("TP-L", from_entry="EL", qty=pos, profit = tp_level_long, stop = sl_level_long)
strategy.close("Close_L", when=tp_exit)
if(sl_exit)
strategy.cancel("Cancel_L", when=sl_exit)
if (shortCondition)
strategy.entry("MACrossSE", strategy.short, comment="SE")
entryPos := nz(pos[1]) == 0 and shortCondition
entry_price := entryPos ? open : entry_price
tp_level_short := entry_price * (1 - tps/100)
sl_level_short := entry_price * (1 + sls/100)
tp_exit := nz(pos[1]) == 1 and (ta.crossover(low, tp_level_short))
sl_exit := nz(pos[1]) == 1 and (ta.crossunder(high, sl_level_short))
if(tp_exit)
strategy.exit("TP-L", from_entry="EL", qty=pos, profit = tp_level_short, stop = sl_level_short)
strategy.close("Close_L", when=tp_exit)
if(sl_exit)
strategy.cancel("Cancel_L", when=sl_exit)
当符合长期条件时,打开了策略条目,但是我没有得到确切的价格,例如,我在策略测试29340
中看到,而在entry> entry_price
的标签中我看到29335
这可能会影响策略测试。
不是我不使用stragity.position
在指示器中应用相同条件
How to get the exact entry price for the order. In TradingView Strategy Tester I see order prices are different than one captured by the strategy which leads to a wrong calculation of the stop-loss and take-profit.
if (longCondition)
strategy.entry("MACrossLE", strategy.long, comment="LE")
entryPos := nz(pos[1]) == 0 and longCondition
entry_price := entryPos ? open : entry_price
tp_level_long := entry_price * (1 + tpl/100)
sl_level_long := entry_price * (1 - sll/100)
tp_exit := nz(pos[1]) == 1 and (ta.crossover(low, tp_level_long))
sl_exit := nz(pos[1]) == 1 and (ta.crossunder(high, sl_level_long))
if(tp_exit)
strategy.exit("TP-L", from_entry="EL", qty=pos, profit = tp_level_long, stop = sl_level_long)
strategy.close("Close_L", when=tp_exit)
if(sl_exit)
strategy.cancel("Cancel_L", when=sl_exit)
if (shortCondition)
strategy.entry("MACrossSE", strategy.short, comment="SE")
entryPos := nz(pos[1]) == 0 and shortCondition
entry_price := entryPos ? open : entry_price
tp_level_short := entry_price * (1 - tps/100)
sl_level_short := entry_price * (1 + sls/100)
tp_exit := nz(pos[1]) == 1 and (ta.crossover(low, tp_level_short))
sl_exit := nz(pos[1]) == 1 and (ta.crossunder(high, sl_level_short))
if(tp_exit)
strategy.exit("TP-L", from_entry="EL", qty=pos, profit = tp_level_short, stop = sl_level_short)
strategy.close("Close_L", when=tp_exit)
if(sl_exit)
strategy.cancel("Cancel_L", when=sl_exit)
When the LongCondition is met a strategy entry is open however I'm not getting the exact price, for example, I see in the Strategy Test 29340
while in the label of entry_price
I see 29335
that's a slight difference that might affect the strategy testing.
Not I'm not using strategy.position
to apply the same condition in the indicator if that's possible
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
此代码将向您显示当前Canlde的反对价格,并随蜡烛逐步改变
this code will show you the oppening price of the current canlde and it change step by step with candles
您可能正在看错误的蜡烛。
您的条件为真时,您将设定入门价格。但是,当栏关闭或下一个条打开时,您的条目将被放置。
我将从IF块中删除所有这些计算和分配,并将它们放入全球SCOPR中。然后,您可以使用
确切的入口价格。
You are probably looking at the wrong candle.
You are setting your entry price when your condition is true. However, your entry will be placed either when the bar is closed or the next bar is open.
I would remove all those calculations and assignments from the if block and put them in the global scopr. Then you can use
to get the exact entry price.
除了上一个答案:
在定义策略的说明中,您可以设置ProcessOdorSerclose = true
效果是,将以近距离的价格(在)关闭蜡烛的订单。
默认processordersonclose = false用于导致在下一个栏上处理的顺序。
什么是最好的?
如果您将其设置为“真实”,则实际上您将获得一个可能在下一个栏上没有有效的价格。
如果将其设置为“ false”,则等待1 bar,1天或一个周末。
这是可以接受的吗?
我更喜欢“ true”,因为我希望得到的价格(在测试过程中)尽可能接近我用于提交订单的价格。
我发现,如果您使用“ true”或“ false”,它可以在测试中产生很大的影响。
In addition to the previous answer:
In the statement defining the strategy you can set ProcessOrdersOnClose=true
The effect is that an order will be handled at(/right after) closing the candle at the close price.
Default ProcessOrdersOnClose=false is used causing the order handled at the next bar.
What is best?
If you set it 'true' indeed you're getting a price that might not be valid at the next bar.
If you set it 'false' you're waiting 1 bar, 1 day or a weekend.
Is that acceptable?
I prefer 'true' as I want the price I get (while backtesting) to be as close as possible to the price I used for submitting the order.
I found out it can make a big difference in testing if you use 'true' or 'false'.