//------------------------------------------------------------------------
// 简称: VolumeAccumulationWithFenxingAndStop
// 名称: 成交量堆积与顶底分型及移动止损止盈策略
// 来源:松鼠QuantAi助手编写-https://ai.kanpan789.com/
// 类别: 公式应用
// 类型: 内建应用
//------------------------------------------------------------------------
Params Numeric Length(10); Numeric Threshold(2); Numeric LookBackPeriod(5); Numeric StopLossPercent(0.02); Numeric TakeProfitPercent(0.05); Numeric TrailingStopPercent(0.01); Numeric AmplitudeFilter(0.01);
Vars Series<Numeric> VolumeAccumulation(0); Series<Bool> BuySignal(False); Series<Bool> SellSignal(False); Series<Numeric> IsTop; Series<Numeric> IsBottom; Series<Numeric> TopPrice; Series<Numeric> BottomPrice; Series<Numeric> StopLossPrice; Series<Numeric> TakeProfitPrice; Series<Numeric> TrailingStopPrice; Series<Numeric> Amplitude;
Events OnBar(ArrayRef<Integer> indexs) { Numeric sumVol = 0; Numeric i = 0;For i = 1 To Length { sumVol = sumVol + vol[i]; } VolumeAccumulation = sumVol;
BuySignal = VolumeAccumulation > Threshold * Average(vol, Length);
SellSignal = VolumeAccumulation < Threshold * Average(vol, Length);
If(High[1] > High[2] And High[1] > High[3] And High[1] > High[4] And High[1] > High[5]) { IsTop = 1; TopPrice = High[1]; }Else { IsTop = 0; }
If(Low[1] < Low[2] And Low[1] < Low[3] And Low[1] < Low[4] And Low[1] < Low[5]) { IsBottom = 1; BottomPrice = Low[1]; }Else { IsBottom = 0; }
Amplitude = Abs(High - Low) / Close;
If (BuySignal[1] And IsBottom[1] > 0And MarketPosition == 0And Amplitude[1] > AmplitudeFilter) { Buy(1, Open); StopLossPrice = EntryPrice * (1 - StopLossPercent); TakeProfitPrice = EntryPrice * (1 + TakeProfitPercent); TrailingStopPrice = EntryPrice * (1 - TrailingStopPercent); }
If (SellSignal[1] And IsTop[1] > 0And MarketPosition == 1And Amplitude[1] > AmplitudeFilter) { Sell(1, Open); }
If (MarketPosition == 1And BarsSinceEntry > 0) { TrailingStopPrice = Max(TrailingStopPrice, Low * (1 - TrailingStopPercent)); }If (MarketPosition == -1And BarsSinceEntry > 0) { TrailingStopPrice = Min(TrailingStopPrice, High * (1 + TrailingStopPercent)); }
If (MarketPosition == 1And BarsSinceEntry > 0) {If (Low <= TrailingStopPrice) { Sell(1, Min(Open, TrailingStopPrice)); }ElseIf (High >= TakeProfitPrice) { Sell(1, Max(Open, TakeProfitPrice)); } }
Commentary("VolumeAccumulation: " + text(VolumeAccumulation)); Commentary("IsTop: " + text(IsTop)); Commentary("TopPrice: " + text(TopPrice)); Commentary("IsBottom: " + text(IsBottom)); Commentary("BottomPrice: " + text(BottomPrice)); Commentary("StopLossPrice: " + text(StopLossPrice)); Commentary("TakeProfitPrice: " + text(TakeProfitPrice)); Commentary("TrailingStopPrice: " + text(TrailingStopPrice)); Commentary("Amplitude: " + text(Amplitude)); }
//------------------------------------------------------------------------
// 编译版本 GS2010.12.08// 版权所有 TradeBlazer Software 2003-2025
// 更改声明 TradeBlazer Software保留对TradeBlazer平台每一版本的TradeBlazer公式修改和重写的权利
//------------------------------------------------------------------------
// 由 Ai 生成的内容仅作为学习参考,不能保证正确性,不构成任何投资意见,风险自负。