Trading Automation with DecisionRules Workflows
Author: Michal Roman
Develop a 200-Day SMA Trading Strategy Using DecisionRules and Polygon—No Coding Required
For those interested in automated trading strategies, building a 200-day Simple Moving Average (SMA) system can now be done without any programming expertise. Leveraging the new Workflow engine from DecisionRules alongside real-time financial data from Polygon, you can seamlessly create, automate, and optimize your trading strategy. This approach empowers users to track market trends and implement responsive strategies through an intuitive, no-code interface, enhancing both efficiency and accessibility. Discover how to simplify complex trading strategies and elevate your investment approach with cutting-edge, code-free solutions.
This is where DecisionRules.io comes in as a no-code platform that allows you to visually design, test, and implement trading strategies using real-time market data. By integrating with APIs like Polygon.io, DecisionRules.io enables you to automate stock analysis and decision-making based on simple financial logic, without needing to know how to code.
In this post, we'll walk through how you can leverage DecisionRules.io to build a trading strategy that uses the 200-day moving average to determine when to buy or sell stocks - all without the need for coding.
About Polygon
Polygon.io is a powerful data platform that provides real-time and historical market data, enabling developers and businesses to access comprehensive stock, forex, and cryptocurrency information. Known for its speed, reliability, and extensive data coverage, Polygon.io is an essential tool for building and automating financial applications. Its robust API allows users to fetch detailed market data, analyze trends, and make informed decisions—making it an ideal choice for integrating with DecisionRules.io to enhance automated trading strategies.
Overview of the Tutorial
In this guide, we will walk you through the steps required to build a trading strategy that uses the 200-day moving average to determine when to buy or sell stocks - all without the need for coding.
Step 1: Set Up Accounts
1.1 Sign up for DecisionRules
DecisionRules allows you to create workflows and decision tables that can be used to automate various business logic, including trading strategies.
1.2 Sign up for Polygon.io
Polygon.io provides real-time and historical market data, which we’ll use to fetch stock prices for our strategy.
Step 2: Create a Blank Workflow in DecisionRules
2.1 Create a New Workflow
Step 3. Set up input and output model
Before building the workflow, you'll need to define the input and output models. These models will structure the data you feed into and get from your trading strategy.
3.1 Input Model
The input model defines the data you’ll provide for the workflow. In this case, you need to specify the following values:
3.2 Output Model
The output model will structure the decision made by your trading strategy:
Step 4. Workflow design
To implement the strategy in DecisionRules.io using Polygon.io, you will need a few specific nodes to structure the logic and API interactions. Here's a breakdown of the necessary nodes:
4.1. Global Variable Node (globalVariable)
This node will store your API key and any additional variables (like ticker symbol, etc.) needed throughout the workflow.
This allows you to manage these values centrally without hard-coding them in multiple places.
4.2. REST API Node 1: Get Actual Price (get_last_price)
This REST API node will call the Polygon API to fetch the current or previous day’s price of the stock.
Expected Response: The API will return a JSON object with the stock’s closing price.
More info in Polygon documentation HERE
4.3. REST API Node 2: Get 200-Day Moving Average (get_moving_averages)
This node will fetch the 200-day historical price data to calculate the 200-day simple moving average.
Expected Response: A JSON object with the historical closing prices for the last 200 days.
More info in Polygon documentation HERE
4.4. Assign Node: Extract Required Data
This node is responsible for parsing and extracting the needed values from the responses of both REST API nodes.
In the Assign Node, you can directly use DecisionRules functions to extract and manipulate the API response data efficiently. Here’s how to implement the extraction and calculation:
4.5. Switch Node: Price Comparison (Decision Node)
This node will decide whether the current price is above or below the 200-day moving average.
4.6. Connect Assign Nodes for Each Outcome of the Switch Node
After the Switch node decides whether the stock’s price is above or below the 200-day moving average, you’ll need to assign specific outcomes for each decision. This is where the Assign nodes come in, which will map the trading position (Buy/Sell) to the output model.
Final Output
Let’s review the final output of the workflow. Using the 200-day moving average, the system evaluates the stock’s current price and has determined that a bull order is the best course of action, with the last closed price 16% above the moving average value. This output reflects the automated decision-making that can be achieved through the no-code workflow. You can download the full rule here.
Conclusion
This tutorial shows you how to create a fully functional trading strategy without writing a single line of code. DecisionRules.io provides a user-friendly, visual interface where the logic is handled through nodes, and integration with external APIs (like Polygon.io) enables you to automate stock trading decisions based on real-time and historical data. This workflow design helps you build, test, and adjust trading strategies quickly and efficiently, even if you're unfamiliar with programming. This example demonstrates a simple use of the workflow, but you can extend it to create much more complex strategies as needed.
Lifelong Gamer
1 周How are you doing? I came across your input on my survey regarding your upcoming journey and was struck by your qualifications. Which position are you interested in pursuing next? Send me a connection request and a message so we can discuss further. I'm looking forward to hearing from you!