Prevent entry near pivot points
Forums › ProRealTime English forum › ProOrder support › Prevent entry near pivot points
- This topic has 6 replies, 5 voices, and was last updated 2 years ago by Nicolas.
-
-
08/19/2020 at 10:02 AM #141997
Hi Guys, hope everyone is well.. loving how informative this platform is..
Was curious if anyone would kindly help me code a condition as part of a strategy.. and that is to prevent orders being opened when they are in close proximity to a pivot point..
e.g. No longs within 5 points of R1, R2, R3
e.g. No Shorts within 5 points of S1, S2, S3These are key reversal points, or where lots of bids are stacked and I find that majority of my losses come from when the automated system enters close to these.
Simply put, the strategy would be superior if somehow it could determine these areas.
Would love some help, albeit I am very very basic, only just picked this up last week so apologies in advance.
1 user thanked author for this post.
08/19/2020 at 10:27 AM #142006The below code could work for this purpose, I let you analyze it, i did not test it, it is just a quick rough version:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273DEFPARAM Cumulateorders=falsedist = 5 //distance from pivot points s/rx = dist*pointsize//find proximity of pivot pointsHt = DHigh(1)Bs = DLow(1)C = DClose(1)Pivot = (Ht + Bs + C) / 3Res3 = Res1 + (Ht - Bs)Res2 = Pivot + Ht - BsRes1 = (2 * Pivot) - BsSup1 = (2 * Pivot) - HtSup2 = Pivot - (Ht - Bs)Sup3 = Sup1 - (Ht - Bs)prox=0if close>pivot then//** above Pivot **i=1while i<=2 doif i=1 thenfloor=res1ceil=res2if (close>floor-x and close<floor+x) or (close>ceil-x and close<ceil+x) thenprox=1breakendifelsif i=3 thenfloor=res2ceil=res3if (close>floor-x and close<floor+x) or (close>ceil-x and close<ceil+x) thenprox=1breakendifendifi=i+1wendelsif close<pivot then//** below Pivot **i=1while i<=2 doif i=1 thenfloor=sup2ceil=sup1if (close>floor-x and close<floor+x) or (close>ceil-x and close<ceil+x) thenprox=1breakendifelsif i=2 thenfloor=sup3if (close>floor-x and close<floor+x) or (close>ceil-x and close<ceil+x) thenprox=1breakendifendifi=i+1wendendif// dummy strategya=rsi[14] crosses over 50 and not proxIF a and not longonmarket THENBUY 1 CONTRACT AT marketset target pprofit 10set stop ploss 5ENDIFgraphonprice floor coloured(0,200,200)graphonprice ceil coloured(200,0,0)graph prox1 user thanked author for this post.
08/19/2020 at 2:36 PM #14205910/16/2022 at 8:38 AM #20260610/16/2022 at 9:15 AM #202609Hi,
floor (and ceil too, ligne 26) were introduced recently as reserved keywords of the language, year of this code 2020 sounds old enough to be “before” they became reserved keywords, so they used to be ok as variable names but not anymore. They have to be changed to other names of your choice, for example you could replace them with “myfloor” and “myceil”.
10/16/2022 at 1:54 PM #202618Thank you indeed, but this code does not in fact give what I want.
Actually, I think my problem is more complex.
I am looking for a code that allows me to put a blocking condition so as not to enter position if my price is too close to a pivot point, say a distance of X points. I would like to consider the Daily Weekly and Monthly pivot points.
The code that I have just created attached does not work, because I do not know how to code how the different levels are positioned between them, and to determine those which frame my price at the moment.
Indeed, the order of the pivot points is then no longer at all obvious and my price can be found for example S1 Daily and S2 Weekly depending on the configuration of the moment.
I hope my question is clear, and if anyone can help me out that would be great.
Thanks!
code prt12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061//find proximity of pivot points journalierHt = High(1)Bs = DLow(1)C = DClose(1)Pivot = (Ht + Bs + C) / 3Res3 = Res1 + (Ht - Bs)Res2 = Pivot + Ht - BsRes1 = (2 * Pivot) - BsSup1 = (2 * Pivot) - HtSup2 = Pivot - (Ht - Bs)Sup3 = Sup1 - (Ht - Bs)midres1 = (res1+pivot)/2midres2= (res2+res1)/2midres3= (res3+res2)/2midsup1=(sup1+pivot)/2midsup2=(sup2+sup1)/2midsup3=(sup3+sup2)/2if close > pivot and close < midres1 thenmyceil=midres1myfloor=pivotelsif close > midres1 and close < res1 thenmyceil=res1myfloor=midres1elsif close > res1 and close < midres2 thenmyceil=midres2myfloor=res1elsif close > midres2 and close < res2 thenmyceil=res2myfloor=midres2elsif close > res2 and close < midres3 thenmyceil=midres3myfloor=res2elsif close > midres3 and close < res3 thenmyceil=res3myfloor=midres3elsif close >sup3 and close < midsup3 thenmyceil=midsup3myfloor=sup3elsif close >midsup3 and close < sup2 thenmyceil=sup2myfloor=midsup3elsif close >sup2 and close < midsup2 thenmyceil=midsup2myfloor=sup2elsif close >midsup2 and close < sup1 thenmyceil=sup1myfloor=midsup2elsif close >sup1 and close < midsup1 thenmyceil=midsup1myfloor=sup1elsif close >midsup1 and close < pivot thenmyceil=pivotmyfloor=midsup1endifreturn myfloor, myceil10/17/2022 at 8:48 AM #202658Much better approach with help of variables in array. We store all pivot points into an array, and the fetch it to check if the current price is near of the pivot point, if that’s the case we do not allow any order to be opened.
You can fill the array $p with any other pivot points from any other time horizons (such as weekly, monthly, ..)
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647DEFPARAM Cumulateorders=falsedist = 5 //distance from pivot points s/rx = dist*pointsize//find proximity of pivot pointsHt = DHigh(1)Bs = DLow(1)C = DClose(1)Pivot = (Ht + Bs + C) / 3Res3 = Res1 + (Ht - Bs)Res2 = Pivot + Ht - BsRes1 = (2 * Pivot) - BsSup1 = (2 * Pivot) - HtSup2 = Pivot - (Ht - Bs)Sup3 = Sup1 - (Ht - Bs)//using arrays to store pivot points$p[0]= Pivot$p[1] = Res3$p[2] = Res2$p[3] = Res1$p[4] = Sup1$p[5] = Sup2$p[6] = Sup3//loop into the array to check if price is too neartradeok = 1for i = 0 to lastset($p)if abs(close-$p[i])<=x then //near a pivot pointtradeok=0 //no trading allowed!!breakendifnext// dummy strategyif tradeok thena=rsi[14] crosses over 50IF a and not longonmarket THENBUY 1 CONTRACT AT marketset target pprofit 10set stop ploss 5ENDIFendifgraph tradeok as "no pivot within range"1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on