增加交易策略、交易指标、量化库代码等文件夹

This commit is contained in:
Win_home
2025-04-27 15:54:09 +08:00
parent ca3b209096
commit f57150dae8
589 changed files with 854346 additions and 1757 deletions

View File

@@ -0,0 +1,273 @@
//------------------------------------------------------------------------
// <20><><EFBFBD><EFBFBD>: VIP17_duo
// <20><><EFBFBD><EFBFBD>: VIP17_duo
// <20><><EFBFBD><EFBFBD>: <20><>ʽӦ<CABD><D3A6>
// <20><><EFBFBD><EFBFBD>: <20>û<EFBFBD>Ӧ<EFBFBD><D3A6>
// <20><><EFBFBD><EFBFBD>: Void
//------------------------------------------------------------------------
Params
Numeric Fund(20000); // Ͷ<>뱣֤<EBB1A3><D6A4>
Vars
Numeric Lots(0); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Numeric totalScore(5); // <20><><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>Ŀǰ<C4BF><C7B0><EFBFBD>ǵ<EFBFBD>Ȩ<EFBFBD><C8A8><EFBFBD><EFBFBD>ܹ<EFBFBD>6<EFBFBD><36>ָ<EFBFBD>꼰6<EABCB0>֡<EFBFBD>
Numeric rpmPeriod(14); // RPM Period
Numeric bboPeriod(16); // BBO Period
Numeric macdFastPeriod(12); // MACD Fast Period
Numeric macdSlowPeriod(24); // MACD Slow Period
Numeric macdSignalPeriod(9); // MACD Signal Period
Numeric rsiPeriod(14); // RSI Period
Numeric cciPeriod(14); // CCI Period
Numeric stochasticKLength(14); // Stochastic %K Length
Numeric stochasticKSmoothing(1); // Stochastic %K Smoothing
Numeric stochasticDSmoothing(3); // Stochastic %D Smoothing
Numeric supertrendPeriod(10); // SUPERTREND Period
Numeric supertrendFactor(2); // SUPERTREND Factor
Series<Numeric> rpmValue; // RPM Value
Series<Numeric> bboValue; // BBO Value
Series<Numeric> macdValue; // MACD Value
Series<Numeric> macdSignal; // MACD Signal Line
Series<Numeric> macdHist; // MACD Histogram
Series<Numeric> rsiValue; // RSI Value
Series<Numeric> stochasticValue; // Stochastic Value
Series<Numeric> cciValue; // CCI Value
Series<Numeric> supertrendValue; // SUPERTREND Value
Series<Numeric> netChgAvg ;
Series<Numeric> totChgAvg ;
Series<Numeric> score;
Numeric EntryStrength(90); // <20><><EFBFBD><EFBFBD>ǿ<EFBFBD>ȵĽ<C8B5><C4BD><EFBFBD>ֵ
Numeric Length(5); // ǿ<><C7BF>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
Series<Numeric> CloseChange; // <20><><EFBFBD>̼۱䶯ֵ
Numeric i; // ѭ<><D1AD><EFBFBD><EFBFBD><EFBFBD>Ʊ<EFBFBD><C6B1><EFBFBD>
Numeric UpCloses; // <20><><EFBFBD>̼<EFBFBD><CCBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ۼ<EFBFBD>ֵ
Numeric DnCloses; // <20><><EFBFBD>̼<EFBFBD><CCBC>µ<EFBFBD><C2B5>ۼ<EFBFBD>ֵ
Numeric SumChange; // <20><><EFBFBD>̼۱<DBB1>ۼ<EFBFBD>ֵ
Series<Numeric> MarketStrength; // <20>г<EFBFBD>ǿ<EFBFBD><C7BF>ָ<EFBFBD><D6B8>
Plot plt1; // <20><><EFBFBD>ڻ<EFBFBD>ͼ<EFBFBD>Ķ<EFBFBD><C4B6><EFBFBD>
Events
OnInit()
{
Range[0:DataCount-1]
{
//=========<3D><><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>==============
AddDataFlag(Enum_Data_RolloverBackWard()); //<2F><><EFBFBD>ú<EFBFBD><C3BA><EFBFBD>Ȩ
AddDataFlag(Enum_Data_RolloverRealPrice()); //<2F><><EFBFBD><EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD><EFBFBD>ʵ<EFBFBD>۸<EFBFBD>
AddDataFlag(Enum_Data_AutoSwapPosition()); //<2F><><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>
//AddDataFlag(Enum_Data_IgnoreSwapSignalCalc()); //<2F><><EFBFBD>ú<EFBFBD><C3BA>Ի<EFBFBD><D4BB><EFBFBD><EFBFBD>źż<C5BA><C5BC><EFBFBD>
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ͼ
plt1.figure(0); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>
plt1.setOption("Score", "width", Enum_7Pix); // <20><>ָ<EFBFBD>ꡰMA1<41><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߿<EFBFBD><DFBF><EFBFBD><EFBFBD><EFBFBD>Ϊ3<CEAA><33><EFBFBD><EFBFBD>
plt1.setOption("Score","color",Blue);
}
OnBar(ArrayRef<Integer> indexs)
{
// <20><><EFBFBD><EFBFBD><E3BDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Lots = Max(1, Round(Fund/(O*ContractUnit*BigPointValue* MarginRatio/rollover), 0));
// <20><><EFBFBD><EFBFBD><EFBFBD>г<EFBFBD>ǿ<EFBFBD><C7BF>ָ<EFBFBD><D6B8>
CloseChange = Close - Close[1];
UpCloses = 0;
DnCloses = 0;
For i = 0 To Length-1
{
// <20><><EFBFBD>̼<EFBFBD><CCBC><EFBFBD><EFBFBD>Ǽ<EFBFBD><C7BC><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ۼ<EFBFBD>
If(CloseChange[i] > 0)
UpCloses = UpCloses + CloseChange[i];
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ۼ<EFBFBD>
Else
DnCloses = DnCloses + CloseChange[i];
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǵ<EFBFBD>
SumChange = Summation(CloseChange, Length);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǣ<EFBFBD><C7A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD>ȣ<EFBFBD>0-100֮<30><D6AE>
If(SumChange >= 0)
{
MarketStrength = SumChange / UpCloses * 100;
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>ǿ<EFBFBD>ȣ<EFBFBD>0-100֮<30><D6AE>
Else
{
MarketStrength = SumChange / Abs(DnCloses) * 100;
}
// <20><><EFBFBD><EFBFBD> MACD ֵ
Numeric emaFast = XAverage(Close, macdFastPeriod);
Numeric emaSlow = XAverage(Close, macdSlowPeriod);
macdValue = emaFast - emaSlow;
macdSignal = XAverage(macdValue, macdSignalPeriod);
macdHist = macdValue - macdSignal;
// <20><><EFBFBD><EFBFBD> RSI ֵ
Numeric SF = 1 / rsiPeriod;
Numeric change = Close - Close[1];
If(CurrentBar <= rsiPeriod - 1)
{
netChgAvg = (Close - Close[rsiPeriod]) / rsiPeriod;
totChgAvg = Average(Abs(Close - Close[1]), rsiPeriod);
}
Else
{
netChgAvg = netChgAvg[1] + SF * (change - netChgAvg[1]);
totChgAvg = totChgAvg[1] + SF * (Abs(change) - totChgAvg[1]);
}
If(totChgAvg <> 0)
{
rsiValue = 50 * (netChgAvg / totChgAvg + 1);
}
Else
{
rsiValue = 50;
}
// <20><><EFBFBD><EFBFBD> Stochastic ֵ
Numeric highestHigh = Highest(High, stochasticKLength);
Numeric lowestLow = Lowest(Low, stochasticKLength);
Numeric stochasticRaw = (Close - lowestLow) / (highestHigh - lowestLow) * 100;
stochasticValue = Average(stochasticRaw, stochasticKSmoothing);
// <20><><EFBFBD><EFBFBD> CCI ֵ
Numeric typicalPrice = (High + Low + Close) / 3;
Numeric smaTypicalPrice = Average(typicalPrice, cciPeriod);
Numeric meanDeviation = Summation(Abs(typicalPrice - smaTypicalPrice), cciPeriod) / cciPeriod;
If(meanDeviation <> 0)
{
cciValue = (typicalPrice - smaTypicalPrice) / (0.015 * meanDeviation);
}
Else
{
cciValue = 0;
}
// <20><><EFBFBD><EFBFBD> SUPERTREND ֵ
Numeric atr = AvgTrueRange(supertrendPeriod);
Numeric basicUpperBand = (High + Low) / 2 + supertrendFactor * atr;
Numeric basicLowerBand = (High + Low) / 2 - supertrendFactor * atr;
Numeric finalUpperBand = IIF(basicUpperBand < supertrendValue[1] || Close[1] > supertrendValue[1], basicUpperBand, supertrendValue[1]);
Numeric finalLowerBand = IIF(basicLowerBand > supertrendValue[1] || Close[1] < supertrendValue[1], basicLowerBand, supertrendValue[1]);
supertrendValue = IIF(Close > supertrendValue[1], finalLowerBand, finalUpperBand);
// <20><><EFBFBD>ö<EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>
Bool macdCondition = macdValue > macdSignal;
Bool rsiCondition = rsiValue >50;
Bool stochasticCondition = stochasticValue > 50;
Bool cciCondition = cciValue >0;
Bool supertrendCondition = Close > supertrendValue;
Bool Marketbool = MarketStrength >= EntryStrength;
// <20><><EFBFBD><EFBFBD><EFBFBD>÷<EFBFBD>
score = 0;
If(macdCondition)
{
score = score + 1;
}
If(rsiCondition)
{
score = score + 1;
}
If(stochasticCondition)
{
score = score + 1;
}
If(cciCondition)
{
score = score + 1;
}
If(supertrendCondition)
{
score = score + 1;
}
if(Marketbool)
{
score = score + 1;
}
// <20>ڸ<EFBFBD>ͼ<EFBFBD><CDBC>ʾ<EFBFBD>÷<EFBFBD>
Commentary("Score: " + Text(score));
plt1.barv("Score",score);
// <20>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD><EFB5BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
If(score == totalScore)
{
Commentary("All conditions met!");
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
If(score[1] >= totalScore And MarketPosition == 0 ) //
{
Buy(Lots, Open);
}
// ƽ<><C6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
If(score[1] == 0 And MarketPosition == 1)
{
Sell(0, Open);
}
// <20>ڸ<EFBFBD>ͼ<EFBFBD><CDBC>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͳ<EFBFBD><CDB2><EFBFBD><EFBFBD><EFBFBD>
If(macdCondition)
{
PlotAuto("MACD_Condition",1,1,Green,Enum_Line,Enum_Solid,Enum_7Pix);
}
Else
{
PlotAuto("MACD_Condition",1,1,Red,Enum_Line,Enum_Solid,Enum_7Pix);
}
If(rsiCondition)
{
PlotAuto("RSI_Condition",2,2,Green,Enum_Line,Enum_Solid,Enum_7Pix);
}
Else
{
PlotAuto("RSI_Condition",2,2,Red,Enum_Line,Enum_Solid,Enum_7Pix);
}
If(stochasticCondition)
{
PlotAuto("Stochastic_Condition", 3,3,Green,Enum_Line,Enum_Solid,Enum_7Pix);
}
Else
{
PlotAuto("Stochastic_Condition", 3,3,Red,Enum_Line,Enum_Solid,Enum_7Pix);
}
If(cciCondition)
{
PlotAuto("CCI_Condition", 4,4,Green,Enum_Line,Enum_Solid,Enum_7Pix);
}
Else
{
PlotAuto("CCI_Condition", 4,4,Red,Enum_Line,Enum_Solid,Enum_7Pix);
}
If(supertrendCondition)
{
PlotAuto("Supertrend_Condition", 5,5,Green,Enum_Line,Enum_Solid,Enum_7Pix);
}
Else
{
PlotAuto("Supertrend_Condition", 5,5,Red,Enum_Line,Enum_Solid,Enum_7Pix);
}
If(Marketbool)
{
PlotAuto("Marketbool", 6,6,Green,Enum_Line,Enum_Solid,Enum_7Pix);
}
Else
{
PlotAuto("Marketbool", 6,6,Red,Enum_Line,Enum_Solid,Enum_7Pix);
}
}
//------------------------------------------------------------------------
// <20><><EFBFBD><EFBFBD><EFBFBD>汾 2024/11/27 145803
// <20><>Ȩ<EFBFBD><C8A8><EFBFBD><EFBFBD> songshu123
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> TradeBlazer Software<72><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD>TradeBlazerƽ̨
// ÿһ<C3BF><EFBFBD><E6B1BE>TradeBlazer<65><72>ʽ<EFBFBD>޸ĺ<DEB8><C4BA><EFBFBD>д<EFBFBD><D0B4>Ȩ<EFBFBD><C8A8>
//------------------------------------------------------------------------

View File

@@ -0,0 +1,274 @@
//------------------------------------------------------------------------
// <20><><EFBFBD><EFBFBD>: vip17_kong
// <20><><EFBFBD><EFBFBD>: vip17_kong
// <20><><EFBFBD><EFBFBD>: <20><>ʽӦ<CABD><D3A6>
// <20><><EFBFBD><EFBFBD>: <20>û<EFBFBD>Ӧ<EFBFBD><D3A6>
// <20><><EFBFBD><EFBFBD>: Void
//------------------------------------------------------------------------
Params
Numeric Fund(20000); // Ͷ<>뱣֤<EBB1A3><D6A4>
Vars
Numeric Lots(0); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Numeric totalScore(5); // <20><><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>Ŀǰ<C4BF><C7B0><EFBFBD>ǵ<EFBFBD>Ȩ<EFBFBD><C8A8><EFBFBD><EFBFBD>ܹ<EFBFBD>6<EFBFBD><36>ָ<EFBFBD>꼰6<EABCB0>֡<EFBFBD>
Numeric rpmPeriod(14); // RPM Period
Numeric bboPeriod(16); // BBO Period
Numeric macdFastPeriod(12); // MACD Fast Period
Numeric macdSlowPeriod(24); // MACD Slow Period
Numeric macdSignalPeriod(9); // MACD Signal Period
Numeric rsiPeriod(14); // RSI Period
Numeric cciPeriod(14); // CCI Period
Numeric stochasticKLength(14); // Stochastic %K Length
Numeric stochasticKSmoothing(1); // Stochastic %K Smoothing
Numeric stochasticDSmoothing(3); // Stochastic %D Smoothing
Numeric supertrendPeriod(10); // SUPERTREND Period
Numeric supertrendFactor(2); // SUPERTREND Factor
Series<Numeric> rpmValue; // RPM Value
Series<Numeric> bboValue; // BBO Value
Series<Numeric> macdValue; // MACD Value
Series<Numeric> macdSignal; // MACD Signal Line
Series<Numeric> macdHist; // MACD Histogram
Series<Numeric> rsiValue; // RSI Value
Series<Numeric> stochasticValue; // Stochastic Value
Series<Numeric> cciValue; // CCI Value
Series<Numeric> supertrendValue; // SUPERTREND Value
Series<Numeric> netChgAvg ;
Series<Numeric> totChgAvg ;
Series<Numeric> score;
Numeric EntryStrength(90); // <20><><EFBFBD><EFBFBD>ǿ<EFBFBD>ȵĽ<C8B5><C4BD><EFBFBD>ֵ
Numeric Length(5); // ǿ<><C7BF>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
Series<Numeric> CloseChange; // <20><><EFBFBD>̼۱䶯ֵ
Numeric i; // ѭ<><D1AD><EFBFBD><EFBFBD><EFBFBD>Ʊ<EFBFBD><C6B1><EFBFBD>
Numeric UpCloses; // <20><><EFBFBD>̼<EFBFBD><CCBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ۼ<EFBFBD>ֵ
Numeric DnCloses; // <20><><EFBFBD>̼<EFBFBD><CCBC>µ<EFBFBD><C2B5>ۼ<EFBFBD>ֵ
Numeric SumChange; // <20><><EFBFBD>̼۱<DBB1>ۼ<EFBFBD>ֵ
Series<Numeric> MarketStrength; // <20>г<EFBFBD>ǿ<EFBFBD><C7BF>ָ<EFBFBD><D6B8>
Plot plt1; // <20><><EFBFBD>ڻ<EFBFBD>ͼ<EFBFBD>Ķ<EFBFBD><C4B6><EFBFBD>
Events
OnInit()
{
Range[0:DataCount-1]
{
//=========<3D><><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>==============
AddDataFlag(Enum_Data_RolloverBackWard()); //<2F><><EFBFBD>ú<EFBFBD><C3BA><EFBFBD>Ȩ
AddDataFlag(Enum_Data_RolloverRealPrice()); //<2F><><EFBFBD><EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD><EFBFBD>ʵ<EFBFBD>۸<EFBFBD>
AddDataFlag(Enum_Data_AutoSwapPosition()); //<2F><><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>
//AddDataFlag(Enum_Data_IgnoreSwapSignalCalc()); //<2F><><EFBFBD>ú<EFBFBD><C3BA>Ի<EFBFBD><D4BB><EFBFBD><EFBFBD>źż<C5BA><C5BC><EFBFBD>
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ͼ
plt1.figure(0); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>
plt1.setOption("Score", "width", Enum_7Pix); // <20><>ָ<EFBFBD>ꡰMA1<41><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߿<EFBFBD><DFBF><EFBFBD><EFBFBD><EFBFBD>Ϊ3<CEAA><33><EFBFBD><EFBFBD>
plt1.setOption("Score","color",Blue);
}
OnBar(ArrayRef<Integer> indexs)
{
// <20><><EFBFBD><EFBFBD><E3BDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Lots = Max(1, Round(Fund/(O*ContractUnit*BigPointValue* MarginRatio/rollover), 0));
// <20><><EFBFBD><EFBFBD><EFBFBD>г<EFBFBD>ǿ<EFBFBD><C7BF>ָ<EFBFBD><D6B8>
CloseChange = Close - Close[1];
UpCloses = 0;
DnCloses = 0;
For i = 0 To Length-1
{
// <20><><EFBFBD>̼<EFBFBD><CCBC><EFBFBD><EFBFBD>Ǽ<EFBFBD><C7BC><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ۼ<EFBFBD>
If(CloseChange[i] > 0)
UpCloses = UpCloses + CloseChange[i];
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ۼ<EFBFBD>
Else
DnCloses = DnCloses + CloseChange[i];
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǵ<EFBFBD>
SumChange = Summation(CloseChange, Length);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǣ<EFBFBD><C7A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD>ȣ<EFBFBD>0-100֮<30><D6AE>
If(SumChange >= 0)
{
MarketStrength = SumChange / UpCloses * 100;
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>ǿ<EFBFBD>ȣ<EFBFBD>0-100֮<30><D6AE>
Else
{
MarketStrength = SumChange / Abs(DnCloses) * 100;
}
// <20><><EFBFBD><EFBFBD> MACD ֵ
Numeric emaFast = XAverage(Close, macdFastPeriod);
Numeric emaSlow = XAverage(Close, macdSlowPeriod);
macdValue = emaFast - emaSlow;
macdSignal = XAverage(macdValue, macdSignalPeriod);
macdHist = macdValue - macdSignal;
// <20><><EFBFBD><EFBFBD> RSI ֵ
Numeric SF = 1 / rsiPeriod;
Numeric change = Close - Close[1];
If(CurrentBar <= rsiPeriod - 1)
{
netChgAvg = (Close - Close[rsiPeriod]) / rsiPeriod;
totChgAvg = Average(Abs(Close - Close[1]), rsiPeriod);
}
Else
{
netChgAvg = netChgAvg[1] + SF * (change - netChgAvg[1]);
totChgAvg = totChgAvg[1] + SF * (Abs(change) - totChgAvg[1]);
}
If(totChgAvg <> 0)
{
rsiValue = 50 * (netChgAvg / totChgAvg + 1);
}
Else
{
rsiValue = 50;
}
// <20><><EFBFBD><EFBFBD> Stochastic ֵ
Numeric highestHigh = Highest(High, stochasticKLength);
Numeric lowestLow = Lowest(Low, stochasticKLength);
Numeric stochasticRaw = (Close - lowestLow) / (highestHigh - lowestLow) * 100;
stochasticValue = Average(stochasticRaw, stochasticKSmoothing);
// <20><><EFBFBD><EFBFBD> CCI ֵ
Numeric typicalPrice = (High + Low + Close) / 3;
Numeric smaTypicalPrice = Average(typicalPrice, cciPeriod);
Numeric meanDeviation = Summation(Abs(typicalPrice - smaTypicalPrice), cciPeriod) / cciPeriod;
If(meanDeviation <> 0)
{
cciValue = (typicalPrice - smaTypicalPrice) / (0.015 * meanDeviation);
}
Else
{
cciValue = 0;
}
// <20><><EFBFBD><EFBFBD> SUPERTREND ֵ
Numeric atr = AvgTrueRange(supertrendPeriod);
Numeric basicUpperBand = (High + Low) / 2 + supertrendFactor * atr;
Numeric basicLowerBand = (High + Low) / 2 - supertrendFactor * atr;
Numeric finalUpperBand = IIF(basicUpperBand < supertrendValue[1] || Close[1] > supertrendValue[1], basicUpperBand, supertrendValue[1]);
Numeric finalLowerBand = IIF(basicLowerBand > supertrendValue[1] || Close[1] < supertrendValue[1], basicLowerBand, supertrendValue[1]);
supertrendValue = IIF(Close > supertrendValue[1], finalLowerBand, finalUpperBand);
// <20><><EFBFBD>ÿ<EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>
Bool macdCondition = macdValue < macdSignal;
Bool rsiCondition = rsiValue <50;
Bool stochasticCondition = stochasticValue < 50;
Bool cciCondition = cciValue <0;
Bool supertrendCondition = Close < supertrendValue;
Bool Marketbool = MarketStrength >= EntryStrength;
// <20><><EFBFBD><EFBFBD><EFBFBD>÷<EFBFBD>
score = 0;
If(macdCondition)
{
score = score + 1;
}
If(rsiCondition)
{
score = score + 1;
}
If(stochasticCondition)
{
score = score + 1;
}
If(cciCondition)
{
score = score + 1;
}
If(supertrendCondition)
{
score = score + 1;
}
if(Marketbool)
{
score = score + 1;
}
// <20>ڸ<EFBFBD>ͼ<EFBFBD><CDBC>ʾ<EFBFBD>÷<EFBFBD>
Commentary("Score: " + Text(score));
plt1.barv("Score",score);
// <20>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD><EFB5BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
If(score == totalScore)
{
Commentary("All conditions met!");
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
If(score[1] >= totalScore And MarketPosition == 0 ) //
{
SellShort(Lots, Open);
}
// ƽ<><C6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
If(score[1] == 0 And MarketPosition == -1)
{
BuyToCover(0, Open);
}
// <20>ڸ<EFBFBD>ͼ<EFBFBD><CDBC>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͳ<EFBFBD><CDB2><EFBFBD><EFBFBD><EFBFBD>
If(macdCondition)
{
PlotAuto("MACD_Condition",1,1,Green,Enum_Line,Enum_Solid,Enum_7Pix);
}
Else
{
PlotAuto("MACD_Condition",1,1,Red,Enum_Line,Enum_Solid,Enum_7Pix);
}
If(rsiCondition)
{
PlotAuto("RSI_Condition",2,2,Green,Enum_Line,Enum_Solid,Enum_7Pix);
}
Else
{
PlotAuto("RSI_Condition",2,2,Red,Enum_Line,Enum_Solid,Enum_7Pix);
}
If(stochasticCondition)
{
PlotAuto("Stochastic_Condition", 3,3,Green,Enum_Line,Enum_Solid,Enum_7Pix);
}
Else
{
PlotAuto("Stochastic_Condition", 3,3,Red,Enum_Line,Enum_Solid,Enum_7Pix);
}
If(cciCondition)
{
PlotAuto("CCI_Condition", 4,4,Green,Enum_Line,Enum_Solid,Enum_7Pix);
}
Else
{
PlotAuto("CCI_Condition", 4,4,Red,Enum_Line,Enum_Solid,Enum_7Pix);
}
If(supertrendCondition)
{
PlotAuto("Supertrend_Condition", 5,5,Green,Enum_Line,Enum_Solid,Enum_7Pix);
}
Else
{
PlotAuto("Supertrend_Condition", 5,5,Red,Enum_Line,Enum_Solid,Enum_7Pix);
}
If(Marketbool)
{
PlotAuto("Marketbool", 6,6,Green,Enum_Line,Enum_Solid,Enum_7Pix);
}
Else
{
PlotAuto("Marketbool", 6,6,Red,Enum_Line,Enum_Solid,Enum_7Pix);
}
}
//------------------------------------------------------------------------
// <20><><EFBFBD><EFBFBD><EFBFBD>汾 2024/11/27 150615
// <20><>Ȩ<EFBFBD><C8A8><EFBFBD><EFBFBD> songshu123
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> TradeBlazer Software<72><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD>TradeBlazerƽ̨
// ÿһ<C3BF><EFBFBD><E6B1BE>TradeBlazer<65><72>ʽ<EFBFBD>޸ĺ<DEB8><C4BA><EFBFBD>д<EFBFBD><D0B4>Ȩ<EFBFBD><C8A8>
//------------------------------------------------------------------------

View File

@@ -0,0 +1,210 @@
from vnpy_ctastrategy import (
CtaTemplate,
TargetPosTemplate,
StopOrder,
TickData,
BarData,
TradeData,
OrderData,
BarGenerator,
ArrayManager,
)
import pandas as pd
import numpy as np
import talib
class vip17_duo(CtaTemplate):
"""
VIP17多头策略
基于多个技术指标的多头策略,当满足一定数量的多头条件时开仓
"""
author = "松鼠Quant"
# 策略参数
total_score = 5 # 开仓分数阈值
entry_strength = 90 # 趋势强度的进场值
length = 5 # 强弱指标和通道计算的周期值
# 指标参数
rpm_period = 14 # RPM Period
bbo_period = 16 # BBO Period
macd_fast_period = 12 # MACD Fast Period
macd_slow_period = 24 # MACD Slow Period
macd_signal_period = 9 # MACD Signal Period
rsi_period = 14 # RSI Period
cci_period = 14 # CCI Period
stoch_k_period = 14 # Stochastic %K Length
stoch_k_smooth = 1 # Stochastic %K Smoothing
stoch_d_smooth = 3 # Stochastic %D Smoothing
supertrend_period = 10 # SUPERTREND Period
supertrend_factor = 2 # SUPERTREND Factor
parameters = ["total_score", "entry_strength", "length",
"macd_fast_period", "macd_slow_period", "macd_signal_period",
"rsi_period", "cci_period", "stoch_k_period"]
variables = ["current_score"]
def __init__(self, cta_engine, strategy_name, vt_symbol, setting):
super().__init__(cta_engine, strategy_name, vt_symbol, setting)
self.bg = BarGenerator(self.on_bar)
self.am = ArrayManager(size=100)
# 指标变量
self.current_score = 0
self.market_strength = 0
self.supertrend_value = 0
def on_init(self):
"""
策略初始化
"""
self.write_log("策略初始化")
self.load_bar(100)
def on_start(self):
"""
策略启动
"""
self.write_log("策略启动")
def on_stop(self):
"""
策略停止
"""
self.write_log("策略停止")
def on_tick(self, tick: TickData):
"""
Tick数据更新
"""
self.bg.update_tick(tick)
def calculate_market_strength(self):
"""计算市场强度指标"""
close_change = self.am.close_array[1:] - self.am.close_array[:-1]
up_closes = 0
dn_closes = 0
for i in range(self.length):
if close_change[-i-1] > 0:
up_closes += close_change[-i-1]
else:
dn_closes += close_change[-i-1]
sum_change = np.sum(close_change[-self.length:])
if sum_change >= 0:
self.market_strength = (sum_change / up_closes * 100) if up_closes != 0 else 0
else:
self.market_strength = (sum_change / abs(dn_closes) * 100) if dn_closes != 0 else 0
return self.market_strength >= self.entry_strength
def calculate_supertrend(self):
"""计算SuperTrend指标"""
atr = talib.ATR(self.am.high_array, self.am.low_array,
self.am.close_array, self.supertrend_period)
basic_upper = (self.am.high_array + self.am.low_array) / 2 + self.supertrend_factor * atr
basic_lower = (self.am.high_array + self.am.low_array) / 2 - self.supertrend_factor * atr
# 简化的SuperTrend计算
self.supertrend_value = basic_lower[-1]
return self.am.close_array[-1] > self.supertrend_value
def calculate_score(self):
"""
计算综合得分
"""
score = 0
# MACD条件 - 多头信号
# 使用talib直接计算MACD
macd, signal, hist = talib.MACD(
self.am.close_array,
fastperiod=self.macd_fast_period,
slowperiod=self.macd_slow_period,
signalperiod=self.macd_signal_period
)
if not np.isnan(macd[-1]) and not np.isnan(signal[-1]):
if macd[-1] > signal[-1]: # 多头信号MACD线在信号线上方
score += 1
# RSI条件 - 多头信号
rsi = talib.RSI(self.am.close_array, timeperiod=self.rsi_period)
if not np.isnan(rsi[-1]) and rsi[-1] > 50: # 多头信号RSI大于50
score += 1
# Stochastic条件 - 多头信号
k, d = talib.STOCH(
self.am.high_array,
self.am.low_array,
self.am.close_array,
fastk_period=self.stoch_k_period,
slowk_period=self.stoch_k_smooth,
slowd_period=self.stoch_d_smooth
)
if not np.isnan(k[-1]) and k[-1] > 50: # 多头信号K值大于50
score += 1
# CCI条件 - 多头信号
cci = talib.CCI(
self.am.high_array,
self.am.low_array,
self.am.close_array,
timeperiod=self.cci_period
)
if not np.isnan(cci[-1]) and cci[-1] > 0: # 多头信号CCI大于0
score += 1
# Supertrend条件
if self.calculate_supertrend():
score += 1
# 市场强度条件
if self.calculate_market_strength():
score += 1
return score
def on_bar(self, bar: BarData):
"""
K线更新回调
"""
self.am.update_bar(bar)
if not self.am.inited:
return
# 计算当前得分
self.current_score = self.calculate_score()
# 交易信号
if self.current_score >= self.total_score and not self.pos:
self.buy(bar.close_price + 5, 1)
elif self.current_score == 0 and self.pos > 0:
self.sell(bar.close_price - 5, abs(self.pos))
# 输出当前得分
self.put_event()
def on_trade(self, trade: TradeData):
"""
成交回调
"""
self.put_event()
def on_order(self, order: OrderData):
"""
委托回调
"""
pass
def on_stop_order(self, stop_order: StopOrder):
"""
停止单回调
"""
pass

View File

@@ -0,0 +1,208 @@
from vnpy_ctastrategy import (
CtaTemplate,
TargetPosTemplate,
StopOrder,
TickData,
BarData,
TradeData,
OrderData,
BarGenerator,
ArrayManager,
)
import pandas as pd
import numpy as np
import talib
class vip17_kong(CtaTemplate):
"""
VIP17空头策略
基于多个技术指标的空头策略,当满足一定数量的空头条件时开仓
"""
author = "松鼠Quant"
# 策略参数
total_score = 5 # 开仓分数阈值
entry_strength = 90 # 趋势强度的进场值
length = 5 # 强弱指标和通道计算的周期值
# 指标参数
rpm_period = 14 # RPM Period
bbo_period = 16 # BBO Period
macd_fast_period = 12 # MACD Fast Period
macd_slow_period = 24 # MACD Slow Period
macd_signal_period = 9 # MACD Signal Period
rsi_period = 14 # RSI Period
cci_period = 14 # CCI Period
stoch_k_period = 14 # Stochastic %K Length
stoch_k_smooth = 1 # Stochastic %K Smoothing
stoch_d_smooth = 3 # Stochastic %D Smoothing
supertrend_period = 10 # SUPERTREND Period
supertrend_factor = 2 # SUPERTREND Factor
parameters = ["total_score", "entry_strength", "length",
"macd_fast_period", "macd_slow_period", "macd_signal_period",
"rsi_period", "cci_period", "stoch_k_period"]
variables = ["current_score"]
def __init__(self, cta_engine, strategy_name, vt_symbol, setting):
super().__init__(cta_engine, strategy_name, vt_symbol, setting)
self.bg = BarGenerator(self.on_bar)
self.am = ArrayManager(size=100)
# 指标变量
self.current_score = 0
self.market_strength = 0
self.supertrend_value = 0
def on_init(self):
"""
策略初始化
"""
self.write_log("策略初始化")
self.load_bar(100)
def on_start(self):
"""
策略启动
"""
self.write_log("策略启动")
def on_stop(self):
"""
策略停止
"""
self.write_log("策略停止")
def on_tick(self, tick: TickData):
"""
Tick数据更新
"""
self.bg.update_tick(tick)
def calculate_market_strength(self):
"""计算市场强度指标"""
close_change = self.am.close_array[1:] - self.am.close_array[:-1]
up_closes = 0
dn_closes = 0
for i in range(self.length):
if close_change[-i-1] > 0:
up_closes += close_change[-i-1]
else:
dn_closes += close_change[-i-1]
sum_change = np.sum(close_change[-self.length:])
if sum_change >= 0:
self.market_strength = (sum_change / up_closes * 100) if up_closes != 0 else 0
else:
self.market_strength = (sum_change / abs(dn_closes) * 100) if dn_closes != 0 else 0
return self.market_strength <= -self.entry_strength # 改为判断下跌强度
def calculate_supertrend(self):
"""计算SuperTrend指标"""
atr = talib.ATR(self.am.high_array, self.am.low_array,
self.am.close_array, self.supertrend_period)
basic_upper = (self.am.high_array + self.am.low_array) / 2 + self.supertrend_factor * atr
basic_lower = (self.am.high_array + self.am.low_array) / 2 - self.supertrend_factor * atr
# 简化的SuperTrend计算
self.supertrend_value = basic_upper[-1] # 改为上轨
return self.am.close_array[-1] < self.supertrend_value # 改为判断价格低于上轨
def calculate_score(self):
"""
计算综合得分
"""
score = 0
# MACD条件 - 空头信号
# 使用talib直接计算MACD
macd, signal, hist = talib.MACD(
self.am.close_array,
fastperiod=self.macd_fast_period,
slowperiod=self.macd_slow_period,
signalperiod=self.macd_signal_period
)
if not np.isnan(macd[-1]) and not np.isnan(signal[-1]):
if macd[-1] < signal[-1]: # 空头信号
score += 1
# RSI条件 - 空头信号
rsi = talib.RSI(self.am.close_array, timeperiod=self.rsi_period)
if not np.isnan(rsi[-1]) and rsi[-1] < 50:
score += 1
# Stochastic条件 - 空头信号
k, d = talib.STOCH(
self.am.high_array,
self.am.low_array,
self.am.close_array,
fastk_period=self.stoch_k_period,
slowk_period=self.stoch_k_smooth,
slowd_period=self.stoch_d_smooth
)
if not np.isnan(k[-1]) and k[-1] < 50:
score += 1
# CCI条件 - 空头信号
cci = talib.CCI(
self.am.high_array,
self.am.low_array,
self.am.close_array,
timeperiod=self.cci_period
)
if not np.isnan(cci[-1]) and cci[-1] < 0:
score += 1
# Supertrend条件 - 空头信号
if self.calculate_supertrend():
score += 1
# 市场强度条件 - 空头信号
if self.calculate_market_strength():
score += 1
return score
def on_bar(self, bar: BarData):
"""
K线更新回调
"""
self.am.update_bar(bar)
if not self.am.inited:
return
# 计算当前得分
self.current_score = self.calculate_score()
# 交易信号
if self.current_score >= self.total_score and not self.pos:
self.short(bar.close_price - 5, 1) # 改为做空
elif self.current_score == 0 and self.pos < 0: # 改为判断空仓
self.cover(bar.close_price + 5, abs(self.pos)) # 改为平空
self.put_event()
def on_trade(self, trade: TradeData):
"""
成交回调
"""
self.put_event()
def on_order(self, order: OrderData):
"""
委托回调
"""
pass
def on_stop_order(self, stop_order: StopOrder):
"""
停止单回调
"""
pass

View File

@@ -0,0 +1,7 @@
ͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>VIP15<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>.rar
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>: https://pan.baidu.com/s/1liwdmvmGJ7wjHWVewZUUWA?pwd=7777 <20><>ȡ<EFBFBD><C8A1>: 7777
--<2D><><EFBFBD>԰ٶ<D4B0><D9B6><EFBFBD><EFBFBD>̳<EFBFBD><CCB3><EFBFBD><EFBFBD><EFBFBD>Աv7<76>ķ<EFBFBD><C4B7><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˲<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˣ<EFBFBD><EFBFBD><EFBFBD>ϵС<EFBFBD><EFBFBD><EFBFBD><EFBFBD>΢<EFBFBD>ţ<EFBFBD>viquant01
quant789.com<6F><6D><EFBFBD><EFBFBD>ʹ<EFBFBD>ò<EFBFBD><C3B2><EFBFBD>ѡȡ<D1A1><C8A1><EFBFBD><EFBFBD>