MACD histogram height
Forums › ProRealTime English forum › ProOrder support › MACD histogram height
- This topic has 11 replies, 4 voices, and was last updated 5 years ago by
Nicolas.
-
-
04/17/2020 at 5:58 AM #126462
Hello all. Fairly new to this PRT etc. coding.
The following code shows no errors, but does not work. I am trying to minimise the sea-saw effect (the back and forth over ‘0’ in the MACD simplified indicator).
For a buy
When the MACDline crosses over 0, and the histogram is higher than 0.00025 within 5 candles of the crossover
It will start the trade. As I said before, but the histogram height does not work.
It opens the trade whether the height is above or below the histogram height
Can someone please help/advise me. Many thanks
12345678910111213141516171819202122232425// Conditions to enter long positions// MACDline crosses over 0indicator1 = MACDline[37/3, 77/3, 9](close)c1 = (indicator1 CROSSES OVER 0)// MACDline crossed over 0 within last 5 barsONCE NbBarLimit = 5IF c1 THENMyLimitBuy = closeMyIndex = BarIndexENDIFIF BarIndex >= MyIndex + NbBarLimit THENMyLimitBuy = 0ENDIF//Histgram minimum heightindicator2 = MACD[37/3, 77/3, 0] (close) - MACD [37/3, 77/3, 9] (close)c2 = (indicator2 > 0.00025)// IF Histogram >IF c1 AND MyLimitBuy > 0 AND c2 AND NOT LongOnMarket THENBUY 1 CONTRACT AT MARKETENDIF04/17/2020 at 7:45 AM #126467There are some simple rules that everyone using the forums is expected to follow. Your post has broken one or more of these rules.
The forum rules are as follows. I have highlighted in bold the rule/rules that you have not followed:
Post your topic in the correct forum.
ProRealTime Platform Support only platform related issues.
ProOrder only strategy topics.
ProBuilder only indicator topics.
ProScreener only screener topics
General Discussion any other topics.
Welcome New Members for new forum members to introduce themselves.Only post in the language of the forum that you are posting in. For example English only in the English speaking forums and French only in the French speaking forums.
Always use the ‘Insert PRT Code’ button when putting code in your posts to make it easier for others to read.
Do not double post. Ask your question only once and only in one forum. All double posts will be deleted anyway so posting the same question multiple times will just be wasting your own time and will not get you an answer any quicker. Double posting just creates confusion in the forums.
Be careful when quoting others in your posts. Only use the quote option when you need to highlight a particular bit of text that you are referring to or to highlight that you are replying to a particular member if there are several involved in a conversation. Do not include large amounts of code in your quotes. Just highlight the text you want to quote and then click on ‘Quote’.
Give your topic a meaningful title. Describe your question or your subject in your title. Do not use meaningless titles such as ‘Coding Help Needed’.
Do not include personal information such as email addresses or telephone numbers in your posts. If you would like to contact another forum member directly outside of the forums then contact the forums administrator via ‘Contact Us’ and they will pass your details on to the member that you wish to contact.
Always be polite and courteous to others.
Have fun.I have edited your post where required. Please ensure that your future posts meet these few simple forum rules. 🙂
04/17/2020 at 7:53 AM #12646904/19/2020 at 12:10 AM #126826Thank you Vonasi.
The graph has highlighed the error.
Process 1. Macd crosses over 0. 2.Macd histogram is above 0.00025
Item 2 is not working. The formula is not correct or used, and the program opens regardless whether it is above or below histogram height.
The attachment shows 2 trades, one of which is open in demo mode. They both were below 0.00025 when opened and one was just over 0.
Any ideas of how to fix the formula greatly appreciated.
regards Trevor
123456789101112131415161718192021222324252627282930313233343536373839// Conditions to enter long positions// MACDline crosses over 0indicator1 = MACDline[37/3, 77/3, 9](close)c1 = (indicator1 CROSSES OVER 0)//Histgram minimum height//NOT WORKING///////////////////////////////////////////////////////////////indicator2 = MACD[37/3, 77/3, 0] (close) - MACD [37/3, 77/3, 9] (close)c2 = (indicator2 > 0.00025)// IF Histogram > 0.00025IF c1 AND c2 AND NOT LongOnMarket THENBUY 1 CONTRACT AT MARKETENDIF// Conditions to exit long positionsindicator3 = MACDline[37/3, 77/3, 9](close)c3 = (indicator3 CROSSES UNDER 0)IF c3 THENSELLSHORT AT MARKETENDIF// Conditions to enter short positionsindicator4 = MACDline[37/3, 77/3, 9](close)c4 = (indicator4 CROSSES UNDER 0)//Histgram minimum heightindicator5 = MACD[37/3, 77/3, 0] (close) - MACD [37/3, 77/3, 9] (close)c5 = (indicator5 < -0.00025)// IF Histogram < -0.00025IF c4 AND c5 AND NOT ShortOnMarket THENSELLSHORT 1 CONTRACT AT MARKETENDIF04/19/2020 at 9:19 AM #126839Have you tried using Cursor Details to see EXACTLY what that histo height is on the bar the entry conditions are met (the bar before actual entry bar)?
Unless I am missing something, the histo height appears to be above 0.00025 when the macd line crosses 0?
Right click, Display, Cursor Details and tell us exactly what the height of the histo is?
04/20/2020 at 9:02 AM #12700004/21/2020 at 3:41 AM #127160Thank you GraHal for your suggestion. Have used the cursor details window and the Histogram Height is not above 0.00025 or below for the sell -0.00025.
And thank you Nicolas also. I have tried the integers of MACD[12, 26, 9] (close), instead of the formula MACD[37/3, 77/3, 9] (close). It did not change anything.
I rewrote the code. Mainly looking back the 5 candles. indicator2, the MACD, is formulated to be the histogram height.
Changed the minimum height of the histogram to 10, which it almost never is in forex, to illustrate that indicator2 does not work.
The trades open whether the histogram height is 0.000001 or whatever.
How does the backtest have a result if the histogram height is never correct?
The attachment shows a trade opened by backtest with the MACD Line minus signal at 0.00016 shown in the cursor details window.
Any help or suggestions appreciated.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465// Main code : 1MACD 1.2 simplified +stopsFX---------------// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// BUY --------------------------------------------------------------------------------------// Conditions to enter long positions// MACDline crosses over 0 within 5 barsindicator1 = MACDline[37/3, 77/3, 9](close)c1 = (indicator1 CROSSES OVER 0)c1 = (indicator1 CROSSES OVER 0[1])c1 = (indicator1 CROSSES OVER 0[2])c1 = (indicator1 CROSSES OVER 0[3])c1 = (indicator1 CROSSES OVER 0[4])c1 = (indicator1 CROSSES OVER 0[5])indicator2 = MACD[37/3, 77/3, 9] (close)c2 = (indicator2 > 10.0)IF c1 AND c2 THENBUY 1 CONTRACT AT MARKETENDIF// Conditions to exit long positionsindicator3 = MACDline[37/3, 77/3, 9](close)c3 = (indicator3 CROSSES UNDER 0)IF c3 THENSELLSHORT AT MARKETENDIF// SELL ------------------------------------------------------------------------------// Conditions to enter short positionsindicator11 = MACDline[37/3, 77/3, 9](close)c11 = (indicator11 CROSSES UNDER 0)c11 = (indicator11 CROSSES UNDER 0[1])c11 = (indicator11 CROSSES UNDER 0[2])c11 = (indicator11 CROSSES UNDER 0[3])c11 = (indicator11 CROSSES UNDER 0[4])c11 = (indicator11 CROSSES UNDER 0[5])indicator12 = MACD[37/3, 77/3, 9] (close)c12 = (indicator12 < -10.0)IF c11 AND c12 THENSELLSHORT 1 CONTRACT AT MARKETENDIF// Conditions to exit short positionsindicator14 = MACDline[37/3, 77/3, 9](close)c14 = (indicator14 CROSSES OVER 0)IF c14 THENBUY AT MARKETENDIF// Stops and targetsSET STOP pTRAILING 50SET TARGET pPROFIT 10004/21/2020 at 8:21 AM #127178The red line on the MACD chart is the MACD signal line and not the MACD line.
Also having the same variable (c1 and c11) defined differently five times in a row will not work – it will simply use the last version of definition.
04/21/2020 at 11:05 PM #127348Thank you Vonasi, for your help. I have corrected the code. The MACD is the histogram height and that is what I now use.
But when I run the code, it still trades when the MACD line minus signal (9) is under the +or – 0.00025.
What is wrong with my code? Help me please.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879//-------------------------------------------------------------------------// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// Conditions to enter long positions// 1. MACDline crosses overindicator1 = MACD[37/3, 77/3, 9](close)c1 = (indicator1 CROSSES OVER 0.00025)// 2. MACD > MACD previousindicator2 = MACD[37/3, 77/3, 9](close)c2 = (indicator2 > indicator2[1])// 3. MACDline crossed over 0 within last 5 barsONCE NbBarLimit = 5IF c1 THENMyLimitBuy = closeMyIndex = BarIndexENDIFIF BarIndex >= MyIndex + NbBarLimit THENMyLimitBuy = 0ENDIF// BUY ---------------------------------------- AND NOT LongOnMarketIF c1 AND c2 AND MyLimitBuy > 0 THENBUY 1 CONTRACT AT MARKETENDIF// Conditions to exit long positionsindicator3 = MACD[37/3, 77/3, 9](close)c3 = (indicator3 CROSSES UNDER 0)IF c3 THENSELLSHORT AT MARKETENDIF// Conditions to enter short positions// 1. MACDline crosses underindicator4 = MACDline[37/3, 77/3, 9](close)c4 = (indicator4 CROSSES UNDER -0.0025)// 2. MACD < MACD previousindicator5 = MACD[37/3, 77/3, 9](close)c5 = (indicator5 < indicator5[1])// 3.MACDline crossed over 0 within last 5 barsONCE NbBarLimit = 5IF c1 THENMyLimitBuy = closeMyIndex = BarIndexENDIFIF BarIndex >= MyIndex + NbBarLimit THENMyLimitBuy = 0ENDIF// BUY --------------------------------------------AND NOT SHORTOnMarketIF c4 AND c5 AND MyLimitBuy > 0 THENSELLSHORT 1 CONTRACT AT MARKETENDIF// Conditions to exit short positionsindicator6 = MACDline[37/3, 77/3, 9](close)c4 = (indicator6 CROSSES OVER 0)IF c4 THENBUY AT MARKETENDIF// Stops and targetsSET STOP pTRAILING 50SET TARGET pPROFIT 10004/22/2020 at 2:50 AM #127371This PRT code does not work. Code created by simplified creation. See attachment error3
I then switched to creation by programming and copied that to my code(attachment error4).
The full code-
This is the PRT code created through their program. It still opens trades but 5 of the 12 trades are outside +or- 0.0003. See third attachment
THE FULL CODE123456789101112131415161718192021222324252627282930313233343536373839404142434445464748//-------------------------------------------------------------------------// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// BUY ----------------------------------------// Conditions to enter long positions// 1. MACDline crosses overindicator1 = MACD[37/3, 77/3, 9](close)c1 = (indicator1 CROSSES OVER 0.0003)IF c1 THENBUY 1 CONTRACT AT MARKETENDIF// Conditions to exit long positionsindicator3 = MACDline[37/3, 77/3, 9](close)c3 = (indicator3 CROSSES UNDER 0)IF c3 THENSELLSHORT AT MARKETENDIF// SELL --------------------------------------------// Conditions to enter short positions// 1. MACDline crosses underindicator4 = MACD[37/3, 77/3, 9](close)c4 = (indicator4 CROSSES UNDER -0.0003)IF c4 THENSELLSHORT 1 CONTRACT AT MARKETENDIF// Conditions to exit short positionsindicator6 = MACDline[37/3, 77/3, 9](close)c6 = (indicator6 CROSSES OVER 0)IF c6 THENBUY AT MARKETENDIF// Stops and targetsSET STOP $TRAILING 50SET TARGET $PROFIT 100This is the part that is not working. Copied from ‘creation by programming’
1234567// Conditions to enter long positionsindicator1 = MACD[37/3, 77/3, 9](close)c1 = (indicator1 > 0.0003)IF c1 THENBUY 1 CONTRACT AT MARKETENDIFCan I get a hand with this error please.
04/22/2020 at 7:10 AM #127385Can you do what Nicolas told you to do and ditch the 37/3 and 77/3 from your MACD and MACDLINE instructions. The instructions should have only whole integers only.
Also I notice that your displayed indicator is the MACD Simplified and not MACD. They are different MACD calculations. Your ProOrder code is using the latter while you are comparing the results to the former.
04/22/2020 at 9:07 AM #127399 -
AuthorPosts
Find exclusive trading pro-tools on