Configure and Execute your strategy
To effectively use pyalgotrading and make the most of your trading strategy, it's essential to be familiar with some frequently used stock market terminologies. Let's go over these terms before diving into configuring your strategy parameters.
- Exchange: An exchange is a marketplace where various financial instruments like securities, commodities, and derivatives are traded. Examples include NSE (National Stock Exchange), BSE (Bombay Stock Exchange), NYSE (New York Stock Exchange), and NASDAQ.
- Instruments: Instruments are the specific assets or securities traded on these exchanges. These include stocks like AAPL (Apple Inc.), TSLA (Tesla, Inc.), TATAMOTORS (Tata Motors Limited), and SBIN (State Bank of India).
- Candlestick Charts: Candlestick charts are commonly used in stock market analysis. They represent the opening and closing prices of a stock or asset over regular time intervals, which are often referred to as "candle size."
- Intraday Trading: Intraday trading, also known as day trading, involves buying and selling stocks within the same trading day.
- Delivery Trading: Delivery trading is a type of trading where traders buy shares and hold them for an extended period, which can range from a few days to several months or even years.
- Position: A position refers to the amount of a security or asset owned (or sold short) by an individual or entity. Traders take positions when they make buy or sell orders.
- Order: An order is an instruction to buy or sell a security or asset on a trading venue, such as a stock market or cryptocurrency exchange.
- Crossover: A crossover occurs when two signal lines intersect. Signal lines can be various indicators like moving averages, Relative Strength Index (RSI), Volume Weighted Averages, etc. Crossovers are often used to trigger and place orders. Now that we've covered these essential terms, let's move on to configuring your trading strategy parameters.
Configure Strategy Parameters
You can configure the strategy’s parameters by clicking on the settings symbol in the top right corner of the code editor. In this section, you can view a strategy’s parameters or edit these parameters too.
There 4 sections for configuring your parameters:
Instruments
- Here you can select the allowed exchanges from the drop box given on the left (eg: NASDAQ, NYSE, NSE etc.)
- Once you have selected the exchange you can search the instrument in the search-box right beside it
Strategy Settings
- Here you can select the candle size, it is the size of candle on which you will run your strategy.
- You can even select the mode i.e. INTRADAY or DELIVERY
Order Settings
- You can adjust your orders, on how they will act when the strategy is 'Resumed' or strategy is 'Exited'
- Resume Positions from Start: If you have previous trades in your strategy, you can resume your strategy without deleting or overwriting them. Only applicable for DELIVERY mode.
- Exit Intraday Orders on Stop: If checked, strategy will square-off positions automatically at the end of each trading day.
- Max Order Count: Maximum number of orders your strategy will execute per day. Once this limit is completed for the day, all BUY/SELL signals for new orders would be automatically ignored.
- Crossover Accuracy Decimal: When running a crossover strategy, the number of decimals of the underlying indicators to be taken do decide an upward cut, downward cut or no cut.
- Credit Exposure Factor: Applicable only for Live Trading. Use this to set the exposure limit given by your broker. System will take available funds as 'current fund balance X credit exposure factor' for executing the strategy
Strategy Parameters
- Use this option to pass various values of the strategy parameters from outside, without changing the code base for every execution. They are accessible as a dictionary called
strategy_parameters
inside your strategy class' constructor method. - You can customise/create your own parameters for the strategy. Click on +Add New Parameter to begin adding them. They should match with the parameters you have defined in your Python class.
Once Strategy and Strategy Parameters are configured, you can follow these steps to execute your strategy.
Execute your strategy
Follow these simple steps to test the strategy's performance
Step 1
After clicking Save & Start, a pop-up window will appear.
Step 2
i. In the Select Execution Mode section, choose Backtesting, Paper Trading or Live Trading according to your preference.
ii. Select "Broker" if you are "Live Trading" or "Broker" and "Data Source" if you are "Virtual Trading"
iii. Click on Open Parameter Configure Panel Button to tweak/view your parameters.
After you click it, a section for parameter configurations will open, where you can check the parameters and modify additional things accordingly.
iv. For Backtesting, you get to specify the dates.
v. For Paper Trading and Live Trading, you can specify the time.
vi. Use the toggle button to activate the P&L Tracker. Add the desired profit and risk appetite here.
Step 3
To begin testing the strategy, click on the bottom-most button, which includes the type of Trade you want to perform.
Step 4
Go to the Analytics section to see the returns and performance of the strategy visualised.
Note
The use of Paper Trading would be available from Monday - Friday (excluding exchange's holidays) from 9 AM to 16:00 PM. You can code your strategy & analyse the strategy results 24x7.
Go to the Logs section to see the step-by-step execution of the strategy in logs.
You can rename a strategy by clicking the edit symbol beside the strategy name.