Mr_Wheeler
Active member
I'm trying to obtain the value, in this case it would be $3.85
http://tos.mx/x6JtfmA
http://tos.mx/x6JtfmA
Code:
input Budget = 2000;
def current_price = close;
def Share_Quantity_purchase_limit = Budget / current_price;
########### Moving Average Lines ###########
input price = close;
input fastLength = 9;
input medLength = 50;
input slowLength = 200;
input displace = 0;
input averageType = AverageType.wilders;
plot fastAvg = MovingAverage(averageType, price[-displace], fastLength);
plot medAvg = MovingAverage(averageType, price[-displace], medLength);
plot slowAvg = MovingAverage(averageType, price[-displace], slowLength);
fastAvg.SetDefaultColor(CreateColor(51, 204, 255));
medAvg.SetDefaultColor(CreateColor(255, 95, 95));
slowAvg.SetDefaultColor(Color.WHITE);
fastAvg.SetLineWeight(2);
medAvg.SetLineWeight(2);
slowAvg.SetLineWeight(2);
fastAvg.SetPaintingStrategy(PaintingStrategy.DASHES);
medAvg.SetPaintingStrategy(PaintingStrategy.DASHES);
slowAvg.SetPaintingStrategy(PaintingStrategy.DASHES);
#####################################################
# Follow Line Indicator
# Coverted to ToS from TV by bigboss. Original © Dreadblitz
#https://usethinkscript.com/threads/follow-line-indicator.9789/
input BbPeriod = 9;
input BbDeviations = 1;
input UseAtrFilter = yes;
input AtrPeriod = 5;
input HideArrows = no;
def BBUpper=SimpleMovingAvg(close,BBperiod)+stdev(close, BBperiod)*BBdeviations;
def BBLower=SimpleMovingAvg(close,BBperiod)-stdev(close, BBperiod)*BBdeviations;
def BBSignal = if close>BBUpper then 1 else if close<BBLower then -1 else 0;
def TrendLine =
if BBSignal == 1 and UseATRfilter == 1 then
max(low-atr(ATRperiod),TrendLine[1])
else if BBSignal == -1 and UseATRfilter == 1 then
min(high+atr(ATRperiod),TrendLine[1])
else if BBSignal == 0 and UseATRfilter == 1 then
TrendLine[1]
else if BBSignal == 1 and UseATRfilter == 0 then
max(low,TrendLine[1])
else if BBSignal == -1 and UseATRfilter == 0 then
min(high,TrendLine[1])
else if BBSignal == 0 and UseATRfilter == 0 then
TrendLine[1]
else TrendLine[1];
def iTrend = if TrendLine>TrendLine[1] then 1 else if TrendLine < TrendLine[1] then -1 else iTrend[1];
plot buy_price = if iTrend[1]==-1 and iTrend==1 and !HideArrows then TrendLine else Double.NaN;
buy_price.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
buy_price.SetDefaultColor(Color.green);
buy_price.SetLineWeight(3);
plot sell_price = if iTrend[1]==1 and iTrend==-1 and !HideArrows then TrendLine else Double.NaN;
sell_price.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
sell_price.SetDefaultColor(Color.white);
sell_price.SetLineWeight(3);
plot buy_arrow = if iTrend[1]==-1 and iTrend==1 and !HideArrows then TrendLine else Double.NaN;
buy_arrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
buy_arrow.SetDefaultColor(Color.green);
buy_arrow.SetLineWeight(5);
plot sell_arrow = if iTrend[1]==1 and iTrend==-1 and !HideArrows then TrendLine else Double.NaN;
sell_arrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
sell_arrow.SetDefaultColor(Color.RED);
sell_arrow.SetLineWeight(5);
###### Math stuff for moving average profit labels ####
def arrow_purchase_price = budget / itrend ;
def profit_at_slowAvg = Share_Quantity_purchase_limit * slowAvg;
#def profit at medAvg
#def profit at fastAvg
############labels###########
AddLabel(yes, Concat("current price shares = ", Round(Share_Quantity_purchase_limit)), Color.orange);
AddLabel(yes, Concat("buy arrow shares = ", Round(arrow_purchase_price)), Color.green);
AddLabel(yes, Concat("Profit at slowAvg = ", Round ( Share_Quantity_purchase_limit * slowAvg)), Color.white);
AddLabel(yes, Concat("Profit at medAvg = ",Round( budget * medAvg)),(CreateColor(255,95,95)));
AddLabel(yes, Concat("Profit at fastAvg = ", Round(budget * fastAvg)),(CreateColor(51, 204, 255)));
########### Alerts########################
Alert(buy_arrow, "Time to buy!", Alert.Bar, Sound.Chimes);
Alert(sell_arrow, "Time to sell!", Alert.Bar, Sound.Bell);
def fastAvg_Alert = MovingAverage(averageType, price[-displace], fastLength) crosses MovingAverage(averageType, price[-displace], medLength);
Alert(fastAvg_Alert, "~~~~~fastAvg / medAvg cross over~~~~~", Alert.BAR, Sound.Chimes);