Bounce from Previous day close

I just want a piece of code when the price bounces from the Previous Day's Close.

e.g. Previous Day's close is 200, today's open is 205 and after sometime the price comes towards Previous days close i.e. 200 and bounces from there. I would like Buy on the next candle which should be above Previous Day's close. Any help /suggestion is highly appreciated.
2020-05-26T18:30:00Z

Did not get any reply so far, is this possible or not, if possible I am ready to pay for the services, please let me know

You never mentioned if it was intraday/ daily. What you consider a bounce. I'll leave you with this quick template. May need some debugging. This is for intraday. Looks for a low .2% away from previous days close, if close is higher then open, enters next bars open.

You can modify some variables for a threshold area and how many trades per day.
No Sell conditions in that AFL either, leave that to you.

yesterday_close = TimeFrameGetPrice("C",inDaily,-1);// previous days daily close

dn = DateNum();
new_day = dn != Ref(dn,-1);
condition = L > yesterday_close * .998 AND L < yesterday_close * 1.002; // used .2% as a threshold area for bounce
upcandle = C > O; // candle closed higher

Buy_criteria = condition AND upcandle;
one_entry = Sum(Buy_criteria,BarsSince(new_day) ) <= 1;// limiting trade to 1 a day.

Buy = Buy_criteria AND one_entry;  
Sell = 0;//enter sell condition or use ApplyStop

BuyPrice = Open;
SellPrice = Close;

PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorGreen);

Thank you very much.
Will check and let you know.

image , its giving signals when it touches the previous day no matter from where the previous candles come(above or below), I am interested in where the previous candles should be above the previous day close before touching the previous day close as shown in the screenshot.Hope this is clear

Best Regards,

Not behind PC. You can see my first line “timeframegetprice”. I’m getting the close , in daily -1(one day back).

Write another line but get today’s open which would be zero.

Add a condition to buy where today’s open is greater then yesterday’s close.

Got to sweat a bit.

But still some unwanted results with below code, please let me know if have to do any other modification

Hld = IIf(C > Ref(MA(H, 3), -1), 1, IIf(C < Ref(MA(L, 3), -1), -1, 0));
Hlv = ValueWhen(Hld != 0, Hld, 1);
Hilo = IIf(Hlv == -1, MA(H, 3), MA(L, 3));

yesterday_close = TimeFrameGetPrice("C",inDaily,-1);// previous days daily close
today_open = TimeFrameGetPrice("O",inDaily, 0);
Open_cond = IIf(today_open > yesterday_close,True,False);

dn = DateNum();
new_day = dn != Ref(dn,-1);
condition = L > yesterday_close * .998 AND L < yesterday_close * 1.002; // used .2% as a threshold area for bounce
upcandle = C > O; // candle closed higher

Buy_criteria = condition AND upcandle;
one_entry = Sum(Buy_criteria,BarsSince(new_day) ) <= 1 AND Open_cond == 1;// limiting trade to 1 a day.

Buy = Buy_criteria AND one_entry;  
Sell = C < Hilo;

BuyPrice = Open;
SellPrice = Close;

PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorGreen);  

Filter = Buy;

Thank you very much for the help, I think I coming closure to what I want
Best Regards,

See if I can a chance today or tomorrow to go over it. Never really used intraday days and timeframegetprice.

One thing that didn’t make the copy and paste is a line for tradedelays.

Since I set buyprice at open, you want the open of the next bar. So at the top should be

Settradedelays(1,0,1,0);

Might be time to look at debugging with exploration and addcolum() or _tracef() and log window to see what values are at conditions.

Perhaps a condition you expect is a big up candle from yesterday’s close so you’d have to have a condition to see if the candle is bigger then average, ATR() be a good function for that.

Perhaps my threshold of .2% isn’t a good choice to account for volatility and range or the underlying and a ATR or stdev be a better measurement for your needs.

As it stands, open is greater then yesterday’s close, low of candle comes without .2% of yesterday’s close, buy at open of next bar, only one test of yesterday close allowed.

You add other criteria you expect.

I am a Newbie and most the things you mentioned are beyond my programming skills, sorry for the inconvenience.

No inconvenience. If I had time I’d help out more. Work/baby keeping me busy.

1 Like
one_entry = Sum(Buy_criteria,BarsSince(new_day) ) <= 1 AND Open_cond == 1

Should be < 1 for one entry. Change that and add Settradedelays(1,0,1,0)

Tried writing it another way. This one here looks for a low to cross yesterday's close but the close of the intraday bar has to be above the yesterday's daily close. I gave it a quick check between some dates it should've have resulted in a trade. Didn't spend too much time at debugging but a check of 10 trades or so looks good.

SetTradeDelays(1,0,1,0); // buy on open next bar, sell at current bar on close

Hld = IIf(C > Ref(MA(H, 3), -1), 1, IIf(C < Ref(MA(L, 3), -1), -1, 0));
Hlv = ValueWhen(Hld != 0, Hld, 1);
Hilo = IIf(Hlv == -1, MA(H, 3), MA(L, 3));

yesterday_close = TimeFrameGetPrice("C",inDaily,-1);// previous days daily close
today_open = TimeFrameGetPrice("O",inDaily,0);// today's open

dn = DateNum();
new_day = dn != Ref(dn,-1); //used to determine new day.

Buycondition = L <= yesterday_close AND C > yesterday_close; // if low crossed yesterday's closed above yesteray's high.
buycondition = ExRem(buycondition,new_day); // remove further signals until new day
first_signal = L == LLV(L,BarsSince(new_day)); /
bull_bar = C > O; 
Open_cond = IIf(today_open > yesterday_close,True,False);//open is greater then today's close.


Buy = buycondition AND Open_cond AND bull_bar AND first_signal;  
Sell = C < Hilo;

BuyPrice = Open;
SellPrice = Close;

PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorGreen);  

Filter = Buy;
2 Likes

Buy signal is given only for the first candle of the day, this is fine but it has to produce Buy signal later in the day when it bounces from the PC also.

Regards,

Its working very well on 20/30 min time frame but not on 5/10 min time frame.

Thank you very much for the help.

With Best Regards,