Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Forex Ticker, Settaggi e Timeframe da Trovare
- //@version=4
- //1. Strategia
- strategy("BR - Breakin Python",
- overlay=true,
- pyramiding=0,
- initial_capital=10000,
- commission_type=strategy.commission.cash_per_order,
- commission_value=0.1, slippage=2,
- default_qty_type=strategy.percent_of_equity,
- currency="EUR")
- //2. Parametri di Imput della strategia
- in_valuta = input(title="Valuta", type=input.string, defval="EUR", options=["EUR", "USD", "CAD", "JPY", "NZD", "GBP", "CHF"])
- riskPerTrade = input(title="Risk Per Trade %", type=input.float, minval=0.1, maxval=100, defval=1.0, step=0.1)
- in_atr_periodo = input(title="Periodicità ATR", type=input.integer, minval=5, maxval=500, defval=5, step=1)
- in_atr_Mult = input(title="atr_Mult", type=input.float, minval=0.0001, maxval=500, defval=1.5, step=0.0001)
- in_tpPips = input(title="TP", type=input.integer, defval=40)
- in_slPips = input(title="SL", type=input.integer, defval=30)
- in_solo_long = input(title="Solo long", type=input.bool, defval=false)
- atr = atr(in_atr_periodo)
- hourTrading = input(title="sessione valida di trading", type=input.string, defval="0600-2300:23456")
- rangeTrading = time(timeframe.period, hourTrading)
- valutaBaseUguale = in_valuta == syminfo.basecurrency
- valutaSecondariaUguale = in_valuta == syminfo.currency
- nessunaValuta = not valutaSecondariaUguale and not valutaBaseUguale
- conversioneCoppia = valutaSecondariaUguale ? syminfo.tickerid : in_valuta + syminfo.currency
- conversioneTassoCambio = security(symbol=conversioneCoppia, resolution="D", expression=close)
- // Calcolo position size
- getVolumePosizione(stopLossSizePoints) =>
- riskAmount = (strategy.equity * (riskPerTrade / 100)) * (valutaBaseUguale or nessunaValuta ? conversioneTassoCambio : 1.0)
- riskPerPoint = (stopLossSizePoints * syminfo.pointvalue)
- positionSize = (riskAmount / riskPerPoint) / (syminfo.mintick * 10)
- round(positionSize)
- //Entrata Long con SL e TP
- if (abs(open-close)>(atr*in_atr_Mult)) and close > open and strategy.opentrades == 0 //and rangeTrading
- longsl = close - (in_slPips*10*syminfo.mintick)
- longslPips = ((close-longsl) / syminfo.mintick / 10)
- longtp = close + (in_tpPips*10*syminfo.mintick)
- size = getVolumePosizione(longslPips)
- strategy.entry("long", true, qty=size)
- strategy.exit("long", stop = longsl, limit = longtp)
- //Entrata Short con SL e TP
- if (abs(open-close)>(atr*in_atr_Mult)) and close < open and strategy.opentrades == 0 and not in_solo_long //and rangeTrading
- shortsl = close + (in_slPips*10*syminfo.mintick)
- shortslPips = ((shortsl-close) / syminfo.mintick / 10)
- shorttp = close - (in_tpPips*10*syminfo.mintick)
- size = getVolumePosizione(shortslPips)
- strategy.entry("short", false, qty=size)
- strategy.exit("short", stop = shortsl, limit = shorttp)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement