Skip to content

Creating Conditions

Creating a strategy

Streak has a simple intuitive interface that lets you create your own customised strategies. Strategies are made by keying in Entry conditions (made up of technical indicators), Exit conditions (made up of stop loss, target profit percentage, and an optional exit condition based on technical indicators), and additional parameters such as chart type, holding type etc.

The Streak platform supports over 80+ technical indicators including Supertrend, MACD, RSI, Momentum indicator, Moving Average.

Below is a step by step breakdown of the "Creating a Strategy":

Step 1: Positions

In this section, you can choose your Entry type (either Buy or Sell), instruments you want to trade with and charting parameters.

Position

  • Scrip/Instrument You can select the stock, commodity, or currency futures from NSE. You can add upto a maximum of 50 instruments in a single strategy.

  • Chart You can select the chart type as Candlestick, Heikin-Ashi or Renko charting.

    You can also choose the candle interval
    - 1 minute checks for signals on minute candles with a maximum allowed window of 30 days
    - 3 minute to 30 minutes checks for signals on the respective candles based on data availability with a maximum allowed window of 90 days.
    - 1 hour candle checks for signals on an hourly candle with a maximum allowed window of 1 year based on data availability.
    - 1 day candle checks for signals on a day candle with a maximum allowed window of 5 years based on data availability.

    You can change order type from MIS(Intraday) to CNC/NRML(Delivery).

  • Quantity is the number of equity share or future lots to be used by the strategy.

Example

Scrip: SBIN, SBIN22MAYFUT Timeframe: 15 min
Position: Buy Quantity: 1

In the above example, the platform will consider the quantity for SBIN as 1 and quantity for SBIN22MAYFUT as 1 lot, i.e. 1500 stocks.

  • Advance Options Click here to read more about Quantity types and PositionSizing


Step 2: Entry


You can build your entry condition using over 80+ technical indicators such as RSI, MACD, Supertrend and more.

Entry

Step 3: Exit


The exit condition includes mandatory Stop loss and Target Profit percentage and an optional exit condition based on technical indicators.

Exit

Step 4: Backtest Parameters


BacktestParameters


You can also change the backtesting parameters before running the backtest. These parameters are:

  1. Initial captial: This is the hypothetical captial required to enter a trade in the backtest period. By default the value is set to 1 crore (10000000) and it does not represent any capital held by the user and is for backtest purposes only. While backtesting an entry will only be triggered when the notional value of the trade is less than the Initial capital + Cumulative Profit or Loss uptill previous trade.
  2. Strategy Cycle defines the loop of the strategy i.e entry followed by respective exit.
  3. Entry start and stop time: This can be customized as per requirements and by default it is set as 9:00 AM to 11:59 PM
  4. Backtest start and stop dates: This is the duration for which the backtest runs.

Points to remember when using Entry Start and Entry Stop time

  1. Given trade time is only inclusive of candle close time.

    Example:

    If trade entry time is given between 11:10 AM to 03:00 PM and for a 15 minute candle interval. Then for 11:00 AM candle since it closes at 11:15 AM and meets the entry condition, the trade will be executed. Similarly, for 03:00 PM candle, the close time is 03:15 PM, even if it meets the entry condition but since the trade time given was only till 03:00 PM trading signal will not be generated.

  2. While backtesting the close time for a candle is consisdered as 'Close time - 1 milisecond'

    Example:

    Candle Interval: 5 mins
    Entry start time: 9:20
    Entry stop time: 2:15

    Now if the entry condition is true on the first candle close (a 5min candle of 9:15, will close at 9:20), the entry will not be captured in the backtest as candle close time in backtest is assumed as "9:19:59:999".

    However, for the same parameters a deployed strategy will receive the alert because the trigger will be generated at 9:20:xy seconds. Since the alert time is higher than entry start time, a triggered is generated.

    By keeping the entry start time as 9:19 one shall receive alert in both, backtest and in deployment.

  3. As a thumb rule, to get same results for backtest and deployments you can keep the start/stop time as below

    Entry Start time: earliest signal time you want to receive the alert (minus) - 1 minute
    Entry Stop time: last signal time you want to receive the alert (plus) + candle interval (plus) + 1 minute

