Reputation: 1
I want to write a program that consists of several parts When the first condition is true(met), the program should wait to check the next conditions in the candles that will be closed soon(in the future) It means to check the continuation in the future of the market, not the past of the market How should I write a program that can check the conditions in the future market candles?
for example: I have a moving average 20 and a moving 50 I want when the bullish cross is formed, after seeing the bullishcross, my program will start to check the every future candles of the market and any candle that had a pullback to the moving 50 and its shadow would touch the moving 50 thats my signal and indicate it to me.
I need someone help me with an example of pinescript code
Upvotes: 0
Views: 180
Reputation: 21382
You need to look at the current bar and set a var
flag if a certain event takes place. Then you wait for new bars to form and check for your additional condition and check the state of your flag.
Here is an example for you from the F.A.Q.
How can I save a value when an event occurs?
//@version=4
study("Save a value when an event occurs", "", true)
hiHi = highest(high, 5)[1]
var float priceAtCross = na
if crossover(close, hiHi)
// When a cross occurs, save price. Since variable was declared with "var" keyword,
// it will then preserve its value until the next reassignment occurs at the next cross.
// Very important to use the ":=" operator here, otherwise we would be creating a second,
// instance of the priceAtCross" variable local to the "if" block, which would disappear
// once the "if" block was exited, and the global variable "priceAtCross"'s value would then not have changed.
priceAtCross := close
plot(hiHi)
plot(priceAtCross, "Price At Cross", color.orange, 3, plot.style_circles)
Upvotes: 0