bottomphishing
New member
Having trouble with my code this section is plotting under every bar no matter the time frame any ideas?:
plot s1 = if IsNaN(currentPrice) then Double.NaN else (currentPrice - (currentPrice * RiskPercent));
s1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
s1.SetDefaultColor(Color.PINK);
plot s1 = if IsNaN(currentPrice) then Double.NaN else (currentPrice - (currentPrice * RiskPercent));
s1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
s1.SetDefaultColor(Color.PINK);
Code:
# Position Size Calculator based on max % account risk with variable position riskPercent %
# Includes % targets and chart plots
# Author: @bottomphishing
# Date: 6/20/2021
declare upper;
# Input max percentage of a portfolio that one stock should be
input Max_Percent = 0.25;
input price = close;
input Extend_to_right = yes;
def netliq = GetNetLiq();
## Risk of Portfolio
def twoperc = netliq * (Max_Percent / 100);
AddLabel(yes, Max_Percent + "% ActRisk " + AsDollars(twoperc), Color.CYAN);
# Input position risk
input RiskPercent = .05 ;
# Position Size
def currentPrice = close;
def dollarRisk = (currentPrice * RiskPercent);
def stopPrice = (currentPrice - dollarRisk);
def SHAREStoBUY = twoperc / (currentPrice - stopPrice);
input showlabel = yes;
AddLabel (yes, " Cap " + AsDollars (SHAREStoBUY * currentPrice), Color.CYAN);
AddLabel (yes, AsPercent(RiskPercent) + " Risk " + AsDollars (currentPrice - (currentPrice * RiskPercent)), Color.CYAN);
AddLabel (yes, " Pos " + RoundUp ((SHAREStoBUY), 0), Color.LIGHT_GREEN);
#Position Targets
def GetAveragePrice = GetAveragePrice();
def TargetPrice = Round((GetAveragePrice * .05) + GetAveragePrice);
def TargetPrice2 = Round((GetAveragePrice * .10) + GetAveragePrice);
def TargetPrice3 = Round((GetAveragePrice * .20) + GetAveragePrice);
def TargetPrice4 = Round((GetAveragePrice * .50) + GetAveragePrice);
def TargetPrice5 = Round((GetAveragePrice * 1.00) + GetAveragePrice);
def dollarStop = Round(GetAveragePrice - (GetAveragePrice * RiskPercent));
AddLabel (yes, "Stop " + AsDollars(dollarStop), Color.LIGHT_RED);
AddLabel (yes, "5% " + AsDollars(TargetPrice), if GetAveragePrice <= 0 then Color.Black else Color.LIGHT_GREEN);
AddLabel (yes, "10% " + AsDollars(TargetPrice2), if GetAveragePrice <= 0 then Color.Black else Color.LIGHT_GREEN);
AddLabel (yes, "20% " + AsDollars(TargetPrice3), if GetAveragePrice <= 0 then Color.Black else Color.LIGHT_GREEN);
# AddLabel (yes, "50% " + AsDollars(TargetPrice4), if GetAveragePrice <= 0 then Color.Black else Color.LIGHT_GREEN);
# AddLabel (yes, "100% " + AsDollars(TargetPrice5), if GetAveragePrice <= 0 then Color.Black else Color.GREEN);
plot s1 = if IsNaN(currentPrice) then Double.NaN else (currentPrice - (currentPrice * RiskPercent));
s1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
s1.SetDefaultColor(Color.PINK);
plot r1 = dollarStop;
r1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
r1.SetDefaultColor(Color.RED);
plot a1 = GetAveragePrice;
a1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
a1.SetDefaultColor(Color.BLUE);
plot t1 = TargetPrice; t1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); t1.SetDefaultColor(Color.GREEN);
plot t2 = TargetPrice2; t2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); t2.SetDefaultColor(Color.GREEN);
plot t3 = TargetPrice3; t3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); t3.SetDefaultColor(Color.GREEN);
# plot t4 = TargetPrice4; t4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); t4.SetDefaultColor(Color.GREEN);
# plot t5 = TargetPrice5; t5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); t5.SetDefaultColor(Color.GREEN);
Last edited by a moderator: