Advertisement
Maurizio-Ciullo

Break In Manuele Caprioli Forex

Nov 23rd, 2021
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Forex Ticker, Settaggi e Timeframe da Trovare
  2.  
  3. //@version=4
  4. //1. Strategia
  5. strategy("BR - Breakin Python",
  6.      overlay=true,
  7.      pyramiding=0,
  8.      initial_capital=10000,
  9.      commission_type=strategy.commission.cash_per_order,
  10.      commission_value=0.1, slippage=2,
  11.      default_qty_type=strategy.percent_of_equity,
  12.      currency="EUR")
  13.      
  14.  
  15.  //2. Parametri di Imput della strategia
  16. in_valuta = input(title="Valuta", type=input.string, defval="EUR", options=["EUR", "USD", "CAD", "JPY", "NZD", "GBP", "CHF"])
  17. riskPerTrade = input(title="Risk Per Trade %", type=input.float, minval=0.1, maxval=100, defval=1.0, step=0.1)
  18.  
  19. in_atr_periodo = input(title="Periodicità ATR", type=input.integer, minval=5, maxval=500, defval=5, step=1)
  20. in_atr_Mult = input(title="atr_Mult", type=input.float, minval=0.0001, maxval=500, defval=1.5, step=0.0001)
  21. in_tpPips = input(title="TP", type=input.integer, defval=40)
  22. in_slPips = input(title="SL", type=input.integer, defval=30)
  23.  
  24. in_solo_long = input(title="Solo long", type=input.bool, defval=false)
  25.  
  26. atr = atr(in_atr_periodo)
  27.  
  28. hourTrading = input(title="sessione valida di trading", type=input.string, defval="0600-2300:23456")
  29.  
  30. rangeTrading = time(timeframe.period, hourTrading)
  31.  
  32.  
  33. valutaBaseUguale = in_valuta == syminfo.basecurrency
  34. valutaSecondariaUguale = in_valuta == syminfo.currency
  35.  
  36. nessunaValuta = not valutaSecondariaUguale and not valutaBaseUguale
  37.  
  38. conversioneCoppia = valutaSecondariaUguale ? syminfo.tickerid : in_valuta + syminfo.currency
  39. conversioneTassoCambio = security(symbol=conversioneCoppia, resolution="D", expression=close)
  40.  
  41. // Calcolo position size
  42. getVolumePosizione(stopLossSizePoints) =>
  43.     riskAmount = (strategy.equity * (riskPerTrade / 100)) * (valutaBaseUguale or nessunaValuta ? conversioneTassoCambio : 1.0)
  44.     riskPerPoint = (stopLossSizePoints * syminfo.pointvalue)
  45.     positionSize = (riskAmount / riskPerPoint) / (syminfo.mintick * 10)
  46.     round(positionSize)
  47.    
  48. //Entrata Long con SL e TP
  49. if (abs(open-close)>(atr*in_atr_Mult)) and close > open and strategy.opentrades == 0 //and rangeTrading
  50.     longsl = close - (in_slPips*10*syminfo.mintick)
  51.     longslPips = ((close-longsl) / syminfo.mintick / 10)
  52.     longtp = close + (in_tpPips*10*syminfo.mintick)
  53.    
  54.     size = getVolumePosizione(longslPips)
  55.     strategy.entry("long", true, qty=size)
  56.     strategy.exit("long", stop = longsl, limit = longtp)
  57.    
  58. //Entrata Short con SL e TP
  59. if (abs(open-close)>(atr*in_atr_Mult)) and close < open and strategy.opentrades == 0 and not in_solo_long //and rangeTrading
  60.     shortsl = close + (in_slPips*10*syminfo.mintick)
  61.     shortslPips = ((shortsl-close) / syminfo.mintick / 10)
  62.     shorttp = close - (in_tpPips*10*syminfo.mintick)
  63.    
  64.     size = getVolumePosizione(shortslPips)
  65.     strategy.entry("short", false, qty=size)
  66.     strategy.exit("short", stop = shortsl, limit = shorttp)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement