Helping with a code
Forums › ProRealTime English forum › ProOrder support › Helping with a code
- This topic has 17 replies, 3 voices, and was last updated 8 years ago by Elsborgtrading.
-
-
07/28/2016 at 6:52 PM #10962
I need this idea translated to code if possible please?
Short: 50 EMA crosses under 200 EMA,
Price crosses over 50 and 200 ema
short entry on pivot or R1 or R2 or S1 or S2….
Also could I get for the long position too (see the second screenshot)
I have attached the screen shot..
Much appreciated
Thanks
1 user thanked author for this post.
07/29/2016 at 3:39 PM #1098807/30/2016 at 11:28 AM #10996Hi Jon. There are some missing infos here. when do you want to exit your positions?
Pivot what do you want , go short or long? It doesn’t make sense to say I want to go short and Long on Pivots. you need to be more specific. Anyway I made a simple code on the EMA200 and 50. it exits if the High or Low on ema 50 touches the price again, SL is set to 65. it should be easy to change the numbers. Unfortunately it doesn’t make any real profit- I tested it on 4H DAX.
Cheers
Kasper
12345678910111213141516171819202122232425262728293031323334353637383940// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// Conditions to enter long positionsindicator1 = Average[50](close)indicator2 = ExponentialAverage[200](close)c1 = (indicator1 CROSSES OVER indicator2)IF c1 THENBUY 1 CONTRACT AT MARKETENDIF// Conditions to exit long positionsindicator3 = Average[20](close)c2 = (low CROSSES UNDER indicator3)IF c2 THENSELL AT MARKETENDIF// Conditions to enter short positionsindicator4 = Average[50](close)indicator5 = ExponentialAverage[200](close)c3 = (indicator4 CROSSES UNDER indicator5)IF c3 THENSELLSHORT 1 CONTRACT AT MARKETENDIF// Conditions to exit short positionsindicator6 = Average[20](close)c4 = (high CROSSES OVER indicator6)IF c4 THENEXITSHORT AT MARKETENDIF// Stops and targetsSET STOP pLOSS 20//SET TARGET pPROFIT 651 user thanked author for this post.
07/30/2016 at 8:32 PM #11010Hi Kasper,
Thank you for making the code, much appreciated. Sorry, I didn’t make the idea more clear. Here is more thought-out idea…..
Long position,
50 Ema is over 200 EMA, then price crossed under EMA 50 and 200 and price equals pivot (this could be any of the R1, R2, S1 or S2 not just pivot level) (see the screen shot attached on first post) so entry is at Pivot.
Stop loss can be set to 10 points, trailing stop 10 points, and target can be till price touches 50 EMA.
Short Position,
200 Ema is over 50 EMA, then price crossed under EMA 200 and 50 and price equals pivot (this could be any of the R1, R2, S1 or S2 not just pivot level) (see the screen shot attached on first post) so entry is at Pivot.
Stop loss can be set to 10 points, trailing stop 10 points, and target can be till price touches 50 EMA.
Thank you again for the help
07/31/2016 at 8:32 AM #11014Hi Jon, I’m sorry I cant make this code. My attempts to code this, don’t shows no orders. this means that either I’m doing something wrong or the conditions are never met.
here is a the code for a simple test only for the Pivot line
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// Conditions to enter long positionsindicator1 = Average[50](close)indicator2 = Average[200](close)c1 = (indicator1 > indicator2)indicator3 = closeindicator4 = Average[50](close)c2 = (indicator3 CROSSES UNDER indicator4)Pivot1Long = (DHigh(1) + DLow(1) + DClose(1))/3c3 = (high[1] = Pivot1Long)c33= Pivot1Long[1]<closeIF c1 AND c2 AND c3 and c33 THENBUY 1 CONTRACT AT MARKETENDIF// Conditions to exit long positionsindicator6 = Average[50](close)indicator7 = closec4 = (indicator6 CROSSES OVER indicator7)IF c4 THENSELL AT MARKETENDIF// Conditions to enter short positionsindicator8 = Average[200](close)indicator9 = Average[50](close)c5 = (indicator8 > indicator9)indicator10 = closeindicator11 = Average[200](close)c6 = (indicator10 CROSSES UNDER indicator11)Pivot1short = (DHigh(1) + DLow(1) + DClose(1))/3c7 = (low[1] CROSSES UNDER Pivot1Short)c77=Pivot1Short[1]>closeIF c5 AND c6 AND c7 and c77 THENSELLSHORT 1 CONTRACT AT MARKETENDIF// Conditions to exit short positionsindicator13 = closeindicator14 = Average[50](close)c8 = (indicator13 = indicator14)IF c8 THENEXITSHORT AT MARKETENDIF// Stops and targets//SET STOP pLOSS 10 pTRAILING 1007/31/2016 at 10:47 AM #1101707/31/2016 at 12:01 PM #11020Hi Nicolas, and Thanks. I also found other errors, and I have some time to think it over, between diaper change and gardening 😊
I will get back a bit later with something.
07/31/2016 at 1:12 PM #11022Hi Jon. This is what I came up with. Seems like there is not to many trades in the 2 years I backtested it on DAX 30 min chart. that is maybe a subject to discuss as I didn’t look further into this. does the number of trades seems legit, should there be more?
It generates a small profit, but it closes the trades on the same bar. that means that we cant be sure if you were stopped out by SL due to limitation in backtesting with ProOrder. ProOrder only calculate profits on the same bar.
Anyway it generates a small profit over the last 2 years.
Cheers Kasper
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129// WORKING test 2.0 Pivot strategy// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// Conditions to enter long positionsindicator1 = Average[200](close)indicator2 = Average[50](close)c1 = (indicator1 < indicator2)indicator3 = closeindicator4 = Average[200](close)c2 = (indicator3 CROSSES OVER indicator4)Pivot1Long = (DHigh(1) + DLow(1) + DClose(1))/3S1DLong = 2*((DHigh(1) + DLow(1) + DClose(1))/3) - DHigh(1)S2DLong = (DHigh(1) + DLow(1) + DClose(1))/3-(DHigh(1)-DLow(1))S3DLong = DHigh(1)+2*(((DHigh(1) + DLow(1) + DClose(1))/3)-DLow(1))R1DLong = 2*((DHigh(1) + DLow(1) + DClose(1))/3) - DLow(1)R2DLong = (DHigh(1) + DLow(1) + DClose(1))/3+(DHigh(1)-DLow(1))R3DLong = DHigh(1)+2*((DHigh(1) + DLow(1) + DClose(1))/3-DLow(1))c3 = (close[1] crosses under Pivot1Long)c3S1D=(close[1] crosses under S1DLong)c3S2D=(close[1] crosses under S2DLong)c3S3D=(close[1] crosses under S3DLong)c3R1D=(close[1] crosses under R1DLong)c3R2D=(close[1] crosses under R2DLong)c3R3D=(close[1] crosses under R3DLong)c33= close[1]<closeIF (c1 AND c2 and c33 AND c3)thenBUY 1 CONTRACT AT MARKETendifif (c1 AND c2 and c33 AND c3S1D) thenBUY 1 CONTRACT AT MARKETendifif (c1 AND c2 and c33 AND c3S2D)thenBUY 1 CONTRACT AT MARKETendifif (c1 AND c2 and c33 AND c3S3D) thenBUY 1 CONTRACT AT MARKETendifif (c1 AND c2 and c33 AND c3R1D) thenBUY 1 CONTRACT AT MARKETendifif (c1 AND c2 and c33 AND c3R2D) thenBUY 1 CONTRACT AT MARKETendifif (c1 AND c2 and c33 AND c3R3D) THENBUY 1 CONTRACT AT MARKETENDIF// Conditions to exit long positionsindicator6 = closeindicator7 = Average[50](close)c4 = (indicator6 crosses under indicator7)IF c4 THENSELL AT MARKETENDIF// Conditions to enter short positionsindicator8 = Average[200](close)indicator9 = Average[50](close)c5 = (indicator8 > indicator9)indicator10 = closeindicator11 = Average[200](close)c6 = (indicator10 CROSSES UNDER indicator11)Pivot1short = (DHigh(1) + DLow(1) + DClose(1))/3S1DShort = 2*((DHigh(1) + DLow(1) + DClose(1))/3) - DHigh(1)S2DShort = (DHigh(1) + DLow(1) + DClose(1))/3-(DHigh(1)-DLow(1))S3DShort = DHigh(1)+2*(((DHigh(1) + DLow(1) + DClose(1))/3)-DLow(1))R1DShort = 2*((DHigh(1) + DLow(1) + DClose(1))/3) - DLow(1)R2DShort = (DHigh(1) + DLow(1) + DClose(1))/3+(DHigh(1)-DLow(1))R3DShort = DHigh(1)+2*((DHigh(1) + DLow(1) + DClose(1))/3-DLow(1))c7 = (low[1] CROSSES over Pivot1Short)c7S1D= (low[1] CROSSES over S1DShort)c7S2D=(low[1] CROSSES over S2DShort)c7S3D=(low[1] CROSSES over S3DShort)c7R1D= (low[1] CROSSES over R1DShort)c7R2D= (low[1] CROSSES over R2DShort)c7R3D= (low[1] CROSSES over R3DShort)c77=close[1]>closeIF (c5 AND c6 AND c77 and c7)thenSELLSHORT 1 CONTRACT AT MARKETendifif (C5 and c6 and c77 and c7S1D) thenSELLSHORT 1 CONTRACT AT MARKETendifif (c5 and c6 and c77 and c7S2D) thenSELLSHORT 1 CONTRACT AT MARKETendifif (c5 and c6 and c77 and c7S3D) thenSELLSHORT 1 CONTRACT AT MARKETendifif (c5 and c6 and c77 and c7R1D)thenSELLSHORT 1 CONTRACT AT MARKETendifif (c5 and c6 and c77 and c7R2D)thenSELLSHORT 1 CONTRACT AT MARKETendifif (c5 and c6 and c77 and c7R3D) thenSELLSHORT 1 CONTRACT AT MARKETENDIF// Conditions to exit short positionsindicator13 = closeindicator14 = Average[50](close)c8 = (indicator13 crosses over indicator14)IF c8 THENEXITSHORT AT MARKETENDIF// Stops and targetsSET STOP pLOSS 10 Ptrailing 507/31/2016 at 1:15 PM #11026more scrndumps
07/31/2016 at 11:47 PM #11042Kasper, thank you very much for taking out your time to provide me with the code.
I think it should have provided more than 44 trades in few years but this probably to do with limitation PRT rather than your code. But how easy would it be to transfer this idea and code you provided me into screener, which prehaps I manually enter position if the setup is correct?
thanks
08/01/2016 at 11:18 AM #11047Hi Jon.
Well It should be no problem to convert the code to both an indicator and a Screener. I think it also will be a good time to test if all S and R lines will be used. I changed your strategy a bit so when you have a retracement towards the Pivot, S and R lines, I test for the next candle actually bounces off and not going through. I think this gives a better strategy in terms of automatic trading. I will see how it turns out in a screener. But I’ve just returned to work from summertime so I can’t say when it will be finish.
Cheers Kasper
08/01/2016 at 12:15 PM #1105008/01/2016 at 2:31 PM #11064Hi Jon. I need to solve this problem. When I add Pivot indicators on price it’s only the current day it will display. If I need to verify your strategy with the actual code, I need the history of those lines in the chart. Otherwise I can’t see if I’m on the spot or not. It may be a simple issue, but in fact I started coding just a few weeks ago so many things are still new to me 🙂 I will try and ask in the community.
08/01/2016 at 2:38 PM #11065Ahh never mind, I think I found another Indicator that does what I want 🙂
08/01/2016 at 6:51 PM #11072Hi Jon. It was actually easier that expected. I have made both the screener and indicator. The code has change a bit in the structure, but they are the same. The indicator together with the backtest of the code will give you an idea when conditions are met. I still can’t verify if the code is in consistent with you requirements, so I guess you have to verify it, by looking at the results.
Further what the backtest shows, I wouldn’t put my money on as the issue with PRT and profit on zero bars is still an issue. PRT will only count the winnings and not the losses, unless there are no winners within the one bar of testing.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192//SCREENER// WORKING test 2.5 Pivot strategy INDICTORINDICATEUR = 0//INDICATEUR1 = 0// Conditions to enter long positionsindicator1 = Average[200](close)indicator2 = Average[50](close)c1 = (indicator1 < indicator2)indicator3 = closeindicator4 = Average[200](close)c2 = (indicator3 CROSSES OVER indicator4)Rule1 = 1//(BarIndex-TradeIndex)>=1Pivot1Long = (DHigh(1) + DLow(1) + DClose(1))/3S1DLong = 2*((DHigh(1) + DLow(1) + DClose(1))/3) - DHigh(1)S2DLong = (DHigh(1) + DLow(1) + DClose(1))/3-(DHigh(1)-DLow(1))S3DLong = DHigh(1)+2*(((DHigh(1) + DLow(1) + DClose(1))/3)-DLow(1))R1DLong = 2*((DHigh(1) + DLow(1) + DClose(1))/3) - DLow(1)R2DLong = (DHigh(1) + DLow(1) + DClose(1))/3+(DHigh(1)-DLow(1))R3DLong = DHigh(1)+2*((DHigh(1) + DLow(1) + DClose(1))/3-DLow(1))c3PvD = (close[1] crosses under Pivot1Long)c3S1D=(close[1] crosses under S1DLong)c3S2D=(close[1] crosses under S2DLong)c3S3D=(close[1] crosses under S3DLong)c3R1D=(close[1] crosses under R1DLong)c3R2D=(close[1] crosses under R2DLong)c3R3D=(close[1] crosses under R3DLong)c33= close[1]<closePivotLong = c1 AND c2 and c33 AND c3PvD and Rule1Sup1Long = c1 AND c2 and c33 AND c3S1D and Rule1Sup2Long = c1 AND c2 and c33 AND c3S2D and Rule1Sup3Long = c1 AND c2 and c33 AND c3S3D and Rule1Res1Long = c1 AND c2 and c33 AND c3R1D and Rule1Res2Long = c1 AND c2 and c33 AND c3R2D and Rule1Res3Long = c1 AND c2 and c33 AND c3R3D and Rule1If PivotLong or Sup1Long or Sup2Long or Sup3Long or Res1Long or Res2Long or Res3Long thenINDICATEUR =1elseINDICATEUR=0Endif// Conditions to enter short positionsindicator8 = Average[200](close)indicator9 = Average[50](close)c5 = (indicator8 > indicator9)indicator10 = closeindicator11 = Average[200](close)c6 = (indicator10 CROSSES UNDER indicator11)Pivot1short = (DHigh(1) + DLow(1) + DClose(1))/3S1DShort = 2*((DHigh(1) + DLow(1) + DClose(1))/3) - DHigh(1)S2DShort = (DHigh(1) + DLow(1) + DClose(1))/3-(DHigh(1)-DLow(1))S3DShort = DHigh(1)+2*(((DHigh(1) + DLow(1) + DClose(1))/3)-DLow(1))R1DShort = 2*((DHigh(1) + DLow(1) + DClose(1))/3) - DLow(1)R2DShort = (DHigh(1) + DLow(1) + DClose(1))/3+(DHigh(1)-DLow(1))R3DShort = DHigh(1)+2*((DHigh(1) + DLow(1) + DClose(1))/3-DLow(1))c7PvD = (low[1] CROSSES over Pivot1Short)c7S1D= (low[1] CROSSES over S1DShort)c7S2D=(low[1] CROSSES over S2DShort)c7S3D=(low[1] CROSSES over S3DShort)c7R1D= (low[1] CROSSES over R1DShort)c7R2D= (low[1] CROSSES over R2DShort)c7R3D= (low[1] CROSSES over R3DShort)c77=close[1]>closePivotShort = c5 AND c6 AND c77 and c7PvD and Rule1Sup1Short = c5 AND c6 AND c77 and c7S1D and Rule1Sup2Short = c5 AND c6 AND c77 and c7S2D and Rule1Sup3Short = c5 AND c6 AND c77 and c7S3D and Rule1Res1Short = c5 AND c6 AND c77 and c7R1D and Rule1Res2Short = c5 AND c6 AND c77 and c7R2D and Rule1Res3Short = c5 AND c6 AND c77 and c7R3D and Rule1IF PivotShort or Sup1Short or Sup2Short or Sup3Short or Res1Short or Res2Short or Res3Short thenINDICATEUR =-1elseINDICATEUR=0ENDIFscreener[INDICATEUR] -
AuthorPosts
Find exclusive trading pro-tools on