Note

  1. During a backtest, if the close price crosses either of the exit price points (SL,TP) in the current candle, an exit is triggered. However, if the exit signal is met, the hypothetical exit order is placed on the open price of the next candle.

    2. After deployment, for virtually deployed strategies, if the strategy has entered a position in the market and the LTP (last traded price) crosses either of the exit prices point(TP SL) or the exit signal is met, the hypothetical order is immediately placed.

---------------------------------------------------------------------------------

More on Create

Comparators

  1. up by/down by
  2. crosses above/crosses below
  3. lower than equal to/higher than equal to
  4. lower than/higher than/equal to

Detailed explanation for each of the comparators is explained here

Math operators

You can also use math operators to add, subtract divide and multiply values. Math operators are usefull for creating complex conditions. How is it helpfull?

Let's understand this with an example

Example

Suppose you want to trigger an entry when there is a rising RSI. But you don't know by what percentage the RSI should rise. Now, how do we create this condition?

Ok, first lets consider a stock moving in a straight line. Straight price line For the above stock, what is the difference between the price on September 3rd and September 2nd? The answer is 0. So, if I were to create a condition to look for the movement like in the above chart, I would put in the below mentioned condition: Close(0) - Close(-1) equal to 0

Again, lets consider a stock, whose price is rising gradually. Slope price line For the above stock, there is a price difference between the candles. The difference between the price on September 3rd and September 2nd = INR 10 and the difference between the price on September 4th and September 3rd = INR 10. So, if we calculate the difference between all the candle it is going to give a positive number( i.e. higher than 0). So, if I were to create a condition to look for the movement like in the above chart, I would put in the following mentioned condition: Close(0) - Close(-1) higher than 0

Now, we are going to use the same logic for rising RSI, we are going to take the help of indicator offset and math operator to do this. An uptrending RSI can denoted by positive difference.

Condition:
RSI(14,0) - RSI(14,-1) higher than 0 and
RSI (14,-1) - RSI (14,-2) higher than 0 and
RSI(14,-2) - RSI(14,-3) higher than 0

The above expression calculating the difference between current candle RSI and previous candle RSI and checking whether this is higher than 0.

Math Functions

Period Min and Period Max

Period Min: The period min function returns the item with the lowest value within stated period. This function takes in two arguments, one is the period and the other is a variable that users want to compare Period min(Period, Variable). It will process all the values mentioned for the period number specified and return the minimum value.

Example

Entry on:SBIN Time frame:1 day

Conditions: Close(0) lower than Period Min(5, Low(-1))

The above query would generate a entry trigger on SBIN, whose current candle close price is lower than lowest low price of the past five days.

Period Max: The period max function returns the item with the highest value within stated period. This function takes in two arguments, one is the period and the other is a variable that users want to compare Period max(Period, Variable). It will check through all the values mentioned for the period specified and returns the maximum value.

Example

Entry on:SBIN Time frame:1 day

Conditions: Close(0) higher than Period Max(5, high(-1))

The above query would generate a entry trigger on SBIN, whose current candle close price is higher than highesh high price of the past five days.

Min and Max

Min: The min() function compares two variables and returns the item with the lowest value. This function takes in two variable arguments, that users want to compare Min(Variable, Variable). This is different from Period min as this consider two variables instead of one. The min function is especially helpfull when you want to compare two independent conditions.

Max: The max() function compares two variables and returns the item with the highest value. This function takes in two variable arguments, that users want to compare Max(Variable, Variable). This is different from Period max as this consider two variables instead of one. The max function is especially helpfull when you want to compare two independent conditions.

Ceil and Floor

Ceil: The ceil() function approximates the given number to the smallest integer, greater than or equal to the given float value. This function is helpful when creating conditions that involve calculation of value and you are unsure about the result. This function rounds up the value to the nearest largest integer. Ceil(5.678) would be rounded up to 6.

Floor: The floor () function returns the largest integer less than or equal to the given number. Similar to Ceil function, this function lets you round off the value to the nearest largest integer. Floor(5.678) would be rounded off to 5.

Abs

The abs() function is similar to mod function and is used to return the absolute value of a number. abs(-6) and abs(6), both would return the absolute value of 6.

Multi-Timeframe Functions

