AmiBroker ApplyStop Introduction

16
ApplyStop Intro 1/2 AMIBROKER QUANT COURSE 73

Transcript of AmiBroker ApplyStop Introduction

Page 1: AmiBroker ApplyStop Introduction

ApplyStop Intro 1/2

AMIBROKER QUANT COURSE

73

Page 2: AmiBroker ApplyStop Introduction

When to sell?

1. Sell Signals

• Sell = sellConMKC AND (sellCon1 AND sellCon2 …);

2. Stop Triggers

• ApplyStop( stopTypeLoss, stopModePercent, 15);

3. Better opportunities

• Calculate current positions

• Calculate opportunities, and then compare to current positions

• Force sell signals, and then enter a better opportunity

Note: use CBI to perform 3.74

Page 3: AmiBroker ApplyStop Introduction

Facts about Stop Triggers

•Stops can help or hurt your results

•Change of degree in stop could result favorably or unfavorably

•Limitation in AmiBroker

•Backtesting VS Execution

•Keep it manageable and executable; otherwise, don’t use it

75

Page 4: AmiBroker ApplyStop Introduction

Basic ApplyStop in AmiBroker

76

ApplyStop( Type, Mode, Amount);

• stopTypeLoss

• stopTypeProfit

• stopTypeNBar

• stopTypeTrailing

• stopModePoint

• stopModePercent

• stopModeBars

• stopModeRisk

• Number: 15

• Point

• Percent

• Bars

• Array: 3ATR(14)

Page 5: AmiBroker ApplyStop Introduction

77

40 days

100

100

120

Profit from High = 120 – 100 = 20, then 10% profit = 2

118

100

120

High at 120, 10% = 12

High at 110, 10% = 11

108

99

-10%

100

90

10%

100

110

ApplyStop(stopTypeLoss,

stopModePercent, 10);

ApplyStop(stopTypeProfit,

stopModePercent, 10);

ApplyStop(stopTypeNBar,

stopModeBars, 40);

ApplyStop(stopTypeTrailing,

stopModePercent, 10);

ApplyStop(stopTypeTrailing,

stopModeRisk, 10);

Page 6: AmiBroker ApplyStop Introduction

EASY ?

Not so fast !

78

Page 7: AmiBroker ApplyStop Introduction

More Details of ApplyStop in AmiBroker

79

• Trade Price: SellPrice = Open or Close

• ExitAtStop: 0, 1, or 2

• Volatility: True or False

• ReEntryDelay: especially in Sideways and many false signals

• ValidFrom & ValidTo: especially in stopModeRisk

• ActivateStopsImmediately: On or Off

Note: please study https://www.amibroker.com/guide/afl/applystop.html

ApplyStop(Type, Mode, Amount, ExitAtStop, Volatility, ReEntryDelay, ValidFrom, ValidTo);

Page 8: AmiBroker ApplyStop Introduction

WARNING

Can Code, but Not Execute = Useless

Can Execute, but Not Understand = Risky

80

Page 9: AmiBroker ApplyStop Introduction

ApplyStop Intro 2/2

AMIBROKER QUANT COURSE

81

Page 10: AmiBroker ApplyStop Introduction

Facts about ApplyStop in AmiBroker

•Compatibility between stopType and stopMode matters

• stopTypeNBar not compatible with stopModePercent

•Compatibility between stopMode and stopAmount matters

• stopModePercent not compatible with stopAmount 3ATR()

•Only one stopMode per one stopType is used

1. ApplyStop(stopTypeTrailing, stopModePercent, 15); //over ruled by next line

2. ApplyStop(stopTypeTrailing, stopModeRisk, 15);

•Keep it manageable and executable; otherwise, don’t use it

82

Page 11: AmiBroker ApplyStop Introduction

stopType… and stopMode… in AmiBroker

83

stopType…

stopMode…

Measured FromPoint Percent NBars Risk

Loss Entry price

Profit Entry price

NBar Entry bar

Trailing (1) (1) (2)(1) % from High

(2) % from High - Entry

ApplyStop( Type, Mode, Amount, ExitAtStop, Volatility, ReentryDelay, ValidFrom, ValidTo);

Page 12: AmiBroker ApplyStop Introduction

stopMode… and stopAmount given: ATR(14) = 5

•ApplyStop(stopTypeLoss, stopModePoint, 10); //Entry: 125 -> then: 115

•ApplyStop(stopTypeLoss, stopModePercent, 10); //125->112.5

•ApplyStop(stopTypeLoss, stopModePercent, 2*ATR(14)); //Run, but non-sense

•ApplyStop(stopTypeLoss, stopModePoint, 2*ATR(14)); //125->115

•ApplyStop(stopTypeProfit, stopModePoint, 10); //Entry: 125 -> then: 135

•ApplyStop(stopTypeProfit, stopModePercent, 10); //125->137.5

•ApplyStop(stopTypeProfit, stopModePercent, 2*ATR(14));

•ApplyStop(stopTypeProfit, stopModePoint, 2*ATR(14)); //125->13584

Page 13: AmiBroker ApplyStop Introduction

stopMode… and stopAmount given: ATR(14) = 5

•ApplyStop( stopTypeNBar, stopModeBars, 40); // Bar 0 until Bar 40

•ApplyStop( stopTypeNBar, stopModePercent, 40); //Run, but non-sense

•ApplyStop( stopTypeNBar, stopModePoint, 40); //Run, but non-sense

•ApplyStop( stopTypeTrailing, stopModePoint, 25); //100->125->100

•ApplyStop( stopTypeTrailing, stopModePoint, 5*ATR(14)); //100->125->100

•ApplyStop( stopTypeTrailing, stopModePercent, 25); //100->125->93.75

•ApplyStop( stopTypeTrailing, stopModeRisk, 25); //100->125->118.75

85

Page 14: AmiBroker ApplyStop Introduction

stopTypeTrailing with stopModeRisk

•ApplyStop( stopTypeTrailing, stopModeRisk, 25); //100->104->103 ???

•ApplyStop( stopTypeTrailing, stopModeRisk, 25, … , … , …, 20); // ValidFrom

86

ApplyStop( Type, Mode, Amount, ExitAtStop, Volatility, ReentryDelay, ValidFrom, ValidTo);

Page 15: AmiBroker ApplyStop Introduction

Conclusion for Basic ApplyStop in AmiBroker

•Not executable or not understand it, Don’t use it !

•Keep it simple and straightforward

•Prefer the followings:

• ApplyStop(stopTypeLoss, stopModePercent, 10); // 5 to 15%;

• ApplyStop(stopTypeProfit, stopModePercent, 20); // 15 to 35%;

• ApplyStop(stopTypeTrailing, stopModePercent, 25); // 20 to 30%;

• ApplyStop(stopTypeNBar, stopModeBars, 40); // Depends on strategy

•Keep stop co-ordinate and logical

•Read: https://www.amibroker.com/guide/afl/applystop.html87

Page 16: AmiBroker ApplyStop Introduction

WARNING (AGAIN)

Can Code, but Not Execute = Useless

Can Execute, but Not Understand = Risky

88

Note: please study https://www.amibroker.com/guide/afl/applystop.html