  
- UID
- 2
- 积分
- 2946807
- 威望
- 1423440 布
- 龙e币
- 1523367 刀
- 在线时间
- 13794 小时
- 注册时间
- 2009-12-3
- 最后登录
- 2025-4-28

|
Supertrend(有買賣訊號)- // Supertrend Indicator with Buy/Sell Arrows for PowerLanguage (MultiCharts)
- // Advanced version with signals
- Inputs:
- ATRLength(10),
- Multiplier(3.0);
- Variables:
- ATR(0),
- UpperBand(0),
- LowerBand(0),
- Trend(1),
- Supertrend(0),
- PrevSupertrend(0),
- PrevTrend(1);
- // Calculate ATR
- ATR = AvgTrueRange(ATRLength);
- // Calculate Basic Bands
- UpperBand = (High + Low) / 2 + Multiplier * ATR;
- LowerBand = (High + Low) / 2 - Multiplier * ATR;
- // Supertrend Calculation
- If CurrentBar = 1 then
- begin
- Supertrend = UpperBand;
- PrevTrend = 1;
- end
- else
- begin
- if Close > PrevSupertrend then
- Supertrend = MaxList(LowerBand, PrevSupertrend)
- else
- Supertrend = MinList(UpperBand, PrevSupertrend);
- if Close > Supertrend then
- Trend = 1
- else if Close < Supertrend then
- Trend = -1;
- end;
- // Detect Trend Change for Buy/Sell Signals
- if Trend <> PrevTrend then
- begin
- if Trend = 1 then
- Alert("Buy Signal");
- if Trend = -1 then
- Alert("Sell Signal");
- end;
- // Save for next bar
- PrevSupertrend = Supertrend;
- PrevTrend = Trend;
- // Plot Supertrend
- Plot1(Supertrend, "Supertrend");
- Plot2(UpperBand, "UpperBand");
- Plot3(LowerBand, "LowerBand");
- if Trend = 1 then
- SetPlotColor(1, Green)
- else
- SetPlotColor(1, Red);
- // Plot Buy/Sell Arrows
- if Trend <> PrevTrend then
- begin
- if Trend = 1 then
- PlotPaintBar(High, Low, Open, Close, "Buy", Green)
- else if Trend = -1 then
- PlotPaintBar(High, Low, Open, Close, "Sell", Red);
- end;
复制代码 |
|