Facebook
From Scorching Madrill, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 49
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © jovi848.mcintyre
  3.  
  4. //@version=4
  5. strategy("My Strategy", overlay=true,slippage=2,initial_capital=2000*100,currency="USD",default_qty_type=strategy.fixed,default_qty_value=10000,commission_type=strategy.commission.percent,commission_value=0.001)
  6.  
  7. fast = 12, slow = 26
  8. fastMA = ema(close, fast)
  9. slowMA = ema(close, slow)
  10. macd = fastMA - slowMA
  11. signal = sma(macd, 9)
  12.  
  13. EMA = ema(close,150)
  14.  
  15. isChartUnderEMA = EMA>close
  16. isSignalandMACDAboveZero = signal > 0 and macd > 0
  17. isSignalandMACDUnderZero = signal < -0 and macd < -0
  18.  
  19. longCondition = crossunder(signal,macd) and not isChartUnderEMA and isSignalandMACDUnderZero and strategy.position_size == 0
  20. shortCondition = crossunder(macd,signal) and isChartUnderEMA and isSignalandMACDAboveZero and strategy.position_size == 0
  21.  
  22.  
  23. // plot(series=longCondition? close*1.0018:na, color=color.lime,style=plot.style_cross, linewidth=2)
  24. // plot(series=shortCondition? close*1.0018:na, color=color.yellow,style=plot.style_cross, linewidth=2)
  25.  
  26. ATR = atr(7)
  27. stop_level = high - (ATR*2)
  28. profit_level = close + (ATR*3)
  29.  
  30. stop_loss = valuewhen(longCondition,stop_level,0)
  31. entry_price = valuewhen(longCondition,close[0],0)
  32. profit = valuewhen(longCondition,profit_level,0)
  33.  
  34. float trail_stop_price = (((profit-entry_price)*.75)+entry_price)*1.0
  35.  
  36. trailing_stop_condition = (high>trail_stop_price)
  37.  
  38.  
  39.  
  40. // if(trailing_stop_condition)
  41.     // profit := (profit-entry_price)*1.25+ entry_price
  42.     // strategy.exit("TP Trailing Stop", "My Long Entry Id", stop=1, limit=profit)
  43.  
  44. // plot(series=trailing_stop_condition and strategy.position_size > 0? profit:na, color=color.yellow,style=plot.style_cross, linewidth=2)
  45.  
  46. plot1 = plot(series=strategy.position_size > 0 ?profit:na , color=color.green,style=plot.style_linebr, linewidth=1)
  47. plot2 = plot(strategy.position_size > 0 ?entry_price:na , color=color.green,style=plot.style_linebr, linewidth=1)
  48. plot3 = plot(series=strategy.position_size > 0 ?stop_loss:na , color=color.red,style=plot.style_linebr, linewidth=1)
  49. fill(plot1,plot2, title="Long Ribbon", color=color.green)
  50. fill(plot2,plot3, title="Long Ribbon", color=color.red)
  51.  
  52.  
  53.  
  54.  
  55. if(longCondition)
  56.     strategy.entry("My Long Entry Id", strategy.long)//,when = isDate() and isTime(entryTime))
  57.     strategy.exit("TP/SL LONG", "My Long Entry Id", stop=stop_level, limit=profit_level)
  58.  
  59. if (shortCondition)
  60.     stop_level := high + (ATR*2)
  61.     profit_level := close - (ATR*3.5)
  62.     // strategy.entry("My Short Entry Id", strategy.short)//,when = isDate() and isTime(entryTime))
  63.     // strategy.exit("TP/SL Short", "My Short Entry Id", stop=stop_level, limit=profit_level)
  64.  
  65. plot(EMA,color=color.orange)
  66.  
  67.  
  68. // plot(series=longCondition or shortCondition? profit_level:na, color=color.lime,style=plot.style_cross, linewidth=2)
  69. // plot(series=longCondition or shortCondition? stop_level:na, color=color.red,style=plot.style_cross, linewidth=2)
  70.