Multi-Timeframe (MTF): The multi timeframe() function allows users to perform multi timeframe analysis i.e check conditions for two different timeframes in a single query.

Note

MTF calculates value of larger timeframe indicator values on partial candles (since the larger timeframe candle takes more time to form). When MTF is used for backtesting, it can have look-ahead bias and live alerts may not always be verifiable with charts or match when backtested. This is because it is not possible to predict future OHLC values and indicator. You should test your strategy and understand the backtest result charts and not just deploy it on the basis of Profit/Loss.

Multi-Timeframe Completed (MTF-Completed): The multi timeframe Completed() function checks for completely formed candle(of same or larger timeframe). Unlike the MTF, MTF-Completed does not consider Partial candle information and does not have a look ahead bias.

If you create a condition as Close(0) crosses above Multi-timeframe completed(day, Supertrend(7,3,0)), then it will compare current candle’s close with the Supertrend on a completely formed day candle i.e yesterday’s Supertrend value. So Multitime-frame with offset of -1 = Multitime-frame completed

Example

Suppose, you want to create a query where you want to create a strategy and take an entry when the stock is
a. trading above 10 EMA on a daily timeframe, and
b. hourly RSI is above 50, and
c. MACD is giving a buy signal in 5 min timeframe

Candle Interval:5 min
Conditions:Close (0) higher thanMulti-timeframe Completed(day, EMA(Close,10,0)) and
Multi-timeframe Completed(hour, RSI(14,0) higher than 50) and
MACD (12,26,9,macd,0)higher than MACD (12,26,9,signal,0)

Symbol

The Symbol function allows users to check their conditions on another scrip/symbol than the one selected under the instrument section in the create strategy page. This function takes in two arguments, one is the scrip and the other is a variable that users want to compare Symbol(scrip, variable). Inside the variable one can add the required conditions and whatever is added within the symbol bracket, all those conditions will be checked on the selected scrip itself and trade will be triggered for the stocks, options or future contract added in the instruments section.

Brackets

Brackets are used to denote and group sub-expression. Bracket follow BODMAS rules. It allows you to exactly create your ideas the way you want. Let's say you have five logics based on which you want to create a strategy condition.

Example: Logic A and Logic B or Logic C or Logic D and Logic E
Conditions with Bracket: (Logic A and Logic B)OR Logic C OR (Logic D and Logic E)

The above condition will trigger an alert when either Logic A and B are true OR when Logic C is true OR when Logic D and E are true.

Risk Management and Position Sizing

