Advertisement
Maurizio-Ciullo

Indicatore Funzione MM Fixed Ratio

Oct 30th, 2023
935
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © Maurizio-Ciullo
  3.  
  4. //@version=5
  5. strategy("Indicatore Funzione MM Fixed Ratio", overlay=true, precision = 5)
  6.  
  7. InitialCapital = input.float(defval = 1000, title="Initial Capital", group="Capital Management", step=0.1)
  8. FixedContracts = input.float(defval=1.0, minval=0.001, maxval=100000, step=0.001, title= "FixedContracts")
  9. FixedRatioContractsDebug = input.float(defval=1, minval=1, maxval=100000, step=1, title= "FixedRatioContractsDebug")
  10. Ratio = input.float(defval = 250, minval = 0.1, maxval=100000, title="Ratio", group="Ratio", step=0.1)
  11. inTruncate = input.int(defval=1, minval=1, maxval=100000, step=1, title= "Truncate")
  12. FixedRationContractDecimals = input.string(defval = "1", title ="Fixed Ratio Contract Decimals", options = ["1", "0.1", "0.01", "0.001"])
  13. plot(InitialCapital + strategy.netprofit, title="Actual Equity")
  14.  
  15.  
  16. // Truncate() truncates a given number to the specified number of decimals.
  17. Truncate(number, decimals) =>
  18.     factor = math.pow(10, decimals)
  19.     int(number * factor) / factor
  20.  
  21.  
  22. // Start Entry Fixed Ratio //
  23. EntryFixedRatio = 0.0
  24. RatioCalculation = 1 + 8 * strategy.netprofit / Ratio
  25. // Contratti Senza Decimali //                                                    
  26. if RatioCalculation > 0 and FixedRationContractDecimals == "1"
  27.     EntryFixedRatio := FixedContracts * int (0.5 * (1 + math.sqrt(RatioCalculation)) / FixedContracts)        
  28. //  EntryFixedRatio := FixedContracts *     (0.5 * (1 + math.sqrt(RatioCalculation)) / FixedContracts)
  29.  
  30. // 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
  31. if RatioCalculation > 0 and FixedRationContractDecimals == "0.1"
  32.     EntryFixedRatio := FixedContracts *  (0.5 * (1 + math.sqrt(RatioCalculation)) / FixedContracts)  / 10 //
  33.     EntryFixedRatio := Truncate(EntryFixedRatio, inTruncate)
  34. // 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
  35. if RatioCalculation > 0 and FixedRationContractDecimals == "0.01"
  36.     EntryFixedRatio := FixedContracts * int (0.5 * int (1 + math.sqrt(RatioCalculation)) / FixedContracts) / 100
  37.     EntryFixedRatio := Truncate(EntryFixedRatio, inTruncate)
  38. // 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
  39. if RatioCalculation > 0 and FixedRationContractDecimals == "0.001"
  40.     EntryFixedRatio := FixedContracts * int (0.5 * int (1 + math.sqrt(RatioCalculation)) / FixedContracts) / 1000
  41.     EntryFixedRatio := Truncate(EntryFixedRatio, inTruncate)
  42.  
  43.  
  44. if EntryFixedRatio < FixedContracts                                                                        
  45.     EntryFixedRatio := FixedContracts                                            
  46. plot(EntryFixedRatio, title="Entry Fixed Ratio")
  47. // End Entry Fixed Ratio //
  48.  
  49.  
  50. // Start Entry Fixed Ratio Debug //
  51. // Per effettuare il Debug, inserire: EntryFixedRatioDubug in qty = EntryFixedRatioDubug della strategia e verificare le altre size se rispettano i decimali minori !!! .
  52. EntryFixedRatioDubug = 0.0
  53. RatioCalculationDubug = 1 + 8 * strategy.netprofit / Ratio
  54. // Contratti Senza Decimali //                                                    
  55. if RatioCalculationDubug > 0
  56.     EntryFixedRatioDubug := FixedRatioContractsDebug * int (0.5 * (1 + math.sqrt(RatioCalculationDubug)) / FixedRatioContractsDebug)        
  57. //  EntryFixedRatio := FixedContractsDebug *     (0.5 * (1 + math.sqrt(RatioCalculation)) / FixedContractsDebug)
  58.  
  59. if EntryFixedRatioDubug < FixedRatioContractsDebug                                                                        
  60.     EntryFixedRatioDubug := FixedRatioContractsDebug                                            
  61. plot(EntryFixedRatioDubug, title="Entry Fixed Ratio Dubug")
  62. // End Entry Fixed Ratio Debug //
  63.  
  64.  
  65.  
  66. // Entry / Exit
  67. longCondition = ta.crossover(ta.sma(close, 14), ta.sma(close, 28))
  68. if (longCondition)
  69.     strategy.entry("My Long Entry Id", strategy.long, qty=EntryFixedRatioDubug)
  70.  
  71. shortCondition = ta.crossunder(ta.sma(close, 14), ta.sma(close, 28))
  72. if (shortCondition)
  73.     strategy.close("My Long Entry Id")
Advertisement
Comments
  • tradingviewcodes
    230 days
    # text 0.12 KB | 0 0
    1. 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