Coding trading strategies – from Pine Script to Python and beyond
In the intermediate phase of my trading journey, I found myself crafting Pine Script indicators and strategies for clients. Pine Script is the coding language used to create custom indicators on the TradingView platform. Initially, I began this journey by developing tools for my friends in our private trading circle. As my proficiency grew, my clientele expanded through their endorsements.
Interestingly, many of the strategies proposed by my clients were not profitable. While these strategies had shown promising results over one or two months during the manual development and backtesting stages, they often failed to generate profits when deployed live. At times, any profits realized were more attributable to Bitcoin’s general bullish trend rather than the efficacy of the strategy. However, amidst this sea of underperforming strategies, some stellar performers sustained profitability over the years. The majority of the strategies found their niche in specific market conditions, exhibiting profitability either during bull or bear markets, generating moderate returns monthly, or showing high profitability with an inherent risk of significant initial drawdown (a drawdown is a decrease in the capital, which, when it occurs right at the beginning of testing, reduces your starting balance, thus making recovery of losses more challenging.).
The game-changer in my journey was the transition from Pine Script to Python. Python unlocked a universe of advanced tools and techniques, including statistical analysis, correlation studies, and advanced mathematical models. This level of sophistication facilitated the creation of highly accurate strategies and allowed for precise replication of their results. However, Pine Script remains a highly accessible language for beginners and is widely adopted among traders. Moreover, it offers a treasure trove of pre-built strategies ripe for tweaking and customization, making it an excellent starting point for this journey.
We will commence with price-derived indicators and strategies, a common approach among trading coders. However, I would like to challenge you to venture beyond the conventional. Once you gain confidence with price-based indicators, consider exploring information not directly derived from price. We have an array of data streams at our disposal, such as news, market sentiment, social media influence, economic calendars, announcements from the Federal Reserve, and more. However, traders often limit themselves to Open, High, Low, Close (OHLC) data, neglecting valuable insights from these additional sources.
Unlocking these alternative perspectives is akin to reaching a level-3 quest in algorithmic trading. However, let me reassure you that this journey doesn’t demand deep coding expertise. Even creating a basic indicator that distinguishes bullish, bearish, or sideways trends could be invaluable for your strategy. The consistency of applying the same code across different strategies will lend a sense of stability in the unpredictable world of trading.
Many traders still follow traditional indicators, some dating back to the 1950s and even earlier. For instance, Ralph Elliot’s Elliot Waves theory is still prevalent, despite its creator passing away in 1948 and the method’s statistical shortcomings. Similarly, indicators such as the stochastic oscillator, the Relative Strength Index (RSI), the Moving Average Convergence Divergence (MACD), and the On-Balance Volume (OBV), all developed between the 1950s and 1970s, continue to be widely used.
In today’s world, the creation of new indicators is commonplace. However, like the underappreciation of contemporary art in favor of classical masterpieces, the vast array of modern indicators often remains unexplored. The challenge lies in sifting through the sea of indicators to find the one that truly adds value to your trading strategy.