首页 > 解决方案 > 四舍五入到刻度精度有什么好处

问题描述

close将下面代码段中的值用于多种目的。

与以下代码无关的两个示例:

  1. ema = ema(close, 200). 如果我使用rounded close代替有真正的好处close吗?我听说它在外汇中最有用。
  2. close > ema. 这里怎么样?

圆形刻度精度的真正好处是什么?

说到它,我可以用它的圆形版本替换每个close, open, high,用法吗?lowf_roundedToTickOHLC()

// ————— Functions rounding OHLC to tick precision
f_roundedToTickOHLC() =>
    float _op = round(open  / syminfo.mintick) * syminfo.mintick
    float _hi = round(high  / syminfo.mintick) * syminfo.mintick
    float _lo = round(low   / syminfo.mintick) * syminfo.mintick
    float _cl = round(close / syminfo.mintick) * syminfo.mintick
    [_op, _hi, _lo, _cl]

// ————— Get rounded prices
[rOpen, rHigh, rLow, rClose] = f_roundedToTickOHLC()

// ————— Pullback
ema = ema(close, i_emaPullback)

// ————— TV built-in MACD code
fastLength = 12
slowlength = 26
MACDLength = 9
MACD = ema(close, fastLength) - ema(close, slowlength)
aMACD = ema(MACD, MACDLength)

// ————— Filter
filterLong = MACD > 0
filterShort = MACD < 0

// ————— States
var float entryPrice = na
var bool inLong = false
var bool inShort = false
bool inTrade = inLong or inShort

// ————— Entries
enterLong  = doLongs  and not inTrade and crossover(MACD, 0)
enterShort = doShorts and not inTrade and crossunder(MACD, 0)

// ————— Stops
atr = atr(14)
stopLong  = min(lowest(5), min(close, open) - atr * 1.5)
stopShort = max(highest(5), max(close, open) + atr * 1.5)

// ————— Exits
exitLong  = inLong  and ((crossunder(MACD, aMACD) and MACD > 0) or close < stopLong[1])
exitShort = inShort and ((crossover(MACD, aMACD) and MACD < 0)  or close > stopShort[1])

if enterLong
    inLong := true
    entryPrice := close
else if enterShort
    inShort := true
    entryPrice := close
else if exitLong
    inLong := false
    entryPrice := na
else if exitShort
    inShort := false
    entryPrice := na

标签: pine-script

解决方案


推荐阅读