Advertisement
Maurizio-Ciullo

Bot 1 Il trading system completo - Trend-wide (Strategia Trend Following) - parte 1

Jul 10th, 2021 (edited)
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Il trading system completo - Trend-wide (Strategia Trend Following) - parte 1
  2. //@version=4    
  3. strategy(title="Strategia trend-wide", overlay=true,
  4.      pyramiding=0, initial_capital=10000,
  5.      commission_type=strategy.commission.cash_per_order,
  6.      commission_value=1, slippage=2,
  7.      default_qty_type=strategy.percent_of_equity)
  8.  
  9. maInputSlow = input(title="MA Slow", type=input.integer, defval=81, minval=0, maxval=500)
  10. maInputFast = input(title="MA Fast", type=input.integer, defval=15, minval=0, maxval=500)
  11. maMinDiff = input(title="Distanza min medie", type=input.float, defval=15)
  12. hourTrading = input(title="Sessione valida di trading", type=input.string, defval="24x7")
  13. onlyLong = input(title="Solo long trade", type=input.bool, defval=false)
  14.  
  15. maSlow = ema(close, maInputSlow)
  16. maFast = ema(close, maInputFast)
  17. rangeTrading = time(timeframe.period, hourTrading)
  18.  
  19. // condizione long cross over chiusura candela con valore media semplice veloce
  20. condEntryLong = close > maSlow and (maFast - maSlow) > maMinDiff and rangeTrading
  21. condExitLong = crossunder(maFast, maSlow)
  22.  
  23. condEntryShort = crossunder(close, maSlow) and (maSlow - maFast) > maMinDiff and rangeTrading and not onlyLong
  24. condExitShort = crossover(close, maFast)
  25.  
  26. strategy.entry("long", true, when = condEntryLong)
  27. strategy.close("long", when=condExitLong)
  28.  
  29. strategy.entry("short", false, when = condEntryShort)
  30. strategy.close("short", when=condExitShort)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement