Should I be intraday trading BSE

Introduction Trading Systems Seminar 2. Philipp Kahler. Acting with a system. Introduction to the development of trading systems.

Transcript

1 Philipp Kahler Systematic Action Introduction to the Development of Trading Systems Philipp Kahler 1

2 So all you rovin 'gamblers, wherever you might be, The moral of this story is very plain to see. Make your money while you can, before you have to stop, For when you pull that dead man's hand, your gamblin 'days are up. (Bob Dylan) Philipp Kahler 2

3 Trading system development: Road map ... 4 Before every system development there is a trading plan ... 4 Equilla - Introduction to the most important commands ... 5 Equilla - Graphical representation: ... 5 Equilla decisions ... 6 Equilla - yesterday, today , tomorrow ... 7 Caution with functions: ... 7 Example pivot point: ... 8 Trend detection and display ... 9 Standard trend indicators: ... 9 Trend Paint indicator ... 10 Further examples of trend indicators: .. .10 Indicator rises? ... 11 Equilla - Trading Verbs ... 12 Equilla System Information ... 13 Trading System Trading System Optimization of Parameters ... 17 System Basket ... 18 Trading System Definition Trend ... 21 System Module 1: Trend Detection .. .23 Entry and Exit ... 24 Philipp Kahler Trading System 3

4 Trading System Development: Road Map A trading system is nothing more than the experience of a trader cast in computer code. Before developing any system there is a trading plan. When do I want to trade the market? How big should the risk per trade be? How do I want to get into position? When will the position be closed? An example of such a trading plan: Only in the entry trend direction with a new high after a break Risk per trade = 2% of the deposit Exit with a fixed stop and target Philipp Kahler 4

5 Equilla - Introduction to the most important commands Equilla - Graphical representation: The TradeSignal programming language contains several possibilities to represent something on the chart. 1. DrawLine (x) draws a line 2. DrawSymbol (x) draws a symbol 3. DrawBar (open, high, low, close) draws a bar 4. DrawCandlestick (open, high, low, close) draws a candlestick 5. DrawForest (0, x) draws a histogram 6. DrawArea (x, y) draws a volume Philipp Kahler 5

6 Equilla decisions 1. With the if-then function, decisions can be made in Equilla. if open 70 then begin short next bar at low stop; cover next bar at highest (high, 3) stop; end; When the RSI is above 70 we will shorten the closest bar below the current low. The position will be closed at the highest high of the last 3 bars. if dayofweek = 1 then begin monday high = high; Monday low = low; end; The code remembers (on the daily chart) the high / low values ​​from Monday. With the and function links can be constructed. if close> average (close, 200) and close> average (close, 21) then ... If the close is above the 200-day average and above the 21-day average, then something is done. With the or function, queries can optionally be carried out. if close> average (close, 200) or close> average (close, 21) then ... If the close is above the 200-day average, or the close is above the 21-day average, then something is done. The query is also run through if the close is above the 200-day and 21-day average. Philipp Kahler 6

7 Equilla - yesterday, today, tomorrow In Equilla, past values ​​of variables can easily be queried: close [1] [1] means that the value of the bar in front of it is returned. This is how simple pattern recognition can be constructed: insidebar = false; if h l [1] then insidebar = true; Drawing functions can also work in the past: if insidebar = true then begin drawcandlestick (o, h, l, c); // candle today drawcandlestick [1] (o [1], h [1], l [1], c [1]); // candle end yesterday; A trick to save the start of the day in the intraday chart: if date <> date [1] then dayopen = open; Be careful with functions: yesterday's value is not always available or correct. If you write the value of the function in a variable, you can work around the problem. Example: marketposition Marketposition returns the current positioning: 1: Long 2: Short 0: Flat Yesterday's value is not available via marketposition [1]. Remedy: Variables: mp; mp = market position; if mp = 0 and mp [1] = 0 then begin ... The market position is written to the variable mp. Mp [1] gives yesterday's market position. The code does something if there was no close position either today or yesterday. Philipp Kahler 7

8 Example pivot point: The pivot point should be displayed on the chart: several options: 2. Not very suitable for trading the pivot is only valid for close, but is displayed on the current bar: piv = (high + low + close) / 3 ; drawsymbol (piv, "pivot"); 2. for traders The pivot calculated yesterday is displayed today piv = (high + low + close) / 3; drawsymbol (piv [1], "pivot"); 3. the same as 2. piv = (high + low + close) / 3; drawsymbol [1] (piv, "pivot"); Philipp Kahler 8

9 Trend recognition and presentation of standard trend indicators: Moving averages and indicators based on them average (close, period) Directional Movement Index (DMI) dmiplus (period), dmiminus (period) Parabolic SAR parabolic (0.01) Philipp Kahler 9

