Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
920 views
in Technique[技术] by (71.8m points)

pine script - How to buy at the previous candle open of a candle which satisfies my variable condition?

strategy("Impulsive Candle" , shorttitle="Big Candle", overlay = true , initial_capital = 100000)

I have made a variable which is defined as below:

impulsive_candle = (close-open) > 0.00102

I would like to buy when the price returns to the open of the most recent candle that satisfies the impulsive_candle condition defined above. I realise I can use the historical reference operator [] to gather previous candle data. e.g. open[1] gives me the value of the open of the previous candle, but I would like to do this for the most recent impulsive_candle.

I have tried:

buy = impulsive_candle(close[1]) == true

But this doesn't work.

I get this as my error: funRefInfo.typeExpression.dereference is not a function

So I tried making a function of the original variable (while keeping the original variable as is because I use it for plotting later):

impulsive_candle_func => (close-open) > 0.00102

And then writing:

buy = impulsive_candle_func(close[1]) == true

But still it's not working. Now I get: Script could not be translated from: |B|impulsive_candle_func => (close-open) as my error.

Any advice on how to resolve this would be appreciated.

question from:https://stackoverflow.com/questions/66068941/how-to-buy-at-the-previous-candle-open-of-a-candle-which-satisfies-my-variable-c

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...