K4eMi
Pine Script Rookie
Pine Script Rookie
Posts: 6
Joined: September 6th, 2020
Location: UK
Contact: TradingView Profile

Lotsize Calculator (USD)

Hey guys here to share my Lotsize calculator for USD Account.

Code: Select all


// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © WelcomeToMathy

//@version=4
study("Lotsize Calculator",overlay=true)

S_Label  = input(true, title="Show LotSize Label")
Balance  = input(title='Account Size (USD)', defval= 5000, step=100)
atrlen   = input(title='Account Size (USD)', defval= 5)
RiskSize = input(title='Risk Size (%)', defval= 0.2, step=0.01, minval=0.0001)
AutoSL   = input(title='Auto StopLoss(Daily ATR)', defval= true)
ManualSL = input(title='SL Manual (pips)', defval=50, step=1.0, minval=0)

//--------------------------------------------------------------------------------------------------------------------------------------------- GLOBALS

currency = syminfo.currency 
symbol = syminfo.tickerid

GetInfo(pair,frame,value)=> 
    return = security(pair, frame, value)
    return
    
//--------------------------------------------------------------------------------------------------------------------------------------------- LABELS

PipValue = 
     (currency == 'AUD') ? GetInfo("AUDUSD", "1", close[1]) :
     (currency == 'CAD') ? GetInfo("USDCAD", "1", close[1]) :
     (currency == 'CHF') ? GetInfo("USDCHF", "1", close[1]) :
     (currency == 'GBP') ? GetInfo("GBPUSD", "1", close[1]) :
     (currency == 'NZD') ? GetInfo("NZDUSD", "1", close[1]) :
     (currency == 'EUR') ? GetInfo("EURUSD", "1", close[1]) :
     (currency == 'JPY') ? GetInfo("USDJPY", "1", close[1])/100 : GetInfo(symbol,"1", close[1])

var label myLabel = na
label.delete(myLabel)

if S_Label==true
    
    yen = syminfo.currency == 'JPY'
    
    DATR = GetInfo(symbol,'D', atr(atrlen))
    WATR = GetInfo(symbol,'W', atr(atrlen))
    
    atrD = yen? DATR*100:DATR*10000
    atrW = yen? WATR*100:WATR*10000
    
    StopLoss = AutoSL? atrD : ManualSL
    Risk = Balance * (RiskSize * 0.01)
    Lote = Risk / (StopLoss * PipValue) / 10
    Size = Lote>=0.01? Lote : 0.01

    labelval1 = "Daily ATR: " + tostring(atrD,"0")
    labelval2 = "Week ATR: " + tostring(atrW,"0")
    labelval3 = "StopLoss: " + tostring(atrD,"0 pips")
    labelval4 = "LotSize: " + tostring(Size,"0.00") + tostring(Risk," ($0.00)")
    
    labelprice = high
    labeltext = labelval1+"\n"+labelval2+"\n"+labelval3+"\n"+labelval4
    
    myLabel := label.new(bar_index, labelprice, color=color.black, 
         text=labeltext, 
         textcolor=color.white, 
         style=label.style_label_lower_left, 
         size=size.large, 
         textalign=text.align_left)
    


Return to “Share Your Scripts”