coding % of time the price reacts to pivot levels in Forex
Forums › ProRealTime English forum › ProScreener support › coding % of time the price reacts to pivot levels in Forex
- This topic has 6 replies, 2 voices, and was last updated 7 months ago by kadziak.
-
-
12/31/2023 at 6:03 PM #225858
Hi all,
I am looking for some help with coding this for PRT charts as I need to backtest something. It is a fairly simple analysis, just want to see the % of time the price reacts to pivot levels in Forex and by how much.
Chart set-up:
- Forex pairs major and minor
- Daily, Weekly and Monthly Pivots (Main pivot, S1,S2,S3, R1,R2,R3) Just these levels for all three.
I want to check the following on selected pairs:
- Within a given period, how many times did the price bounce off the daily, weekly or monthly pivot (within 2-3 pips of the pivot considering the spread)
- Stop loss would be between 7-20 pips (I need to able to test different variables here)
- Take profit R:R 1:2, 1:3 etc
I do not know coding, I am assuming more specifics may be required. Just wanted to give a brief info, not sure if this kind of backtesting is even possible on PRT.
Thanks in advance to anyone who responds.
Happy New Year to all!
Mike
01/11/2024 at 11:43 AM #226224Happy New Year Mike, do you need a screener or a strategy?
01/11/2024 at 7:58 PM #226256Hi
Thank you. I want to backtest this, so I am guessing that would be a strategy. Since pivots have an exact calculation, I wanted to test several pairs to find out which one reacts to them the most etc. Does that make sense? And since I have no idea how to code, this is like rocket science to me.
I am sure it would be possible to do this?
01/27/2024 at 4:30 PM #22694801/28/2024 at 4:15 PM #22697502/20/2024 at 6:56 PM #228473I just finished the MONTHLY test. It took quite a long time to code it in my spare time!
Adding the DAILY and WEEKLY tests will not be as time consuming as the MONTHLY-only version, as it will be a simple copy & paste with some minor editing, but I first want to know your feedback before going ahead, just to avoid wasting time in case the code does not meet your criteria.
I am posting this very first code, which is almost 300 lines, but next times, after finishing it, I will only attach the ITF file, as it will grow well over 500 hundreds lines, making the code and the post very tough to read:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291// https://www.prorealcode.com/topic/need-help-with-coding-this/Timeframe(default)ONCE FromDate = 20200101 //00000000 to start testing from the first bar loadedONCE ToDate = 20231231 //99999999 to finish testing on the current dateONCE PipBuffer = 3 * PipSize//ONCE TradeType = 1 //1=Monthly, 2=Weekly, 3=Daily, 9=allONCE LONGenabled = 1 //1=enable LONG trades, 0=disable LONG tradesONCE SHORTenabled = 1 //1=enable SHORT trades, 0=disable SHORT trades//ONCE WeeklySL = 20 * PipSizeONCE WeeklyTP = WeeklySL * 3//ONCE DailySL = 20 * PipSizeONCE DailyTP = DailySL * 3//TradeON = 0IF (OpenDate >= FromDate) AND (OpenDate <= ToDate) THENTradeON = 1ENDIF//Timeframe(Monthly,UpdateOnClose)ONCE MonthlySL = 20 * PipSizeONCE MonthlyTP = MonthlySL * 3//ONCE MonthlyWinLp = 0ONCE MonthlyWinSp = 0ONCE MonthlyLossLp = 0ONCE MonthlyLossSp = 0//ONCE MonthlyWinSr1 = 0ONCE MonthlyLossSr1 = 0ONCE MonthlyWinSr2 = 0ONCE MonthlyLossSr2 = 0ONCE MonthlyWinSr3 = 0ONCE MonthlyLossSr3 = 0//ONCE MonthlyWinLs1 = 0ONCE MonthlyLossLs1 = 0ONCE MonthlyWinLs2 = 0ONCE MonthlyLossLs2 = 0ONCE MonthlyWinLs3 = 0ONCE MonthlyLossLs3 = 0//ONCE BouncePvtM = 0ONCE BounceRes1M = 0ONCE BounceRes2M = 0ONCE BounceRes3M = 0ONCE BounceSus1M = 0ONCE BounceSup2M = 0ONCE BounceSup3M = 0//ONCE MonthlyPvtT = 0ONCE MonthlyRes1T = 0ONCE MonthlyRse2T = 0ONCE MonthlyRes3T = 0ONCE MonthlySup1T = 0ONCE MonthlySup2T = 0ONCE MonthlySup3T = 0//PivotM = (High[1] + Low[1] + Close[1]) / 3Res1M = PivotM + (PivotM - Low)Res2M = PivotM + (High - Low)Res3M = High + (2 * (PivotM - Low))Sup1M = PivotM - (High - PivotM)Sup2M = PivotM - (High - Low)Sup3M = Low - (2 * (High - PivotM))IF TradeON AND ((TradeType = 1) OR (TradeType = 9)) THEN//---------------------------------------------------------------------------// LONG exit//---------------------------------------------------------------------------IF MonthlyPvtT = 1 THENIF high >= MonthlyTPPvt THEN //TPMonthlyWinLp = MonthlyWinLp + 1MonthlyPvtT = 0ELSIF low <= MonthlyTPPvt THEN //SLMonthlyLossLp = MonthlyLossLp + 1MonthlyPvtT = 0ENDIFENDIF//IF MonthlySup1T THENIF high >= MonthlyTPSup1 THEN //TPMonthlyWinLs1 = MonthlyWinLs1 + 1MonthlySup1T = 0ELSIF low <= MonthlyTPSup1 THEN //SLMonthlyLossLs1 = MonthlyLossLs1 + 1MonthlySup1T = 0ENDIFENDIF//IF MonthlySup2T THENIF high >= MonthlyTPSup2 THEN //TPMonthlyWinLs2 = MonthlyWinLs2 + 1MonthlySup2T = 0ELSIF low <= MonthlyTPSup2 THEN //SLMonthlyLossLs2 = MonthlyLossLs2 + 1MonthlySup2T = 0ENDIFENDIF//IF MonthlySup3T THENIF high >= MonthlyTPSup3 THEN //TPMonthlyWinLs3 = MonthlyWinLs3 + 1MonthlySup3T = 0ELSIF low <= MonthlyTPSup3 THEN //SLMonthlyLossLs3 = MonthlyLossLs3 + 1MonthlySup3T = 0ENDIFENDIF//---------------------------------------------------------------------------// SHORT exit//---------------------------------------------------------------------------IF MonthlyPvtT = 2 THENIF low <= MonthlyTPPvt THEN //TPMonthlyWinSp = MonthlyWinSp + 1MonthlyPvtT = 0ELSIF high >= MonthlyTPPvt THEN //SLMonthlyLossSp = MonthlyLossSp + 1MonthlyPvtT = 0ENDIFENDIF//IF MonthlyRes1T THENIF low <= MonthlyTPRes1 THEN //TPMonthlyWinLs1 = MonthlyWinLs1 + 1MonthlyRes1T = 0ELSIF high >= MonthlyTPRes1 THEN //SLMonthlyLossLs1 = MonthlyLossLs1 + 1MonthlyRes1T = 0ENDIFENDIF//IF MonthlyRes2T THENIF low <= MonthlyTPRes2 THEN //TPMonthlyWinLs2 = MonthlyWinLs2 + 1MonthlyRes2T = 0ELSIF high >= MonthlyTPRes2 THEN //SLMonthlyLossLs2 = MonthlyLossLs2 + 1MonthlyRes2T = 0ENDIFENDIF//IF MonthlyRes3T THENIF low <= MonthlyTPRes3 THEN //TPMonthlyWinLs3 = MonthlyWinLs3 + 1MonthlyRes3T = 0ELSIF high >= MonthlyTPRes3 THEN //SLMonthlyLossLs3 = MonthlyLossLs3 + 1MonthlyRes3T = 0ENDIFENDIF//---------------------------------------------------------------------------// LONG entry//---------------------------------------------------------------------------IF LONGenabled THENxPivotM = PivotM + PipBufferyPivotM = PivotM - PipBufferIF (close > yPivotM) AND (low <= xPivotM) AND (MonthlyPvtT = 0) THENMonthlyPvtT = 1BouncePvtM = BouncePvtM + 1MonthlyEntryPvt = closeMonthlyTPPvt = MonthlyEntryPvt + MonthlyTP*PipSizeMonthlySLPvt = MonthlyEntryPvt - MonthlySL*PipSizeENDIF//xSup1M = Sup1M + PipBufferySup1M = Sup1M - PipBufferIF (close > ySup1M) AND (low <= xSup1M) AND (MonthlySup1T = 0) THENMonthlySup1T = 1BounceSup1M = BounceSup1M + 1MonthlyEntrySup1 = closeMonthlyTPSup1 = MonthlyEntrySup1 + MonthlyTP*PipSizeMonthlySLSup1 = MonthlyEntrySup1 - MonthlySL*PipSizeENDIF//xSup2M = Sup2M + PipBufferySup2M = Sup2M - PipBufferIF (close > ySup2M) AND (low <= xSup2M) AND (MonthlySup2T = 0) THENMonthlySup2T = 1BounceSup2M = BounceSup2M + 1MonthlyEntrySup2 = closeMonthlyTPSup2 = MonthlyEntrySup2 + MonthlyTP*PipSizeMonthlySLSup2 = MonthlyEntrySup2 - MonthlySL*PipSizeENDIFxSup3M = Sup3M + PipBufferySup3M = Sup3M - PipBufferIF (close > ySup3M) AND (low <= xSup3M) AND (MonthlySup3T = 0) THENMonthlySup3T = 1BounceSup3M = BounceSup3M + 1MonthlyEntrySup3 = closeMonthlyTPSup3 = MonthlyEntrySup3 + MonthlyTP*PipSizeMonthlySLSup3 = MonthlyEntrySup3 - MonthlySL*PipSizeENDIFENDIF//---------------------------------------------------------------------------// SHORT entry//---------------------------------------------------------------------------IF SHORTenabled THENxPivotM = PivotM + PipBufferyPivotM = PivotM - PipBufferIF (close < xPivotM) AND (high >= yPivotM) AND (MonthlyPvtT = 0) THENMonthlyPvtT = 2BouncePvtM = BouncePvtM + 1MonthlyEntryPvt = closeMonthlyTPPvt = MonthlyEntryPvt - MonthlyTP*PipSizeMonthlySLPvt = MonthlyEntryPvt + MonthlySL*PipSizeENDIF//xRes1M = Res1M + PipBufferyRes1M = Res1M - PipBufferIF (close < xRes1M) AND (high >= yRes1M) AND (MonthlyRes1T = 0) THENMonthlyRes1T = 1BounceRes1M = BounceRes1M + 1MonthlyEntryRes1 = closeMonthlyTPRes1 = MonthlyEntryRes1 - MonthlyTP*PipSizeMonthlySLRes1 = MonthlyEntryRes1 + MonthlySL*PipSizeENDIF//xRes2M = Res2M + PipBufferyRes2M = Res2M - PipBufferIF (close < xRes2M) AND (high <= yRes2M) AND (MonthlyRes2T = 0) THENMonthlyRes2T = 1BounceRes2M = BounceRes2M + 1MonthlyEntryRes2 = closeMonthlyTPRes2 = MonthlyEntryRes2 - MonthlyTP*PipSizeMonthlySLRes2 = MonthlyEntryRes2 + MonthlySL*PipSizeENDIFxRes3M = Res3M + PipBufferyRes3M = Res3M - PipBufferIF (close < xRes3M) AND (high >= yRes3M) AND (MonthlyRes3T = 0) THENMonthlyRes3T = 1BounceRes3M = BounceRes3M + 1MonthlyEntryRes3 = closeMonthlyTPRes3 = MonthlyEntryRes3 - MonthlyTP*PipSizeMonthlySLRes3 = MonthlyEntryRes3 + MonthlySL*PipSizeENDIFENDIFENDIF//===========================================================================//===========================================================================Timeframe(Weekly,UpdateOnClose)//PivotW = (High[1] + Low[1] + Close[1]) / 3Res1W = PivotW + (PivotW - Low)Res2W = PivotW + (High - Low)Res3W = High + (2 * (PivotW - Low))Sup1W = PivotW - (High - PivotW)Sup2W = PivotW - (High - Low)Sup3W = Low - (2 * (High - PivotW))////===========================================================================//===========================================================================Timeframe(Daily,UpdateOnClose)////PivotD = (High[1] + Low[1] + Close[1]) / 3Res1D = PivotD + (PivotD - Low)Res2D = PivotD + (High - Low)Res3D = High + (2 * (PivotD - Low))Sup1D = PivotD - (High - PivotD)Sup2D = PivotD - (High - Low)Sup3D = Low - (2 * (High - PivotD))//Timeframe(default)buy at -close limit//GRAPH MonthlyWinLp AS "Monthly Wins - LONG pvt"GRAPH MonthlyLossLp AS "Monthly Losses - LONG pvt"GRAPH MonthlyWinLs1 AS "Monthly Wins - LONG sup1"GRAPH MonthlyLossLs1 AS "Monthly Losses - LONG sup1"GRAPH MonthlyWinLs2 AS "Monthly Wins - LONG sup2"GRAPH MonthlyLossLs2 AS "Monthly Losses - LONG sup2"GRAPH MonthlyWinLs3 AS "Monthly Wins - LONG sup3"GRAPH MonthlyLossLs3 AS "Monthly Losses - LONG sup3"//GRAPH MonthlyWinSp AS "Monthly Wins - SHORT pvt"GRAPH MonthlyLossSp AS "Monthly Losses - SHORT pvt"GRAPH MonthlyWinSr1 AS "Monthly Wins - SHORT res1"GRAPH MonthlyLossSr1 AS "Monthly Losses - SHORT res1"GRAPH MonthlyWinSr2 AS "Monthly Wins - SHORT res2"GRAPH MonthlyLossSr2 AS "Monthly Losses - SHORT res2"GRAPH MonthlyWinSr3 AS "Monthly Wins - SHORT res3"GRAPH MonthlyLossSr3 AS "Monthly Losses - SHORT res3"the attached pic shows how data will be plotted in the variable panel of the backtest.
Lines 2-16 are self-explanatory.
Line 273 (the BUY line) serves no purpose other than abiding by the requirement of ProBackTest.
As to GRAPH, I fear the dubugging lines exceed the limit of ProBackTest, so I suggest to first monitor the LONG performance only by commenting out the SHORT lines, then reverting the comments to test the SHORT performance.
1 user thanked author for this post.
04/19/2024 at 10:14 AM #231685Hi Roberto,
Thank you so much for this, I really appreciate it. I see the date you sent this message was in Feb, for whatever reason I did not receive a message from the portal notifying me of your response. So, apologies for my late reply. I just got a message yesterday with the ITF file.
Once again, thank you very much for the work you put into this. I hope this will work.
Best regards
Mike
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on