【问题标题】:Integrating Line Style into MA/EMA Trend Line将线型整合到 MA/EMA 趋势线中
【发布时间】:2021-10-26 03:00:25
【问题描述】:

想知道是否可以帮助我将线条样式集成到 MA/EMA 脚本中。顶部是从交易视图帮助部分中直接提取的关于如何设置趋势线样式的部分。

//@version=4
study(title="Set line style with input", overlay=true)

// STEP 1. Make the input with pull-down menu
styleOption = input(title="Line Style", type=input.string, 
     options=["solid (─)", "dotted (┈)", "dashed (╌)", 
     "arrow left (←)", "arrow right (→)", "arrows both (↔)"], 
     defval="solid (─)")

// STEP 2. Convert the input to a proper line style value
lineStyle = styleOption == "dotted (┈)" ? line.style_dotted :
     styleOption == "dashed (╌)" ? line.style_dashed :
     styleOption == "arrow left (←)" ? line.style_arrow_left :
     styleOption == "arrow right (→)" ? line.style_arrow_right :
     styleOption == "arrows both (↔)" ? line.style_arrow_both :
         line.style_solid

// STEP 3. Use the input option to set the line's style
if barstate.islastconfirmedhistory
    // Create a new line and immediately set its style
    line.new(x1=bar_index[55], y1=close[55],
         x2=bar_index, y2=close, width=4, color=color.blue,
         style=lineStyle)
    
    // Or make a line, and then change its style
    myLine = line.new(x1=bar_index[35], y1=close[35],
         x2=bar_index, y2=close, width=4, color=color.orange)
    
    line.set_style(id=myLine, style=lineStyle)


// EMA Example Need to Integreate Above style    
len1 = input(21, minval=1, title="EMA 1")
src1 = input(close, title="EMA 1 source")
plot(ema(src1, len1), color=#8b0000, title="EMA 1",linewidth=1)

【问题讨论】:

    标签: function styles line pine-script trend


    【解决方案1】:

    您不能将以下内容与绘图功能一起使用。下面可以配合line、hline函数来绘制水平线和垂直线。

    styleOption = input(title="Line Style", type=input.string, 
         options=["solid (─)", "dotted (┈)", "dashed (╌)", 
         "arrow left (←)", "arrow right (→)", "arrows both (↔)"], 
         defval="solid (─)")
    
    // STEP 2. Convert the input to a proper line style value
    lineStyle = styleOption == "dotted (┈)" ? line.style_dotted :
         styleOption == "dashed (╌)" ? line.style_dashed :
         styleOption == "arrow left (←)" ? line.style_arrow_left :
         styleOption == "arrow right (→)" ? line.style_arrow_right :
         styleOption == "arrows both (↔)" ? line.style_arrow_both :
             line.style_solid
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-15
      • 2011-01-31
      • 2013-07-09
      • 1970-01-01
      • 2018-03-27
      • 2021-06-17
      • 1970-01-01
      相关资源
      最近更新 更多