Stock Portfolio Organizer

The ultimate porfolio management solution.

Shares, Margin, CFD's, Futures and Forex
EOD and Realtime
Dividends and Trust Distributions
And Much More ....
For Portfolio Manager Click Here

WiseTrader Toolbox

#1 Selling Amibroker Plugin featuring:

Advanced Adaptive Indicators
Advanced Pattern Exploration
Neural Networks
And Much More ....
Find Out More Here

Stops on Percentages for Amibroker (AFL)
kaiji
about 15 years ago
Amibroker (AFL)

Rating:
5 / 5 (Votes 1)
Tags:

Stops on percentages can be set to low,high,close and open on the bars for long and short stops.

By Chris

Indicator / Formula

Copy & Paste Friendly
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// code from http://www.amibroker.com/kb/2007/03/24/how-to-plot-a-trailing-stop-in-the-price-chart/
// I added the short side and some options. Just drag and drop onto a price chart
 
_SECTION_BEGIN("Long Short % Stop");
//---long var
Stoplong = 1-Param("stop % Long", 7, 0.1, 20, 0.1) / 100;
Plong = ParamField("Price Field Long");
Longcol = ParamColor("Color Long Stop", colorCycle);
Buy = 1; //Change for your long signal eg Short=Cross(ma(c,10),ma(c,20));
 
 
Sell = 0;
traillongARRAY = Null;
trailstoplong = 0;
 
//----short var
 
 
StopLevel = 1-Param("Stop Short %", 7, 0.1, 20, 0.1) / 100;
P = ParamField("Price Field Short");
Shortcol = ParamColor("Color Short Stop", colorCycle);
Short = 1; // Change for your short signal eg Short=Cross(ma(c,20),ma(c,10));
Cover = 0;
trailARRAY = Null;
trailstop = 0;
 
//---calculate
for (i = 2; i < BarCount; i++)
{
  //---long
  if (trailstoplong == 0 AND Buy[i])
  {
    trailstoplong = Plong[i] *Stoplong;
  }
  else
    Buy[i] = 0;
  // remove excess buy signals
 
  if (trailstoplong > 0 AND Plong[i] < trailstoplong)
  {
    Sell[i] = 1;
    SellPrice[i] = trailstoplong;
    trailstoplong = 0;
  }
 
  if (trailstoplong > 0)
  {
    trailstoplong = Max(Plong[i] *Stoplong, trailstoplong);
    traillongARRAY[i] = trailstoplong;
  }
 
 
  //---short
 
 
  if (trailstop == 0 AND Short[i])
  {
 
    trailstop = P[i] / StopLevel; // set intinal % stop then trailing stop takes over
 
  }
  else
    Short[i] = 0;
  // remove excess short signals
 
  if (trailstop > 0 AND P[i] > trailstop)
  {
    Cover[i] = 1;
    CoverPrice[i] = trailstop;
    trailstop = 0;
  }
 
  if (trailstop > 0)
  {
    trailstop = Min(P[i] / stoplevel, trailstop);
    trailARRAY[i] = trailstop;
  }
 
}
 
// ----display results
 
Plot(traillongARRAY, "Stop Long", Longcol);
Plot(trailARRAY, "Stop Short", shortcol);
 
//PlotShapes(Short*shapeUpArrow,ParamColor( "Arrow Short Color", colorCycle),0,Low);
//PlotShapes(Cover*shapeDownArrow,ParamColor( "Arrow Cover Color", colorCycle),0,High);
//PlotShapes(Buy*shapeUpArrow,ParamColor( "Arrow Buy Color", colorCycle),0,Low);
//PlotShapes(Sell*shapeDownArrow,ParamColor( "Arrow Sell Color", colorCycle),0,High);
//Plot( Close,"Price",colorBlack,styleBar);
 
 
_SECTION_END();

0 comments

Leave Comment

Please login here to leave a comment.

Back