Automated trading with Pivot Points and Dojis
Forums › ProRealTime English forum › ProOrder support › Automated trading with Pivot Points and Dojis
- This topic has 84 replies, 5 voices, and was last updated 6 years ago by robertogozzi.
Tagged: candlestick pattern, doji, pivot points
-
-
05/14/2018 at 5:11 PM #70395
I tried to change the time frame for the daily pivot conditions by only considering the 34 candles before 16:30. But apparently that is also not working:(
12345678910111213if time = 163000 thennewdailyhigh = highest[34](high)[0]newdailylow = lowest[34](low)[0]newdailyclose = close[0]endifPivot = (newdailyhigh[1] + newdailylow[1] + newdailyclose[1]) / 3R1 = 2*Pivot - newdailylow[1]S1 = 2*Pivot - newdailyhigh[1]rR2 = Pivot + (newdailyhigh[1] - newdailylow[1])S2 = Pivot - (newdailyhigh[1] - newdailylow[1])R3 = R1 + (newdailyhigh[1] - newdailylow[1])S3 = S1 - (newdailyhigh[1] - newdailylow[1])05/14/2018 at 7:11 PM #7042605/14/2018 at 7:25 PM #7042905/14/2018 at 8:37 PM #70430Sorry to bother you again, but it is almost working:) I enhanced to range of the day to the whole day from 0:00 till 23:59 and the pivot lines match those of the chart:) The profit is also still high. But now I have a new issue:( As you can see in the picture, the pivot lines are good for tuesdays till friedays but they are pretty messed up on mondays. I have no idea why that happens.
05/14/2018 at 9:46 PM #70434the pivot lines are good for tuesdays till friedays but they are pretty messed up on mondays
Now I’ve forgotten again what market this is on sorry? 🙂
Are the Pivot lines based on price the day before? If Yes, then the DAX and other markets open for 2 or 3 hours on Sunday night (e.g. EUR/USD @ 22:00 and DAX @ 23:00) so this could be screwing the Pivots for Monday??
Just an idea / immediate thoughts?
1 user thanked author for this post.
05/14/2018 at 11:39 PM #70436You don’t have to say sorry:) Yes it is the DAX, and you where right about sunday. Now I change the code to this and the pivot lines for mondays are align with those within the chart:) Thank you so much!!!
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465DEFPARAM CumulateOrders = falseDEFPARAM FlatBefore = 000000DEFPARAM FlatAfter = 234500if OpenDayOfWeek = 1 thenPivot = (DHigh(2) + DLow(2) + DClose(2)) / 3R1 = 2*Pivot - DLow(2)S1 = 2*Pivot - DHigh(2)rR2 = Pivot + (DHigh(2) - DLow(2))S2 = Pivot - (DHigh(2) - DLow(2))R3 = R1 + (DHigh(2) - DLow(2))S3 = S1 - (DHigh(2) - DLow(2))endifif OpenDayOfWeek = 2 thenPivot = (DHigh(1) + DLow(1) + DClose(1)) / 3R1 = 2*Pivot - DLow(1)S1 = 2*Pivot - DHigh(1)rR2 = Pivot + (DHigh(1) - DLow(1))S2 = Pivot - (DHigh(1) - DLow(1))R3 = R1 + (DHigh(1) - DLow(1))S3 = S1 - (DHigh(1) - DLow(1))endifif OpenDayOfWeek = 3 thenPivot = (DHigh(1) + DLow(1) + DClose(1)) / 3R1 = 2*Pivot - DLow(1)S1 = 2*Pivot - DHigh(1)rR2 = Pivot + (DHigh(1) - DLow(1))S2 = Pivot - (DHigh(1) - DLow(1))R3 = R1 + (DHigh(1) - DLow(1))S3 = S1 - (DHigh(1) - DLow(1))endifif OpenDayOfWeek = 4 thenPivot = (DHigh(1) + DLow(1) + DClose(1)) / 3R1 = 2*Pivot - DLow(1)S1 = 2*Pivot - DHigh(1)rR2 = Pivot + (DHigh(1) - DLow(1))S2 = Pivot - (DHigh(1) - DLow(1))R3 = R1 + (DHigh(1) - DLow(1))S3 = S1 - (DHigh(1) - DLow(1))endifif OpenDayOfWeek = 5 thenPivot = (DHigh(1) + DLow(1) + DClose(1)) / 3R1 = 2*Pivot - DLow(1)S1 = 2*Pivot - DHigh(1)rR2 = Pivot + (DHigh(1) - DLow(1))S2 = Pivot - (DHigh(1) - DLow(1))R3 = R1 + (DHigh(1) - DLow(1))S3 = S1 - (DHigh(1) - DLow(1))endif1 user thanked author for this post.
05/15/2018 at 7:18 AM #70457Why not code fewer lines re days other than Day 1 and use …
123456789if OpenDayOfWeek <> 1 thenPivot = (DHigh(1) + DLow(1) + DClose(1)) / 3R1 = 2*Pivot - DLow(1)S1 = 2*Pivot - DHigh(1)rR2 = Pivot + (DHigh(1) - DLow(1))S2 = Pivot - (DHigh(1) - DLow(1))R3 = R1 + (DHigh(1) - DLow(1))S3 = S1 - (DHigh(1) - DLow(1))1 user thanked author for this post.
05/15/2018 at 11:09 PM #70557You are right, that looks better!:)
Unfortunately there still seems to be a problem with my stops.
I tried to set the stop to the highest high of the doji or of the confirmation candle right next to the doji. So if the high of the doji is higher, then this is my stop, and vice versa. Additionally the stop should be placed 2 points higher than those highs, because of the spread. But as you can see in the picture the trade is exited by the condition when a close ist higher than the previous high. It should have been closed somewhere around the red line. It would be nice if the stop was triggerd immediately and not at the open of the next candle. Thank you very much for your help!:)
123456789101112131415161718192021222324252627282930313233343536//DAX//15 minDEFPARAM CumulateOrders = falseDEFPARAM FlatBefore = 090000DEFPARAM FlatAfter = 173000Pivot = (DHigh(1) + DLow(1) + DClose(1)) / 3R1 = 2*Pivot - DLow(1)S1 = 2*Pivot - DHigh(1)rR2 = Pivot + (DHigh(1) - DLow(1))S2 = Pivot - (DHigh(1) - DLow(1))R3 = R1 + (DHigh(1) - DLow(1))S3 = S1 - (DHigh(1) - DLow(1))dojisize = 4.2*pipsizedoji = Range >= ABS(Open[1] - Close[1]) * dojisizebearishp = (doji and close[1] <= pivot+2 and close[1] >= pivot-2 and close<low[1])If bearishp ThenSellShort size Contract at Marketif shortonmarket and high>high[1] thenexitshort at (high+2*pipsize) stopendifif shortonmarket and high<high[1] thenexitshort at (high[1]+2*pipsize) stopendifEndifIF shortonmarket and (close >high[1]) thenexitshort at marketENDIF05/16/2018 at 7:58 AM #7056705/16/2018 at 2:09 PM #70627This did not change anything. And the conditions where it places the stop would also be neglected.
123456789101112131415//DAX//15 min exit strategyIf bearishp ThenSellShort size Contract at Marketexitshort at (high+2*pipsize) stopexitshort at (high+2*pipsize) stopEndifIF shortonmarket and (close >high[1]) thenexitshort at marketENDIF05/16/2018 at 6:19 PM #70643I tried a different approach but as soon as I added one more Pivot Line the system fails again and messes up. It works for only one Line, though. Within this approach I tried to store the candle conditions of the entry. It was also not possible to write the exitshort commands within the “if bearishp” conditions. I had to write them into new if conditions afterwards.
I don’t know what to try anymore, or if it will work at all like I planned. Any suggestions?:)
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061//DAX// 15 minDEFPARAM CumulateOrders = falseDEFPARAM FlatBefore = 090000DEFPARAM FlatAfter = 173000Pivot = (DHigh(1) + DLow(1) + DClose(1)) / 3R1 = 2*Pivot - DLow(1)S1 = 2*Pivot - DHigh(1)rR2 = Pivot + (DHigh(1) - DLow(1))S2 = Pivot - (DHigh(1) - DLow(1))R3 = R1 + (DHigh(1) - DLow(1))S3 = S1 - (DHigh(1) - DLow(1))dojisize = 4.2*pipsizedoji = Range >= ABS(Open[1] - Close[1]) * dojisizebearishp = (doji and close[1] <= pivot+2 and close[1] >= pivot-2 and close<low[1])bearishr1 = (doji and close[1] <= r1+2 and close[1] >= r1-2 and close<low[1])If bearishp thenif high<high[1] Thenhdbp = high[1]+2SellShort size Contract at Marketelsif high>high[1] thenhnbp = high+2sellshort size contract at marketendifendifif shortonmarket thenif hdbp thenexitshort at hdbp stopelsif hnbp thenexitshort at hnbp stopendifendifIf bearishr1 thenif high<high[1] Thenhdbr1 = high[1]+2SellShort size Contract at Marketelsif high>high[1] thenhnbr1 = high+2sellshort size contract at marketendifendifif shortonmarket and hdbr1 thenexitshort at hdbr1 stopendifif shortonmarket and hnbr1 thenexitshort at hnbr1 stopendifexitshort at (close >high[1]) stop05/16/2018 at 6:33 PM #70645Sorry to write again, but I coudn’t edit it anymore. A simple solution might be to set up 8 different trading systems where each system consideres a different Pivot line and execute all of them at the same time. Does that make sense?
05/16/2018 at 6:41 PM #70647I’m not one bit a supa-coder and have to visualise more complex actions happening in order to understand them and so all I have been doing is offering a solution to your snippets that you said did not work.
Maybe supa-coder @RobertoGozzi (or AN Other) might happen along anytime soon and see what is wrong with your System?
In the meantime, to make it easy for helpers …
- Post an equity curve of results from a backtest.
- What is the most significant function that is not working?
05/17/2018 at 1:17 AM #70660I was looking at code at post https://www.prorealcode.com/topic/automated-trading-with-pivot-points-and-dojis/page/3/#post-70557, these are the logical errors I could spot:
- lines 24 and 28 + 41 and 43 may assign new values to the variables that mimic a stoploss at each new bar because they do not tell between being or not ONMARKET and this behaviour will change the results of your attempts to exit due to SL, so they should not be changed ONCE a trade has been opened (line 22 should read If bearishp and Not OnMarket then)
- at lines 34, 36, 53 and 57 variables HDBP, HNBP, HDBR1 and HNBR1 will always be true once they have been set the first time, while you should reset them to ZERO when Not OnMarket, I guess;
- line 61 will NEVER be true, since you want to exit at a price which is either 0 or 1; for sure it won’t work with DAX, it may turn true with EUR/USD if that pair falls to 1.0000 and at that very moment that line is executed, what did you want to do with that line?
05/17/2018 at 12:23 PM #70698First of all, thank you very much!!! 😉
I changed a few things, but it is still not executing the exitshorts when hitting the highest high of the doji or the trigger candle. Where the red circle is, was it supposed to exit.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107//DAX//15 minDEFPARAM CumulateOrders = falseDEFPARAM FlatBefore = 090000DEFPARAM FlatAfter = 173000if OpenDayOfWeek = 1 thenPivot = (DHigh(2) + DLow(2) + DClose(2)) / 3R1 = 2*Pivot - DLow(2)endifif OpenDayOfWeek = 2 thenPivot = (DHigh(1) + DLow(1) + DClose(1)) / 3R1 = 2*Pivot - DLow(1)endifif OpenDayOfWeek = 3 thenPivot = (DHigh(1) + DLow(1) + DClose(1)) / 3R1 = 2*Pivot - DLow(1)endifif OpenDayOfWeek = 4 thenPivot = (DHigh(1) + DLow(1) + DClose(1)) / 3R1 = 2*Pivot - DLow(1)endifif OpenDayOfWeek = 5 thenPivot = (DHigh(1) + DLow(1) + DClose(1)) / 3R1 = 2*Pivot - DLow(1)endifdojisize = 4.2*pipsizedoji = Range >= ABS(Open[1] - Close[1]) * dojisizebearishp = (doji and close[1] <= pivot+2 and close[1] >= pivot-2 and close<low[1])bearishr1 = (doji and close[1] <= r1+2 and close[1] >= r1-2 and close<low[1])size = 5If bearishp and not onmarket thenif high<high[1] Thenhdbp = high[1]+2SellShort size Contract at Marketelsif high>high[1] thenhnbp = high+2sellshort size contract at marketendifendifif shortonmarket thenif hdbp thenexitshort at hdbp stopelsif hnbp thenexitshort at hnbp stopendifendifIf bearishr1 and not onmarket thenif high<high[1] Thenhdbr1 = high[1]+2SellShort size Contract at Marketelsif high>high[1] thenhnbr1 = high+2sellshort size contract at marketendifendifif shortonmarket and hdbr1 thenexitshort at hdbr1 stopendifif shortonmarket and hnbr1 thenexitshort at hnbr1 stopendifif shortonmarket and (close >high[1]) thenexitshort at marketendifif not onmarket thenhdbp = 0hnbp = 0hdbr1 = 0hnbr1 = 0endif -
AuthorPosts
Find exclusive trading pro-tools on