Advertisement
Maurizio-Ciullo

Indicatore Win/Rate Position Size

Oct 4th, 2023
916
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 Win/Rate Position Size", overlay=true, margin_long=100, margin_short=100)
  6.  
  7. // Calcolo Win/Rate %
  8. win_rate = (strategy.wintrades / strategy.closedtrades) * 100
  9. plot(win_rate, title="win_rate")
  10.  
  11. // Calcolo Balance
  12. InitialCapital = input.float(defval = 1000, title="Initial Capital", group="Capital Management", step=0.1)
  13. float Balance = 2 // (((InitialCapital + strategy.netprofit) * 24) / 100) / close
  14. pos_size = Balance
  15.  
  16. // Calcolo Position Size
  17. if strategy.closedtrades > 5 and  win_rate > 42 // E' possibile usare anche un numero float
  18.     pos_size := Balance
  19. else if strategy.closedtrades > 5 and win_rate < 42
  20.     pos_size := 00000.1//Balance / 2 // OPPURE ALTRE CONDIZIONI TIPO STOP DELLA STRATEGIA ENTRANDO CIN UN CAPITALE RIDICOLO TIPO: 0.001
  21. plot(Balance, title="Balance")
  22.  
  23. // Condizioni Di Ingresso Long
  24. longCondition = ta.crossover(ta.sma(close, 14), ta.sma(close, 28))
  25. if (longCondition)
  26.     strategy.entry("My Long Entry Id", strategy.long, qty=pos_size)
  27.  
  28. closeConditionLong = ta.crossunder(ta.sma(close, 14), ta.sma(close, 28))
  29. if (closeConditionLong)
  30.     strategy.close("My Long Entry Id")
  31.  
  32.  
  33. // Qui se voglio provare lo swing della posizone per vedere se chiude tutte le posizioni. Funziona !!!, con questo codice chiude tutto specialmente al cambio della size "va bene" !!!
  34.  
  35. // Condizioni Di Ingresso Short
  36. // shortCondition = ta.crossunder(ta.sma(close, 14), ta.sma(close, 28))
  37. // if (shortCondition)
  38. //     strategy.entry("My Short Entry Id", strategy.short, qty=pos_size)
  39.  
  40. // Monitoraggio posizione
  41. bought = strategy.position_size[0]> strategy.position_size[1]
  42. Close_TP = false    
  43. Close_TP := strategy.position_size[1] - strategy.position_size[0] and strategy.position_size[1] != 0 and strategy.position_size[0] != 0
  44.  
  45.  
  46. plotshape(Close_TP,title="Close_TP", style=shape.xcross, color=color.blue, size =size.small, editable = true)
  47. plot(strategy.position_size[1],"Position Old")
  48. plot(strategy.position_size,"Position")
Advertisement
Comments
  • hemal9022
    262 days
    # text 0.12 KB | 0 0
    1. i got 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