i'm trying to feed the price which an arrow points at into a formula, how would I obtain the price?

Status
Not open for further replies.

Mr_Wheeler

Active member
I'm trying to obtain the value, in this case it would be $3.85

0cJuOJs.png


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);
 
Solution
It doesn't work.

My goal would be to divide 2000 dollars of my budget into shares at a price of 3.85 dollars a share as stated at the price at the green arrow.
So it would be a budget of 2000/ 3.85 = 519 shares. I would display the "519" in the green label next to the orange label that's currently showing "421 shares". What I'm having difficult with is getting my script to look up the last green arrow price.

The orange label tells me how many shares I could purchase at the current price, and the green label shows how many shares I can buy when the script tells me to buy shares.

Replace your buy arrow shares label with these two lines of code

Ruby:
def buy = if iTrend[1]==-1 and iTrend==1 and !HideArrows then TrendLine...
At just a quick glance, the actual data is stored in TrendLine, and in this case, it is conditionally plotted with buy_arrow... You could feed either of these variables into the later formula, depending on the formula and your intentions of course. You may need to be more specific.
 
Alright, I'll give it a shot. If you're wondering what I'm attempting I'm attempting to use the three moving day average lines as take-profit levels so you can analyze if it's worth holding above invidual moving average lines instead of taking profit and moving onto the next trade.

That way you don't have to constantly move back & forth between the charts & the trade analyze tab, be quick with your trades, and also set yourself some profit taking rules.

If you're up say 200 bucks it might not be worth holding out for another 50 dollars, and you could make that decision based on the 3 MDA lines & their accompanying labels, and the apparent momentum of a stock's price movement.
 
At just a quick glance, the actual data is stored in TrendLine, and in this case, it is conditionally plotted with buy_arrow... You could feed either of these variables into the later formula, depending on the formula and your intentions of course. You may need to be more specific.

It doesn't work.

My goal would be to divide 2000 dollars of my budget into shares at a price of 3.85 dollars a share as stated at the price at the green arrow.
So it would be a budget of 2000/ 3.85 = 519 shares. I would display the "519" in the green label next to the orange label that's currently showing "421 shares". What I'm having difficult with is getting my script to look up the last green arrow price.

The orange label tells me how many shares I could purchase at the current price, and the green label shows how many shares I can buy when the script tells me to buy shares.
 
It doesn't work.

My goal would be to divide 2000 dollars of my budget into shares at a price of 3.85 dollars a share as stated at the price at the green arrow.
So it would be a budget of 2000/ 3.85 = 519 shares. I would display the "519" in the green label next to the orange label that's currently showing "421 shares". What I'm having difficult with is getting my script to look up the last green arrow price.

The orange label tells me how many shares I could purchase at the current price, and the green label shows how many shares I can buy when the script tells me to buy shares.

Replace your buy arrow shares label with these two lines of code

Ruby:
def buy = if iTrend[1]==-1 and iTrend==1 and !HideArrows then TrendLine else buy[1];
AddLabel(yes, Concat("buy arrow shares = ", Round(arrow_purchase_price/buy,0)), Color.green);
 
Solution
Status
Not open for further replies.

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
144 Online
Create Post

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top