How to correctly locate a Buy Online signal


Category:
0
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;
input Price = close;
input tradeSize = 100;
input LowPrice = Low;

def UpperBolli = BollingerBands(“num dev dn” = -0.382, “num dev up” = 0.382).UpperBand;

# **** Find where 5 consecutive bars apear
def ConsecutiveAbove = if close >= UpperBolli and close[1] >= UpperBolli[1] and close[2] >= UpperBolli[2] and close[3] >= UpperBolli[3] and close[4] >= UpperBolli[4] then 1 else double.naN;

# temp points of Consecutive above
def ConsAbovePoint = if ConsecutiveAbove ==1 then close else double.naN;
plot ConsAbovePlot = ConsAbovePoint;
ConsAbovePlot.SetDefaultColor(Color.cyan);
ConsAbovePlot.SetLineWeight(2);
ConsAbovePlot.setstyle(curve.points);

# **** Define the end bar of the STHP (above the highest Bollinger band)
def STHP_Above_Flag = if (high[2] > UpperBolli[2] and high > UpperBolli and high[1] > UpperBolli[1]) then 1 else 0;

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;
Last_STHPPlot.SetDefaultColor(Color.blue);
Last_STHPPlot.SetLineWeight(2);
Last_STHPPlot.setstyle(curve.points);
plot STHPPlot = STHPivot;
STHPPlot.SetDefaultColor(Color.pink);
STHPPlot.SetLineWeight(5);
STHPPlot.setstyle(curve.points);

def STHP_ConsecAbove = if (!isNan(ConsecutiveAbove[1]) and high>=Last_STHP+Ticks_Above and high>UpperBolli) then Last_STHP+Ticks_Above else double.naN;
plot STHP_ConsecAbove_Plot = STHP_ConsecAbove;
STHP_ConsecAbove_Plot.SetDefaultColor(Color.dark_green);
STHP_ConsecAbove_Plot.SetLineWeight(5);
STHP_ConsecAbove_Plot.setstyle(curve.points);

def Buysignal = if (!isNan(ConsecutiveAbove[1]) and high>=Last_STHP+Ticks_Above and high>UpperBolli) then 1 else 0;

Attachments:
Marked as spam
Posted by (Questions: 2, Answers: 1)
Asked on December 8, 2017 2:36 am
143 views
0
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
Posted by (Questions: 37, Answers: 4118)
Answered on December 8, 2017 8:34 am
0

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!

( at December 8, 2017 9:56 am)