♥ 0 |
Hi Pete, I’m trying to write a script for almost online buying but couldn’t locate the buy signal to be on the right bar. It apears on the next bar. The right bar is the one with the dark_green point. Can you explain how do I create an online buying signal? Thanks a lot! here is my script: input Ticks_Above = 0.2; def UpperBolli = BollingerBands(“num dev dn” = -0.382, “num dev up” = 0.382).UpperBand; # **** Find where 5 consecutive bars apear # temp points of Consecutive above # **** Define the end bar of the STHP (above the highest Bollinger band) def STHPivot = if (high < high[1] and high[1] > high[2] and STHP_Above_Flag>0) then high[1] else double.naN; rec Last_STHP = if (!isNan(STHPivot) and close>= UpperBolli and !isNan(ConsecutiveAbove)) then STHPivot else if (isNan(STHPivot) and close>= UpperBolli and !isNan(ConsecutiveAbove)) then Last_STHP[1] else double.naN; plot Last_STHPPlot = Last_STHP; def STHP_ConsecAbove = if (!isNan(ConsecutiveAbove[1]) and high>=Last_STHP+Ticks_Above and high>UpperBolli) then Last_STHP+Ticks_Above else double.naN; def Buysignal = if (!isNan(ConsecutiveAbove[1]) and high>=Last_STHP+Ticks_Above and high>UpperBolli) then 1 else 0;
Marked as spam
|
Private answer
The screenshot you provided is for a Strategy while the code you provided is for a Study. So I cannot diagnose what is causing this, or offer a direct remedy. Your code is missing the AddOrder statement, which is where the issue most likely resides. I have no idea what this means: “online buying” and “buy online” I see you are concerned about aligning the Theoretical Order with the first green dot. But you did not mention when the buy condition occurs. Does it occur at the open of the bar or the close of the bar? You don’t need to answer that, it is just for you to consider. What you are trying to address is an alignment issue. We have already addressed alignment issues in the following post: https://www.hahn-tech.com/ans/parablic-sar-signal-not-firing-in-tos-strategy/ In this post I provide three examples to demonstrate how to adjust the position of theoretical orders on a Strategy. I encourage you to use my very simple examples to practice on your own before trying to apply the corrections to your code. Be careful to ensure that your orders execute at the location and price level that is achievable when trading this strategy on a live chart. Otherwise, you have nothing but garbage. Marked as spam
|
Please log in to post questions.
Oh, sorry about that.
The order is:
addOrder (OrderType.BUY_TO_OPEN, Buysignal, Last_STHP+Ticks_Above, tradeSize, Color.CYAN, Color.CYAN);
By “Online” I mean the strategy should show a buy arrow at the first bar which PRICE is above the Last STHP (+some ticks above), but somehow it happens the next bar.
I will watch the post of course and try to learn from it.
Thanks!