10 Trend Paint indicator All those days should be shown in green on which the market is trading above the 20 day and 200 day GD, the 20 day GD is above the 200 day GD, and the 20 day and 200 day GD rises. Inputs: short (20), long (200); Variables: GD20, GD200; GD20 = average (open, short); GD200 = average (open, lang); drawline (gd20, "GD short"); drawline (gd200, "GD long"); // Representation of the GDs if open> gd20 and open> gd200 and // Market via the GDs GD20> GD200 and // 20 days GD over 200 days GD GD20> GD20 [3] and // 20 days GD increases GD200> GD200 [ 3] Then // 200 days GD increases drawbar (o, h, l, c); Further examples of trend indicators: sma = average (close, 21); // Simple moving average xma = xaverage (close, 21); // Exponential moving average para = parabolic (0.01); // Parabolic SAR pdm = dmiplus (14); // DMI Plus mdm = dmiminus (14) // DMI Minus Philipp Kahler 10

11 is the indicator rising? There are several ways to test whether an indicator is rising. Indicator greater than x days ago av = average (close, 20); if av> av [3] then bulltrend = true; Indicator greater than its average av = average (close, 20); av2 = average (av, 5); if av> av2 then bulltrend = true; Indicator greater than its highest level within the last x days av = average (close, 20); if av> = highest (av, 30) then bulltrend = true; The strength of the increase can also be determined av = average (close, 20); av2 = average (close, 100); trend = abs (100 * (av-av2) / av2); drawforest (0, trend); Philipp Kahler 11

12 Equilla - Trading Verbs The following options are available to open a long position // 1. Trade on the Close if Bulltrend = true then buy x contracts this bar on close; // 2. Trade at the next opening if Bulltrend = true then buy x contracts next bar at market; // 3. Stop order for tomorrow if Bulltrend = true then buy x contracts next bar at xy stop; // 4. Limit order for tomorrow if Bulltrend = true then buy x contracts next bar at xy limit; If one does not want to buy at the opening in case 3 if the opening jumped with a gap above the price xy, then it must first be checked whether there was an opening gap // 3a. Stop order for tomorrow - protection against gaps if Bulltrend = true then begin if open of tomorrow = xy then buy x contracts next bar at xy limit; end; To open a short position, buy is replaced by short. Buy or short close any existing position in the opposite direction. To close the long position, the buy command is replaced by the sell command. sell next bar at market sell next bar at xy limit; sell next bar at xy stop; The entire position is closed. To close only part of the position, the following systax must be used: sell x contracts total next bar at xy market; sell x contracts total next bar at xy limit; sell x contracts total next bar at xy stop; To close a short position buy is replaced by cover. Philipp Kahler 12

13 Equilla System Information The number of shares currently held. Positive for long positions, negative for short positions Current contracts The current positioning of the system. 0 for flat, 1 for long, -1 for short market position The serial number of the current position TotalPositions The open and closed portfolio status OpenEquity ClosedEquity The entry price to the current position Entry price The number of bars since the position was opened Barssinceentry Philipp Kahler 13

14 Trading system 1 idea: with a rising moving average, trading is long, with a falling average short. First, the length of the GD and the number of pieces to be purchased are defined as inputs. Inputs: period (21), con (50); Variables: sma; Each variable used must be defined once. The next line calculates the moving average and writes the value to the variable sma sma = average (close, period); When the close is above the SMA and the SMA is greater than before 3 bars (= rises), then the graphic display and the construction of the position begin. The position is immediately hedged via a stop loss, so it should not lose more than its average true range. if close> sma and sma> sma [3] then begin drawforest (h, l, "up", "up.", thick, green); if marketposition = 0 then buy con contracts next bar at close limit; setstoploss (avgtruerange (period) * lotsize * con); end Now the commands for the short entry come: else if close 0 then setstoploss (0); if barssinceentry> 5 then setprofittarget (avgtruerange (period) * lotsize * currentcontracts); Philipp Kahler 14

15 Trading system 2 Idea: The upward trend is found with the help of 2 moving averages. If there is not yet a long position, one will be entered the next day. The position is initially hedged with a stop loss. After a few days, the stop is raised to the entry price. If this does not close the position, the stop will later be raised to profitability. When the trend ends, the position is also closed. The active exit levels should be displayed graphically. Philipp Kahler 15

