交易视图策略中的多个条目

时间:2020-10-17 02:03:00

标签: pine-script

编辑/////确定,我发现这与每笔价格变动的计算有关。实际上,它不会每10秒准确地回测某些内容。您最能在5分钟的蜡烛图上的交易视图中准确测试的是每5分钟一批的订单。因此,限制竞价可能是因为较高的出价会带来更好的平均竞价。

基本上,此脚本在多头条件发生时进行初始输入,然后假定每10秒进行一次新出价,直到允许的最大合同限制生效(实际上这是USD值,但我不能使用需要使它适用于以太坊)

我认为随时间定义变量flipstamp就是打破它的原因。为了使循环正常工作,我需要在发生逆转时以unix格式记录UTC时间,该循环使用var计数器,即,假设从逆转时间开始并以10秒为增量添加增量因此,每10秒只下一次出价。 (或者无论多长时间,这仅是一个示例) 绘制此图时,其他条目将不起作用,也不会通过。想法?

//@version=4

strategy(title="Example: maximum position size", overlay=false, pyramiding=390, default_qty_type=strategy.fixed, default_qty_value=100, precision=0)

// Calculate the moving averages
quickMA = ema(close, 25)
slowMA = ema(close, 200)

// Trade at most 1,000 shares long or short
strategy.risk.max_position_size(contracts=390)

// Plot position size and its maximum
plot(series=strategy.position_size, style=plot.style_areabr, color=strategy.position_size > 0 ? color.green : color.red)

hline(price=1000, color=color.orange, linestyle=hline.style_solid)
hline(price=-1000, color=color.orange, linestyle=hline.style_solid)

// Determine trading conditions
GoLong = crossover(quickMA, slowMA)
GoShort = crossunder(quickMA, slowMA)

// Submit initial entry orders
if GoLong
    strategy.entry(id="EL", long=true)

if GoShort
    strategy.entry(id="ES", long=false)

flipstamp = 0

if GoLong or GoShort //and barssince(GoLong) % 1 == 0 or barssince(GoShort) % 1 == 0
    flipstamp := time
var int baseincrement_id=0
var int baseunit_increment_total = flipstamp 
timeDifference = (time - time[1]) / 1000
timebaseunit = timeDifference / 10

if timenow > baseunit_increment_total 
    baseunit_increment_total :=  baseunit_increment_total + timebaseunit
    baseincrement_id := baseincrement_id + 1

// Submit entry orders
if (GoLong)
    strategy.entry(id="EL", long=true, qty=.195)

if (GoShort)
    strategy.entry(id="ES", long=false, qty=.195)

if timenow > baseunit_increment_total and strategy.position_size > 0 and barssince(GoLong)<barssince(GoShort)
    strategy.entry(id="OPartLong", long=true, qty=.0025, when=GoLong)
    
if timenow > baseunit_increment_total and strategy.position_size < 0 and barssince(GoLong)>barssince(GoShort)
    strategy.entry(id="OPartShort", long=false, qty=.0025, when=GoShort)
    

0 个答案:

没有答案