Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // © Maurizio-Ciullo
- //@version=5
- strategy("Indicatore Funzione MM Fixed Ratio", overlay=true, precision = 5)
- InitialCapital = input.float(defval = 1000, title="Initial Capital", group="Capital Management", step=0.1)
- FixedContracts = input.float(defval=1.0, minval=0.001, maxval=100000, step=0.001, title= "FixedContracts")
- FixedRatioContractsDebug = input.float(defval=1, minval=1, maxval=100000, step=1, title= "FixedRatioContractsDebug")
- Ratio = input.float(defval = 250, minval = 0.1, maxval=100000, title="Ratio", group="Ratio", step=0.1)
- inTruncate = input.int(defval=1, minval=1, maxval=100000, step=1, title= "Truncate")
- FixedRationContractDecimals = input.string(defval = "1", title ="Fixed Ratio Contract Decimals", options = ["1", "0.1", "0.01", "0.001"])
- plot(InitialCapital + strategy.netprofit, title="Actual Equity")
- // Truncate() truncates a given number to the specified number of decimals.
- Truncate(number, decimals) =>
- factor = math.pow(10, decimals)
- int(number * factor) / factor
- // Start Entry Fixed Ratio //
- EntryFixedRatio = 0.0
- RatioCalculation = 1 + 8 * strategy.netprofit / Ratio
- // Contratti Senza Decimali //
- if RatioCalculation > 0 and FixedRationContractDecimals == "1"
- EntryFixedRatio := FixedContracts * int (0.5 * (1 + math.sqrt(RatioCalculation)) / FixedContracts)
- // EntryFixedRatio := FixedContracts * (0.5 * (1 + math.sqrt(RatioCalculation)) / FixedContracts)
- // Diviso 10 Dall'originale per tradare size minori di un contratto, E con Truncate ESEGUE STEP DA 0.1 A 0.2 ETC... ATTENZIONE SOLO CON SIZE AD 1 DECIMALE: 0.1, 0.2 ETC ... IMPOSTA TRUNCATE A 1
- if RatioCalculation > 0 and FixedRationContractDecimals == "0.1"
- EntryFixedRatio := FixedContracts * (0.5 * (1 + math.sqrt(RatioCalculation)) / FixedContracts) / 10 //
- EntryFixedRatio := Truncate(EntryFixedRatio, inTruncate)
- // Diviso 100 e un'altro int aggiunto Dall'originale per tradare size minori di un contratto, ESEGUE STEP DA 0.01, 0.02, 0.03 ETC... ATTENZIONE SOLO CON SIZE AD 2 DECIMALI: 0.01, 0.02 ETC ... IMPOSTA TRUNCATE A 2
- if RatioCalculation > 0 and FixedRationContractDecimals == "0.01"
- EntryFixedRatio := FixedContracts * int (0.5 * int (1 + math.sqrt(RatioCalculation)) / FixedContracts) / 100
- EntryFixedRatio := Truncate(EntryFixedRatio, inTruncate)
- // Diviso 1000 e un'altro int aggiunto Dall'originale per tradare size minori di un contratto, ESEGUE STEP DA 0.001, 0.002, 0.003 ETC... ATTENZIONE SOLO CON SIZE AD 2 DECIMALI: 0.001, 0.002 ETC ... IMPOSTA TRUNCATE A 3
- if RatioCalculation > 0 and FixedRationContractDecimals == "0.001"
- EntryFixedRatio := FixedContracts * int (0.5 * int (1 + math.sqrt(RatioCalculation)) / FixedContracts) / 1000
- EntryFixedRatio := Truncate(EntryFixedRatio, inTruncate)
- if EntryFixedRatio < FixedContracts
- EntryFixedRatio := FixedContracts
- plot(EntryFixedRatio, title="Entry Fixed Ratio")
- // End Entry Fixed Ratio //
- // Start Entry Fixed Ratio Debug //
- // Per effettuare il Debug, inserire: EntryFixedRatioDubug in qty = EntryFixedRatioDubug della strategia e verificare le altre size se rispettano i decimali minori !!! .
- EntryFixedRatioDubug = 0.0
- RatioCalculationDubug = 1 + 8 * strategy.netprofit / Ratio
- // Contratti Senza Decimali //
- if RatioCalculationDubug > 0
- EntryFixedRatioDubug := FixedRatioContractsDebug * int (0.5 * (1 + math.sqrt(RatioCalculationDubug)) / FixedRatioContractsDebug)
- // EntryFixedRatio := FixedContractsDebug * (0.5 * (1 + math.sqrt(RatioCalculation)) / FixedContractsDebug)
- if EntryFixedRatioDubug < FixedRatioContractsDebug
- EntryFixedRatioDubug := FixedRatioContractsDebug
- plot(EntryFixedRatioDubug, title="Entry Fixed Ratio Dubug")
- // End Entry Fixed Ratio Debug //
- // Entry / Exit
- longCondition = ta.crossover(ta.sma(close, 14), ta.sma(close, 28))
- if (longCondition)
- strategy.entry("My Long Entry Id", strategy.long, qty=EntryFixedRatioDubug)
- shortCondition = ta.crossunder(ta.sma(close, 14), ta.sma(close, 28))
- if (shortCondition)
- strategy.close("My Long Entry Id")
Advertisement
Comments
-
- download all types of premium tradingview indicators codes available on telegram - https://t.me/tradingview_premium_indicator
Add Comment
Please, Sign In to add comment
Advertisement