16 inputs: len1 (50), len2 (200), con (1); Inputs: entrymod (closeentry, pivotentry, highstopentry) = pivotentry; Variables: sma1, sma2, stopvalue, trend, mp, avtr, bse, raise; trend = 0; mp = market position; avtr = avgtruerange (14); bse = barssinceentry; // Calculation of moving averages sma1 = average (close, len1); sma2 = average (close, len2); // Trend detection and visualization if sma1> = sma2 and sma1> sma1 [3] and sma2> sma2 [3] and close> sma1 then begin trend = 1; if mp = 0 and mp [1] = 0 and mp [2] = 0 then begin // Entry if entrymod = closeentry then buy ("Entry") con contracts this bar on close; if entrymod = high stop entry then buy ("Entry") con contracts next bar at high stop; if entrymod = pivotentry then buy ("Entry") con contracts next bar at (h + l + c) / 3 limit; end; end; // Initial Stop setstoploss (con * lotsize * 1.5 * avtr [bse]); sell ("stop 1") next bar at low [bse] -avtr [bse] stop; // Entry price stop If mp = 1 and mp [1] = 1 and low crosses above (entry price + 2 * avtr [bse]) Then raise = 1; if mp = 0 and mp [1] = 1 then raise = 0; if raise = 1 then sell ("ep-r1") next bar at entry price + avtr [bse] stop; if raise = 0 and bse> 5 then sell ("ep") next bar at entry price stop; // Profit trailing if no trend detected if trend = 0 then sell ("no trend Exit") next bar at maxlist (highest (high, bse) -avtr [bse], entryprice) stop; // Visualization of active orders, trend and moving averages drawsymbol (getactiveorderprice (1)); if trend = 1 then drawbar (open, high, low, close); drawline (sma1, "sma1"); drawline (sma2, "sma2"); mp = market position; Philipp Kahler 16

17 Optimizing the parameters In search of stability ... A moderate change in the parameters should only lead to a small change in the results. Philipp Kahler 17

18 System basket If the system works with several instruments, a system basket can be set up. A higher diversification according to markets and investment vehicles automatically brings a higher stability of the results. Bund: Dax: Philipp Kahler 18

19 Bund and Dax combined Philipp Kahler 19

20 Trading System 3 Buy the High - Short the Low Idea: If the market is trending then buy new highs and sell new lows. Implementation: Definition of trend? Definition high? Exit if it doesn't increase any further Always the same risk per trade test: Stability of the parameters Multi-market capable Multi-timeframe capable Philipp Kahler 20

21 Trend definition Experiment 1: Close over 200 days Philipp Kahler line 21

22 Experiment 3: Close over a rising 200-day line and over a 25-day line Philipp Kahler 22

23 System module 1: Trend detection Inputs: long (200), short (25); Variables: ma200, ma25, bulltrend; ma200 = average (o, long); ma25 = average (o, short); drawline (ma200, "200 day line"); drawline (ma25, "25 day line"); Bull trend = 0; if o> ma25 and ma200> ma200 [5] and ma25> ma200 then Bulltrend = 1; Philipp Kahler 23

24 Entry and exit idea: In an upward trend, after a recovery (= day without a new high), buying is made when a new high is reached. If the market falls below the low of the correction day, the position is closed. if h h [2] then begin drawcandlestick [1] (o [1], h [1], l [1], c [1]); longentry = high [1]; longexit = low [1]; end; Philipp Kahler 24

25 System code Long: Inputs: long (200), short (25), risk (150), goal (2.0); Variables: ma200, ma25, bulltrend; variables: longentry, longexit, con; ma200 = average (o, long); ma25 = average (o, short); drawline (ma200, "200 day line"); drawline (ma25, "25 day line"); Bull trend = 0; if o> ma25 and ma200> ma200 [5] and ma25> ma200 then Bulltrend = 1; if h h [2] then begin drawcandlestick [1] (o [1], h [1], l [1], c [1]); longentry = high [1]; longexit = low [1]; end; if longentry> longexit then begin con = maxlist (1, risk / (longentry-longexit)); end; if marketposition = 0 then begin if open of tomorrow 0 then setprofittarget (target * risk * lotsize); drawsymbol (longentry); drawsymbol (longexit); Philipp Kahler 25

26 Trading system 4 Red Candle Reversal System idea and system description The system is based on weekly data and risks 150 per trade. Trend direction: Index rises above its 54 week average and 54 week average of the share Entry threshold: Falling week in the share, entry in the following week at Reaching the high of the falling week Exit threshold: at the low of the trigger week or when the target number of shares is reached: 150 / (high-low) {of the trigger week}, max capital investment per position Target threshold: High + 1.5 * (high-low) {der red trigger week} Philipp Kahler 26

27 System code inputs: debug (on, off) = off; inputs: debugdate (); Inputs: printinfo (yes, no) = no; inputs: targ (1.5), risk (150), maxkap (3000); variables: avg, numstocks, index, period (54), mp, avgindex, rcl, rch; index = close of '.