代码之家  ›  专栏  ›  技术社区  ›  Luca_TV

场景条件下的第二条打开值

  •  0
  • Luca_TV  · 技术社区  · 2 年前

    我请你帮忙解决这个问题:正如你从下面的代码中看到的,我正试图在第二支每日蜡烛的开盘价上创建一条5粗的红线(我正在查看30分钟的图表),所以我想在10:00-10:30蜡烛收盘并合并后尽快获得开盘值。正如你所看到的,我试图推断出第二根蜡烛的开口,但它让我回到了前一天第二支蜡烛的开口。我该怎么办?你有想法吗?

    非常感谢任何能帮助我的人

     //@version=5
    indicator('Custom Gap Indicator', max_lines_count = 500, max_boxes_count = 500, shorttitle='CGI', overlay=true)
    
    // Parameters
    gap_threshold_percent = input(0.1, title='Gap Threshold (%)')
    spread_percent = input(5, title='Open Stoploss Gap (%)')
    multiplier = input(1.5, title='Take Profit Multiplier')
    WRB_MIN_VALUE = input(75, title='WRB min value to range min-max (%)')
    DOJI_DEF = input(30, title='Doji max value to range min-max (%)')
    DOJI_in_trend= input(1, title = "Doji in trend? (1=yes  0=no)")
    DOJI_in_trend_max_val= input(6.0,title = "Max val Doji in trend body (%)")
    Min_value_SL=input(1.0,"Min Value Stop Loss gap ($)")
        
    // gap value
    gap = open - close[1]
        
    // gap is bearish or bullish 
    is_bearish_gap = gap < 0
            
    var firstBar = 0
    var secondBar = 0
    var secondOpen = 0.0
    var line openLine = na
        
    newDay = ta.change(time('D'))
    firstBar := newDay ? bar_index : firstBar
    secondBar := bar_index == firstBar + 1 ? time : secondBar
    secondOpen := bar_index == firstBar + 1 ? open : secondOpen
    
        
    // Scenario 1: bullish gap (DOJI/CANDELA PICCOLA inversione a rialzo)
    
    if math.abs(gap) > close[1] * gap_threshold_percent / 100 and is_bearish_gap and open <= close and (close - open) / (high - low) <= DOJI_DEF / 100 and (high+((high-open)* spread_percent / 100)-open)>= Min_value_SL
        opening_price = open
        highest_or_lowest = high
        line.new(x1=bar_index, y1=open, x2=bar_index + 12, y2=open, width=2, color=color.orange) 
        box.new(left = bar_index,top = highest_or_lowest + ((highest_or_lowest-open) * spread_percent / 100) , right = bar_index+12, bottom = open - (multiplier * ((highest_or_lowest-open) +((highest_or_lowest-open) * spread_percent / 100))),text="DOJI/PICCOLA SHORT" ,text_color=color.red, border_color=color.red,border_width= 0,bgcolor = color.rgb(215, 43, 43, 86))
        line.new(bar_index+1, secondOpen,bar_index+11 ,secondOpen,color = color.red,width = 15)
    
    //Scenario 2 etc................
    

    看图片可以更好地理解问题并帮助我解决

    look the wrong result

    0 回复  |  直到 2 年前
    推荐文章