Risk management is one of the most important factors when it comes to creating a strategy. You can further fine tune your exit parameters using various types of target profit and stoploss, additionally you can choose to size your positions using two different methods. These parameters will allow you to mangage your risk better and further optimise your strategy. ### Types Of Target profit (TP) and Stoploss (SL) You can choose to set your Target Profit (TP) and Stoploss (SL) in three different types as mentioned below - Percentage (Pct) - Absolute (Abs) - Points (Pts) ![TPSL](img/TPSL_Types.png "TPSL types") 1. Percentage (Pct) Type TPSL
The values entered here will be calculated on the basis of percentage from the entry price. When backtesting with multiple scrips with different values, Pct (%) type of TP/SL can be useful as the levels will be calculated with respect its value no matter if the scrip is worth 100 or 5000. Example: `Position: Long`
`Entry price: 500`
`Stoploss % = 2` the SL level will be (500 - 2%) = 490
`Target Profit % = 4` the TP level will be (500 + 4%) = 520
2. Absolute (Abs) Type TPSL
As the name suggest this will consider the absolute amount of the trade while calculating the levels. In simple terms, you can input the total profit/loss amount where you'd like to exit your trade. Here the quantity has a significant impact on the TP/SL calculation. To determine the TP/SL level for Abs type, you have to take Total TP/SL value and divide it with the quantity. This result will then be added/subtracted from the entry price to get the respective TP/SL level. Example: | Particulars | Input | TP SL levels | | Particulars | Input | TP SL levels | |:------------:|:------:|:------------:|:-:|:------------:|:------:|:------------:| | Entry | 500 | | | Entry | 500 | | | **Quantity** | **40** | | | **Quantity** | **25** | | | Total SL | 1000 | **475** | | Total SL | 1000 | **460** | | Total TP | 2000 | **550** | | Total TP | 2000 | **580** |
From the above table we can see that the quantity indeed has a big impact on the TP/SL level. With the same Absolute TP and SL input, the levels differ when the quantity is changed. Let's further breakdown the numbers to understand how the TP/SL levels were generated. `Position: Long`
`Entry price: 500`
`Quantity: 40`
`Total Stoploss = 1000` the SL level will be (500 - [1000/40]) = 475
`Total Target Profit = 2000` the TP level will be (500 + [2000/40]) = 550
3. Points (Pts) Type TPSL
This is quite straight forward and similar to Pct type TPSL. The values entered here will be calculated on the basis of points (irrespective of the quantity and value of scrip) from the entry price. Let's say you want to exit when the scrip moves up by 10 points, now this movement can be big move for a scrip whose value is say 100, however the same movement can be quite a small move for a scrip whose value is 5000. This is something to keep in mind while using Points based TPSL type. Example: `Position: Long`
`Entry price: 500`
`Stoploss = 12` the SL level will be (500 - 12) = 488
`Target Profit = 25` the TP level will be (500 + 25) = 525
#### **Position Sizing** To manage and optimize risk, traders use different ways to size their positions. With Streak you can decide your position size using two methods 1. Capital Based 2. Risk Based Capital Based This parameter allows you to size your position based on the capital you assign. Once you assign the capital, the system will automatically calculate the maximum quantity that it can enter with the specified amount. Let’s understand this with an example. !!!info "Example" I want to allocate INR 25000 for each instrument. So you just have to enter “25000” under the Max allocation field and select the Position Sizing Type as “Capital Based”. Now let's assume the stock TCS is priced at 3294, the position size that can be bought at this price level with INR 25000 will be equal to 7.58 ~ 7 quantity. This is calculated as `[ Max allocation / instrument price ]` If the same allocation is used for the stock SBIN which is priced at, let’s assume, 486.9 then the position size will be 25000/486.9 = 51.34 ~ 51 quantity. Risk Based As the name suggests, this method gives more importance to the risk aspect of the trade and helps you size the position accordingly. To size your position in this method, you have to input two values A. Max SL per trade B. Max SL per quantity Value B is dependent on the type of TPSL selected by you. It is also important to note that with Risk-based position sizing, you can only select Percentage % (pct) and Points (Pts) based TPSL. Let us now understand more about this with examples !!!info "Example" 1. Risk-based position sizing with Percentage type TPSL Let’s assume, if in a single trade you don't want to risk more than 2% and the maximum that you want to risk is INR 3500 then the 2% becomes the Max SL per quantity and INR 3500 becomes the Max SL per trade. In such a scenario, your position size will be calculated as `[ Max SL per trade / Max SL per quantity ]`. So if you want to go long in SBIN, which as per our example is priced at 486.9, the position size will be 359.416 ~ 359 quantity `[ 3500 / (486.9 *2%) ]` After buying if SBIN falls by 2%, i.e breaches the SL of 477.16, the loss will be [486.9 - 477.16] * 359 = 3496.66. Which is within the Max SL limit that was mentioned in the strategy. With the same example if we change the SL to 4% (i.e increase the risk), the position size will be 179.7 ~ 179 quantity `[ 3500 / (486.9 *4%) ]`. As you can notice, with more risk (4% from 2%) the position size is reduced. Ergo, allowing you to control the risk better.
2. Risk-based position sizing with Points type TPSL This is similar to the method for Pct type TPSL. Just that here the Max SL per quantity remains the same for every scrip. Hence the position size will also remain same for all scrips. Continuing with the same example of SBIN, priced at 486.9, with Max SL per quantity as 12 Points (Pts) and Max SL per trade as INR 3500. The position size will be 291.66 ~ 291 quantity [ 3500 / 12 ]. If after buying, SBIN falls by 12 points, i.e breaches the SL of 474.9, your loss will be [486.9 - 474.9] * 291 = 3492. Which is within the Max SL limit that was mentioned in the strategy. !!! important "Note" Position sizing doesn't assume any margin requirements or leverage. It uses allocation and instrument price directly to calculate the order quantity. You should enter the allocation value such that margin requirements are being satisfied in your trading account for live trades. To check the margin requirements, visit your brokers' website.