problem with plot...

wam1234

New member
Hi,

Here is a simple plot I woul dlike to have on my chart

def __signalup = if close[2]<open[2] and close[1]>open[1] then high[1] else Double.NaN;

plot _signaltriggered = if high>signalup then high else Double.Nan;

The problem I have is the plot only appears if it's the next candle that triggered the _signalup while I would like to have the plot when the _signalup is triggered even if it's 3 candles after the _signalup appeared.
Any ideas?
Thanks for your help!
 
Solution
Hi,

Here is a simple plot I woul dlike to have on my chart

def __signalup = if close[2]<open[2] and close[1]>open[1] then high[1] else Double.NaN;

plot _signaltriggered = if high>signalup then high else Double.Nan;

The problem I have is the plot only appears if it's the next candle that triggered the _signalup while I would like to have the plot when the _signalup is triggered even if it's 3 candles after the _signalup appeared.
Any ideas?
Thanks for your help!

this draws a green line above the bars, when signalup and signaltriggered are true.


it can get confusing if multiple condition formulas are assigning price levels. then you can't easily reference those formulas, to see if the condition was true. there is nothing...
# I tried within x bars, and I couldn't get it to work, so I just tried 3 different patterns :D

Code:
# I see three patterns:
def barUP = close > open;
def barDN = close < open;
def barHB1 = high > high[1];
def barHB2 = high > high[2];
def barHB3 = high > high[3];

def pattern1 = barDN[2] && barUP[1] && barHB1;
def pattern2 = barDN[3] && barUP[2] && barHB2;
def pattern3 = barDN[4] && barUP[3] && barHB3;

plot patternType = 
if      pattern1 then 1 
else if pattern2 then 2
else if pattern3 then 3
else double.NaN;
patternType.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
patternType.AssignValueColor(Color.White);

plot signaltriggered = if PatternType == 1 then high 
else if PatternType == 2 then high
else if PatternType == 3 then high
else Double.NaN;
signaltriggered.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
signalTriggered.SetDefaultColor(Color.GREEN);
 
Hi,

Here is a simple plot I woul dlike to have on my chart

def __signalup = if close[2]<open[2] and close[1]>open[1] then high[1] else Double.NaN;

plot _signaltriggered = if high>signalup then high else Double.Nan;

The problem I have is the plot only appears if it's the next candle that triggered the _signalup while I would like to have the plot when the _signalup is triggered even if it's 3 candles after the _signalup appeared.
Any ideas?
Thanks for your help!

this draws a green line above the bars, when signalup and signaltriggered are true.


it can get confusing if multiple condition formulas are assigning price levels. then you can't easily reference those formulas, to see if the condition was true. there is nothing wrong with doing that, but sometimes if the price levels are assigned by other formulas, the program flow makes more sense.

changed the formulas, so when conditions are compared, the output is logical, 0 or 1 , not a price level.
def signal_up = if close[2] < open[2] and close[1] > open[1] then 1 else 0;
def signal_triggered = if signal_up and high > high[1] then 1 else 0;

these could be combined if signal_up isn't used elsewhere in the program. i left them separate.

add a plot that draws white wedges (small arrows) when signal_up occurs.

enter a number, default 3, for how many bars to look back at, to check if signal_triggered was true. it starts from the current bar. to skip the current bar , change signal_triggered[0] to signal_triggered[1]

use sum( ) to count how many times signal_triggered was true. if more than 0 then plot a line.

if sum( ) is greater 0, then plot a line at the bar high, times a factor.
there is a vertical factor number to adjust the level of the line. default is 0.8 , (high * (1 + 0.8/100))


Ruby:
# plot_0to3_barslater0a

#-----------------------------------------------
# original

# def signalup = if close[2] < open[2] and close[1] > open[1] then high[1] else Double.NaN;
# plot signaltriggered = if high > zsignalup then high else Double.Nan;

# -------------------------------------

# change the formulas, so when conditions are compared, the output is logical, 0 or 1 ,  not a price level.
# add a formula to assign a price level if the logical formulas are true ( signalup and signaltriggered )

def na = double.nan;

def signal_up = if close[2] < open[2] and close[1] > open[1] then 1 else 0;
def signal_triggered = if signal_up and high > high[1] then 1 else 0;
#def trig_level = if signal_triggered then high else na;

# draw a green wedge when signal_triggered is true
plot z1 = signal_triggered;
z1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_up);
z1.SetDefaultColor(Color.white);
z1.setlineweight(2);

input trigger_prev_x_bars = 3;
def trigger_len = if trigger_prev_x_bars < 1 then 1 else trigger_prev_x_bars;
# count the triggers during the previous x bars , starting with the current bar
#  to skip the current bar , change  signal_triggered[0]  to  signal_triggered[1] 
def sum_trig = sum(signal_triggered[0], trigger_len);


input line_ht_factor = 0.8;
plot trig_level = if sum_trig > 0 then (high * (1 + (line_ht_factor/100))) else na;
trig_level.SetDefaultColor(Color.green);
#
#

WFC 30D 1hr
ggDpUK0.jpg
 
Solution

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
279 Online
Create Post

Similar threads

Similar threads

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