Help Creating Bull Market Indicator with a Custom Indicator

Forums ProRealTime English forum ProBuilder support Help Creating Bull Market Indicator with a Custom Indicator

  • This topic has 12 replies, 4 voices, and was last updated 5 years ago by avatarBard.
Viewing 13 posts - 1 through 13 (of 13 total)
  • #94831

    Hi

    I was studying Bulkowki’s Candlestick Patterns: https://www.prorealcode.com/topic/8-high-probability-bulkowski-candlestick-patterns/

    And wanted to make an indicator that would really define a Bull (and Bear) Market so that his percentage probabilities (eg there’s an 84% chance of a Bullish Reversal with a Bearish 3 Line Strike Up  in a Bull Market) could be traded upon.

    Bulkowski defined a Bull and Bear as:

    I define a bear market as when an index or average (I prefer the S & P 500 Index) declines by more than 20%. Similarly, a bull market occurs when the index or average rises by at least 20%. Based on this definition, you will not know you are in a bull or bear market until well after they have begun. The definition does not matter because the words bull and bear are just labels. Following the current market or stock trend is more important than a label.

    I added the moving averages condition (prices above the 50, 100 and 200 day moving averages) and this worked with a simple moving average but when I added the ALMA moving average I got a warning about the number of parameters called, pls see screenshot:

    Not sure how to solve that – tried adding variables for 50, 100 and 200 etc but that didn’t fix it.

    Also happy to hear of any other ideas how to make a better Bull / Bear indicator?

    Using simple moving averages it looked like this: Screens with 20% rule = images 1 & 2 and without (and just using moving averages), screen #3:

     

    #94844

    “Interestingly” the indicator acts at times as a good contrarian signal of the end of Bull and Bear markets too:

    Does anyone know how to make it have a “zero line axis” so it’s green on the top half and red on the bottom half of the indicator panel?

    Cheers

    #94851

    Add “,0” to line 20:

    Though this is not enough, by itself, to plot above/below the zero line. Values above/below 0 must be returned, I think the same line 20 should be replaced by (not tested) so that it returns either 1 or -1:

     

     

    1 user thanked author for this post.
    #94859

    Roberto

    is no good probleme

    #94888

    Because your “ALMA Moving Average” indicator doesn’t have any external setting, such as the period. I’m sure the settings are embedded directly in the code and not as external variables. Thought you were now perfectly trained for that newbie error Bard! (just joking) 😆

    #94913

    Thanks for sorting that out, thing is I’m not sure how to program it to buy when the Bear conditions end?

    For example after those (short period) red spikes have ended and the indicator has returned to neutral (zero), I would like the system to take a long trade at that point? (Pls see last screenshot). Because there are no “crossovers” I can’t make it do that. I’d also probably program the Buy rules to define a Bear spike as any Bear condition that lasts for less than 5 or maybe 10 days, (depending on backtests), it (the pull backs) appears – at least on observation – to be a great place to enter Long. Similar in concept to what Nicolas coded for me here: https://www.prorealcode.com/topic/how-would-you-create-a-mov-ave-distribution-histogram/#post-92863

    Cheers

    #94914

    Tbh, I didn’t spend too much time looking “under the hood” of the ALMA! And I certainly didn’t see “Period” because: “Fenetre…” sigh… 😄

    If I add “Fenetre” as a variable and strike it out in the original ALMA indicator code and my indicator “works,” well, it loaded okay even without adding //Fenetre in my code below (although I have just added it)… but is my code now referring to the new 50, 100, & 200 periods of this indicator code? I think it is.

     

    Also it doesn’t like “CALL” as it keeps re-calculating on my 15000 unit chart, even though I added DEFPARAM CalculateOnLastBars = 2000?

    Cheers

    #94933

    I always embed indicators in my code, to avoid CALLing them, whenever possible. You may try, despite you have to embed it three times or use a FOR…NEXT loop to calulate all of them (just in this case, since each MA is twice the previous one):

     

    1 user thanked author for this post.
    #94934

    Your full code would be (not tested):

     

    #94935

    Ps// To stop the indicator from constantly reloading I also tried to speed up the code with:

    but it says the variable myalma is not used in the code? I borrowed an example from the PRT manual: myindic = CALL “My Function” from p24 of : https://www.prorealtime.com/nl/pdf/probacktest_c1504281788c.pdf

    So I added the ALMA to the Bull/Bear indicator:

    I’m not sure why there are more Bull and Bear Spikes when the ALMA was being CALLED compared to embedded? Adding the ALMA into the Bull/Bear indicator produces a different set of Bear Bull Spikes compared to the original code where ALMA is CALLED in the code (the one I posted directly above in post #94914)?

    Pls see two screenshots below — one with the ALMA average not embedded and being CALLED  and the other with the ALMA code imbedded directly IN the indicator to avoid the CALL issue. The issue for me is how to get it to work using 3 different moving averages and whether I’ve achieved that or not.

    Cheers
    Veteran “Newbie” 😀

     

    #94939

    In line 1 you assign a value to MyAlma, you cannot later CALL it, since it is not an indicator and ProBuilder reports (correctly) that you are not using that variable. You should remove line 1 and replace “MyAlma” with “ALMA Moving Average” throughout the code when CALLing it.

    The way you embedded and use the code for the ALMA Average is wrong.

    You need to embed it three times (once for each average) using different names for variables, or use a FOR..NEXT loop. There’s no workaround.

    Lines 30-33 are absolutely wrong. Line 30 will assign ShortMA the value ALAaverage retained 50 periods ago! That has nothing to do to with computing the average of the last 50 periods!

    Moreover, you are ALWAYS using FENETRE as the number of periods, instead of the three different periods you would like to use.

    My code (https://www.prorealcode.com/topic/help-creating-bull-market-indicator-with-a-custom-indicator/#post-94934) will work the same as your code at https://www.prorealcode.com/topic/help-creating-bull-market-indicator-with-a-custom-indicator/#post-94914.

     

    1 user thanked author for this post.
    #95047

    Thanks very much @RobertoGozzi and @Nicolas, works very well. Better than Standard Deviation variances and Moving Average Distributions entries.

    It acts as a good contrarian indicator if you use those short term (couple of days) Bear Spikes as long entries: Dow Jones
    Pls see images (this indicator is the bottom of the two Bull/Bear indicators being used, the top one is just a regular 50, 100, 200 SMA).

    Dow Jones Daily/3.8 Spread/Random Dates: 26th Aug 2010 – 12 Oct 2017.
    Dev Stop 6.0 worked “best.” Everyones risk/drowdown profile is different.

    I was actually trying to enter Long AFTER a 3 day Bear Spike Pullback ENDS. The code above is a random accident in an attempt to code it as just described.

    Instinctively that’s where I feel the drawdowns can be reduced more through better entry timing. Hooking onto the price after it has plummeted and is already safe and returning back north not heading for possibly more falls as per the system as it currently stands.

    So now look at the Drawdown with a wild Dev Stop 6.0 and how it maintains the profits when using this entry:

    Cheers
    Bard

    #95053

    Logged out and back in and there’s definitely a few images didn’t post, 2nd attempt..

    Caveat: Wide Dev Stops like 6.0 are always late in catching quick adverse market turns. There is no one size fits all algo system. Different dates work better than others (even with the “genius” of John Ehler’s indcators), different setting work better than others. This example above is just illustrative of the search for better entries.. and it’s original intent: To define a Bull or Bear market for the purposes of Bulkowski’s Candlestick patterns.

Viewing 13 posts - 1 through 13 (of 13 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login