0

我正在尝试编写用户定义百分比烛台的代码。为了绘制每根蜡烛图,范围必须等于用户定义的百分比%,(例如,0.05% 或 1% 的一半)基于开盘价 - 与时间无关。就像 Renko,但不是 Renko 45 度价格情节或转载。如果达到该范围,则烛台收盘并根据先前的收盘价打开新的蜡烛。因此,新烛台将从之前的收盘价高点或低点开始。烛台将有一个开/高/低/收盘,就像任何标准烛台一样 - 但不像 renko 盒子。范围四舍五入到小数点后 3 位。

*****************************************
Example:
Open $10 * .05= .50 (range) , High $10.5, Low $10.5, Close $10.5
Next bar, Open from previous bar close. Open $10.5 *.05 =.525 (range), High $10.75, Low $10.535, Close $10.535
Open $10.535 * .05 = .52675 ~ .537 (round to 3 decimal places)
High $10.535 + 0.287 = $10.922, Low $10.40, Close $10.922
Open $10.922 *.05 = .546, High 11.468, Low $10.922, Close $11.468
Open $11.468 *.05 = .573, High 11.468, Low 10.895
********************************************************

    [pine] Code
    
    //@version=5
    indicator("User define candlestick size",shorttitle="Brick Size",format=format.price,overlay=true)
    
    // Get price data
    OpenPrice = open
    
    //  User define 100% to 0%, where 0.005 is half of 1% or 0.5%
    candleSize = input.float(title='Brick Size (%)', defval=0.005)
    
    //  Calculate the candlestick range by multiplying the user define value and round the result to the nearest three decimal places
    CalcCandle_Range = ((open * defval) math.round(3))
    
    //  defining how each candlestick closes, by +/- the openprice to CalcCandle_Range or whetherever the range has met
    candleClose = (OpenPrice + CalcCandle_Range) or (OpenPrice - CalcCandle_Range) or candleCandle_Range // has met
    
    //  plot the candle to overlay chart to be used with other strategies
    plotcandle(candleClose)
    [pine/]

**************************
I'm a beginner pinescript coder and would appreciate any help completing this project! This would be easy for an experienced coder, but seem to be so difficult for me :( 
Thank you for your help!
4

0 回答 0