bottomphishing
New member
Having trouble getting the target lines to plot correctly. The problem is they are plotting current trade averages and prior averages for trades I haven't been in in quiet some time. I also added a predetermined stop loss for trades I have not entered yet in order to see my risk real time at the current price. This plots under all candles displayed on the chart. Idk why. Lastly I'm having trouble extending these target plots right. Any help will be greatly appreciated.
Screenshots:
No position: https://ibb.co/NTrzWMp
No positions showing past trades targets: https://ibb.co/dWzgZmz
With Position: https://ibb.co/Fqjz3gY
Below is the 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 = .03 ;
# Position Size
def currentPrice = close;
def dollarRisk = (currentPrice * RiskPercent);
def stopPrice = (currentPrice - dollarRisk);
def SHAREStoBUY = twoperc / (currentPrice - stopPrice);
input showlabel = yes;
AddLabel (yes, " Pos " + RoundUp ((SHAREStoBUY), 0), Color.CYAN);
AddLabel (yes, AsPercent(RiskPercent) + " Risk " + AsDollars (currentPrice - (currentPrice * RiskPercent)), Color.VIOLET);
AddLabel (yes, " Cap " + AsDollars (SHAREStoBUY * currentPrice), Color.CYAN);
#Position Targets
def GetAveragePrice = GetAveragePrice();
def TargetPrice = Round((GetAveragePrice * .03) + GetAveragePrice); # Change Percent to 1 to 1
def TargetPrice2 = Round((GetAveragePrice * .06) + GetAveragePrice);
def TargetPrice3 = Round((GetAveragePrice * .09) + GetAveragePrice);
def TargetPrice4 = Round((GetAveragePrice * .50) + GetAveragePrice);
def TargetPrice5 = Round((GetAveragePrice * 1.00) + GetAveragePrice);
def dollarStop = Round(GetAveragePrice - (GetAveragePrice * RiskPercent));
AddLabel(1, " Targets: Stop: " + AsDollars(dollarStop) + " | 3%: " + AsDollars(TargetPrice) + " | 6%: " + AsDollars(TargetPrice2) + " | 9%: " + AsDollars(TargetPrice3) + " | 50%: " + AsDollars(TargetPrice4) + " | 100%: " + AsDollars(TargetPrice5), if GetAveragePrice <= 0 then Color.Black else Color.GREEN);
plot s1 = (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);
Screenshots:
No position: https://ibb.co/NTrzWMp
No positions showing past trades targets: https://ibb.co/dWzgZmz
With Position: https://ibb.co/Fqjz3gY
Below is the 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 = .03 ;
# Position Size
def currentPrice = close;
def dollarRisk = (currentPrice * RiskPercent);
def stopPrice = (currentPrice - dollarRisk);
def SHAREStoBUY = twoperc / (currentPrice - stopPrice);
input showlabel = yes;
AddLabel (yes, " Pos " + RoundUp ((SHAREStoBUY), 0), Color.CYAN);
AddLabel (yes, AsPercent(RiskPercent) + " Risk " + AsDollars (currentPrice - (currentPrice * RiskPercent)), Color.VIOLET);
AddLabel (yes, " Cap " + AsDollars (SHAREStoBUY * currentPrice), Color.CYAN);
#Position Targets
def GetAveragePrice = GetAveragePrice();
def TargetPrice = Round((GetAveragePrice * .03) + GetAveragePrice); # Change Percent to 1 to 1
def TargetPrice2 = Round((GetAveragePrice * .06) + GetAveragePrice);
def TargetPrice3 = Round((GetAveragePrice * .09) + GetAveragePrice);
def TargetPrice4 = Round((GetAveragePrice * .50) + GetAveragePrice);
def TargetPrice5 = Round((GetAveragePrice * 1.00) + GetAveragePrice);
def dollarStop = Round(GetAveragePrice - (GetAveragePrice * RiskPercent));
AddLabel(1, " Targets: Stop: " + AsDollars(dollarStop) + " | 3%: " + AsDollars(TargetPrice) + " | 6%: " + AsDollars(TargetPrice2) + " | 9%: " + AsDollars(TargetPrice3) + " | 50%: " + AsDollars(TargetPrice4) + " | 100%: " + AsDollars(TargetPrice5), if GetAveragePrice <= 0 then Color.Black else Color.GREEN);
plot s1 = (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: