MACD histogram height

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #126462 quote
    trevor
    Participant
    Senior

    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

    // Conditions to enter long positions
    // MACDline crosses over 0
    indicator1 = MACDline[37/3, 77/3, 9](close)
    c1 = (indicator1 CROSSES OVER 0)
    
    // MACDline crossed over 0 within last 5 bars
    ONCE NbBarLimit = 5
    
    IF c1 THEN
    MyLimitBuy = close
    MyIndex = BarIndex
    ENDIF
    
    IF BarIndex >= MyIndex + NbBarLimit THEN
    MyLimitBuy = 0
    ENDIF
    
    //Histgram minimum height
    indicator2 = 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 THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    #126467 quote
    Vonasi
    Moderator
    Master

    There 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. 🙂

    #126469 quote
    Vonasi
    Moderator
    Master

    Add the following to the bottom of your code and you will get some clues as to what is going wrong.

    graph MACD [37/3, 77/3, 9](close)
    graph indicator1
    graph indicator2
    #126826 quote
    trevor
    Participant
    Senior

    Thank 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

    // Conditions to enter long positions
    // MACDline crosses over 0
    indicator1 = 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.00025
    IF c1 AND c2 AND NOT LongOnMarket THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    
    // Conditions to exit long positions
    indicator3 = MACDline[37/3, 77/3, 9](close)
    c3 = (indicator3 CROSSES UNDER 0)
    
    IF c3 THEN
    SELLSHORT AT MARKET
    ENDIF
    
    // Conditions to enter short positions
    indicator4 = MACDline[37/3, 77/3, 9](close)
    c4 = (indicator4 CROSSES UNDER 0)
    
    
    //Histgram minimum height
    indicator5 = MACD[37/3, 77/3, 0] (close) - MACD [37/3, 77/3, 9] (close)
    c5 = (indicator5 < -0.00025)
    
    
    // IF Histogram < -0.00025
    IF c4 AND c5 AND NOT ShortOnMarket THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    
    PRT-histogram-height.png PRT-histogram-height.png
    #126839 quote
    GraHal
    Participant
    Master

    Have 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?

    #127000 quote
    Nicolas
    Keymaster
    Master

    You should use integer for your MACD periods, the problem might come from rounding differences in the EMA calculation used in the MACD formula.

    #127160 quote
    trevor
    Participant
    Senior

    Thank 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.

     

    
    
    
    
    // Main code : 1MACD 1.2 simplified +stopsFX---------------
    
    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    
    
    
    // BUY  --------------------------------------------------------------------------------------
    // Conditions to enter long positions
    // MACDline crosses over 0 within 5 bars
    indicator1 = 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 THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    
    // Conditions to exit long positions
    indicator3 = MACDline[37/3, 77/3, 9](close)
    c3 = (indicator3 CROSSES UNDER 0)
    
    IF c3 THEN
    SELLSHORT AT MARKET
    ENDIF
    
    // SELL ------------------------------------------------------------------------------
    // Conditions to enter short positions
    indicator11 = 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 THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    
    // Conditions to exit short positions
    indicator14 = MACDline[37/3, 77/3, 9](close)
    c14 = (indicator14 CROSSES OVER 0)
    
    IF c14 THEN
    BUY AT MARKET
    ENDIF
    
    // Stops and targets
    SET STOP pTRAILING 50
    SET TARGET pPROFIT 100
    MACD-line-minus-Signal.png MACD-line-minus-Signal.png
    #127178 quote
    Vonasi
    Moderator
    Master

    The 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.

    #127348 quote
    trevor
    Participant
    Senior

    Thank 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.

    //-------------------------------------------------------------------------
    
    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    
    
    
    
    // Conditions to enter long positions
    // 1. MACDline crosses over
    indicator1 = MACD[37/3, 77/3, 9](close)
    c1 = (indicator1 CROSSES OVER 0.00025)
    
    // 2. MACD > MACD previous
    indicator2 = MACD[37/3, 77/3, 9](close)
    c2 = (indicator2 > indicator2[1])
       
    // 3. MACDline crossed over 0 within last 5 bars
    ONCE NbBarLimit = 5
    
    IF c1 THEN
    MyLimitBuy = close
    MyIndex = BarIndex
    ENDIF
    
    IF BarIndex >= MyIndex + NbBarLimit THEN
    MyLimitBuy = 0
    ENDIF
    
    // BUY ----------------------------------------     AND NOT LongOnMarket
    IF c1 AND c2 AND MyLimitBuy > 0 THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    
    // Conditions to exit long positions
    indicator3 = MACD[37/3, 77/3, 9](close)
    c3 = (indicator3 CROSSES UNDER 0)
    
    IF c3 THEN
    SELLSHORT AT MARKET
    ENDIF
    
    // Conditions to enter short positions
    // 1. MACDline crosses under
    indicator4 = MACDline[37/3, 77/3, 9](close)
    c4 = (indicator4 CROSSES UNDER -0.0025)
    
    // 2. MACD < MACD previous
    indicator5 = MACD[37/3, 77/3, 9](close)
    c5 = (indicator5 < indicator5[1])
    
    // 3.MACDline crossed over 0 within last 5 bars
    ONCE NbBarLimit = 5
    
    IF c1 THEN
    MyLimitBuy = close
    MyIndex = BarIndex
    ENDIF
    
    IF BarIndex >= MyIndex + NbBarLimit THEN
    MyLimitBuy = 0
    ENDIF
    
    //  BUY --------------------------------------------AND NOT SHORTOnMarket
    IF c4 AND c5 AND MyLimitBuy > 0 THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    
    // Conditions to exit short positions
    indicator6 = MACDline[37/3, 77/3, 9](close)
    c4 = (indicator6 CROSSES OVER 0)
    
    IF c4 THEN
    BUY AT MARKET
    ENDIF
    
    // Stops and targets
    SET STOP pTRAILING 50
    SET TARGET pPROFIT 100
    PRT-histogram-height-2.png PRT-histogram-height-2.png
    #127371 quote
    trevor
    Participant
    Senior

    This 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

    //-------------------------------------------------------------------------
    
    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    
    
    
    // BUY ----------------------------------------
    // Conditions to enter long positions
    // 1. MACDline crosses over
    indicator1 = MACD[37/3, 77/3, 9](close)
    c1 = (indicator1 CROSSES OVER 0.0003)
    
    IF c1 THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    
    // Conditions to exit long positions
    indicator3 = MACDline[37/3, 77/3, 9](close)
    c3 = (indicator3 CROSSES UNDER 0)
    
    IF c3 THEN
    SELLSHORT AT MARKET
    ENDIF
    
    
    //  SELL --------------------------------------------
    // Conditions to enter short positions
    // 1. MACDline crosses under
    indicator4 = MACD[37/3, 77/3, 9](close)
    c4 = (indicator4 CROSSES UNDER -0.0003)
    
    
    IF c4 THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    
    // Conditions to exit short positions
    indicator6 = MACDline[37/3, 77/3, 9](close)
    c6 = (indicator6 CROSSES OVER 0)
    
    IF c6 THEN
    BUY AT MARKET
    ENDIF
    
    // Stops and targets
    SET STOP $TRAILING 50
    SET TARGET $PROFIT 100

     

    This is the part that is not working. Copied from ‘creation by programming’

    // Conditions to enter long positions
    indicator1 = MACD[37/3, 77/3, 9](close)
    c1 = (indicator1 > 0.0003)
    
    IF c1 THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF

    Can I get a hand with this error please.

    trading-error3.png trading-error3.png trading-error4.png trading-error4.png trading-error5.png trading-error5.png
    #127385 quote
    Vonasi
    Moderator
    Master

    Can 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.

    #127399 quote
    Nicolas
    Keymaster
    Master

    By GRAPHin your variables in backtests, you will find many interesting information. Firstly, compare the MACD from the backtest and the MACD indicator on the chart.

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.

MACD histogram height


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 11 replies,
has 4 voices, and was last updated by Nicolas
5 years, 10 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 04/17/2020
Status: Active
Attachments: 6 files
Logo Logo
Loading...