问题
I have a strategy. I read that strategy is given open or low or high or close prices of a bar. I wonder if within a strategy. how the program can determine what the current price is and if it is equal to the open bar price. The program need to enter positions only at open bars.
回答1:
close
is the current/last price of a bar that is being rendered. Then you can compare close
with open
.
However, I would not recommend a strategy that is based on the current price. A lot can change during the intra-bar action and it is always a nice idea to wait until the bar closes. If you choose to use the current price, then you might have a lot of "repaint" issues. The outcome of your strategy will be very vulnerable to price actions and might give you different signals on the very same bar.
Try the following code:
//@version=3
study("My Script", overlay=true)
plotshape(series=close>open, style=shape.triangleup, color=green, location=location.belowbar, size=size.small)
plotshape(series=close<open, style=shape.triangledown, color=red, location=location.abovebar, size=size.small)
It is a simple code that plots a green/red triangle depending on if close > open
or close < open
. Then change your time frame to 1-min. Within 5 seconds, I got two different signals (a red triangle and a green triangle) on the same bar.
You can also see that close
is the last/current price in the screenshots.
来源:https://stackoverflow.com/questions/56413062/how-can-i-check-in-a-strategy-if-the-current-price-is-open-price