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 Win/Rate Position Size", overlay=true, margin_long=100, margin_short=100)
- // Calcolo Win/Rate %
- win_rate = (strategy.wintrades / strategy.closedtrades) * 100
- plot(win_rate, title="win_rate")
- // Calcolo Balance
- InitialCapital = input.float(defval = 1000, title="Initial Capital", group="Capital Management", step=0.1)
- float Balance = 2 // (((InitialCapital + strategy.netprofit) * 24) / 100) / close
- pos_size = Balance
- // Calcolo Position Size
- if strategy.closedtrades > 5 and win_rate > 42 // E' possibile usare anche un numero float
- pos_size := Balance
- else if strategy.closedtrades > 5 and win_rate < 42
- pos_size := 00000.1//Balance / 2 // OPPURE ALTRE CONDIZIONI TIPO STOP DELLA STRATEGIA ENTRANDO CIN UN CAPITALE RIDICOLO TIPO: 0.001
- plot(Balance, title="Balance")
- // Condizioni Di Ingresso Long
- longCondition = ta.crossover(ta.sma(close, 14), ta.sma(close, 28))
- if (longCondition)
- strategy.entry("My Long Entry Id", strategy.long, qty=pos_size)
- closeConditionLong = ta.crossunder(ta.sma(close, 14), ta.sma(close, 28))
- if (closeConditionLong)
- strategy.close("My Long Entry Id")
- // 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" !!!
- // Condizioni Di Ingresso Short
- // shortCondition = ta.crossunder(ta.sma(close, 14), ta.sma(close, 28))
- // if (shortCondition)
- // strategy.entry("My Short Entry Id", strategy.short, qty=pos_size)
- // Monitoraggio posizione
- bought = strategy.position_size[0]> strategy.position_size[1]
- Close_TP = false
- Close_TP := strategy.position_size[1] - strategy.position_size[0] and strategy.position_size[1] != 0 and strategy.position_size[0] != 0
- plotshape(Close_TP,title="Close_TP", style=shape.xcross, color=color.blue, size =size.small, editable = true)
- plot(strategy.position_size[1],"Position Old")
- plot(strategy.position_size,"Position")
Advertisement
Comments
-
- 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