Identifying Market Phases Using Moving Averages in ProBuilder

14 Jul 2024
0 comment
0 attachment

This code snippet is designed to identify six distinct market phases using two moving averages (MA50 and MA200) on a daily timeframe. It can be integrated into trading strategies to optimize entry and exit conditions based on the current market phase.

//Market Phases
// based off https://www.youtube.com/live/pXxmhZsqbzA?si=UbPSOTYNvrVpvc-v
Timeframe (1 day)
MA200 = average[200] (close)
MA50 = average[50] (close)
$mp[1] = close > MA50 and MA50 > MA200 and MA50[0] > MA50[1] and MA200[0] > MA200[1] //Bullish Phase
$mp[2] = close < MA50 and MA50 > MA200 // Warning Phase
$mp[3] = MA50[0] < MA50[1] and MA50 > MA200 and MA200[0] > MA200[1] //Distribution Phase
$mp[4] = MA50[0] < MA50[1] and MA200[0] < MA200[1] and MA50 < MA200 //Bearish Phase
$mp[5] = MA200[0] < MA200[1] and MA50[0] > MA50[1] and close > MA50 and close < MA200 //Recovery Phase
$mp[6] = close > MA50 and MA50[0] > MA50[1] and MA200[0] > MA200[1] //Accumulation Phase
Timeframe (default)
and $mp[x]

This code uses two key moving averages to determine the market’s phase:

  • MA200 (Moving Average over 200 days) and MA50 (Moving Average over 50 days) are calculated to represent long-term and medium-term trends, respectively.
  • $mp[1] identifies a Bullish Phase, where the price is above MA50, MA50 is above MA200, and both MAs are trending upwards.
  • $mp[2] signals a Warning Phase, where the price falls below MA50 but MA50 is still above MA200, indicating potential instability.
  • $mp[3] denotes a Distribution Phase, characterized by a declining MA50 while MA50 remains above MA200 and MA200 is trending upwards.
  • $mp[4] marks a Bearish Phase, with both MA50 and MA200 trending downwards and MA50 below MA200.
  • $mp[5] indicates a Recovery Phase, where MA200 is declining, MA50 is rising, and the price is between these two averages.
  • $mp[6] represents an Accumulation Phase, with both moving averages and the price trending upwards.

This approach allows traders to adapt their strategies based on the prevailing market conditions, potentially enhancing decision-making processes.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/market-phases-code-snippet/#post-237035

Visit Link
What is a Snippet? A snippet is a small, reusable chunk of code designed to solve specific tasks quickly. Think of it as a shortcut that helps you achieve your coding goals without reinventing the wheel. How to Use: Simply copy the snippet and paste it into your project where needed. Don't forget to tweak it to fit your context. Snippets are not just time-savers; they're also learning tools to help you become a more efficient coder.
Nicolas New
Trader, Programmer, Coder enthusiast. Work with each other for a common goal.
Author’s Profile

Comments

Search Snippets

Showing some results...
Sorry, no result found!

Snippets Categories

global
33
indicator
132
strategy
170

Recent Snippets

Utilizing Arrays to Track and Compare Indicator Values Within the Same Bar in ProBuilder
indicator
This ProBuilder code snippet demonstrates how to use arrays to compare the values of an indicator (RSI in this case) [...]
Calculating Break-Even Points in ProBuilder
strategy
This ProBuilder code snippet demonstrates how to calculate the break-even point for a trading position. The break-even [...]
Implementing Time and Day Restrictions in Trading Algorithms
strategy
This code snippet demonstrates how to set restrictions on trading activities based on specific days of the week and [...]
Implementing Partial Position Closure Based on Price Retracement in ProBuilder
strategy
This code snippet demonstrates how to partially close a trading position when the price retraces to a certain level in [...]
Implementing Single Trade Per Timeframe Logic in ProBuilder
strategy
This code snippet demonstrates how to ensure that only one trade is executed per timeframe in a trading strategy using [...]
Logo Logo
Loading...