龙听期货论坛's Archiver

C
+
+


 微信: QQ:

龙听 发表于 2020-12-6 10:18

期货软件TB系统源代码解读系列73-恒温器系统

**** Hidden Message *****[/size]

龙听 发表于 2020-12-6 10:19

做空代码及结果如下:
[code]Params

Numeric swingTrendSwitch(20);

Numeric swingPrcnt1(0.50);

Numeric swingPrcnt2(0.75);

Numeric atrLength(10);

Numeric bollingerLengths(50);

Numeric numStdDevs(2);

Numeric trendLiqLength(50);

Numeric Lots(0);

Vars

NumericSeries cmiVal(0);

BoolSeries buyEasierDay(False);

BoolSeries sellEasierDay(False);

NumericSeries myATR(0);

NumericSeries MidLine(0);

Numeric Band(0);

NumericSeries upBand(0);

NumericSeries dnBand(0);

NumericSeries trendLokBuy(0);

NumericSeries trendLokSell(0);

NumericSeries keyOfDay(0);

NumericSeries swingBuyPt(0);

NumericSeries swingSellPt(0);

NumericSeries trendBuyPt(0);

NumericSeries trendSellPt(0);

NumericSeries swingProtStop(0);

NumericSeries trendProtStop(0);

BoolSeries swingEntry(False);

Begin

If(!CallAuctionFilter()) Return;

cmiVal = Abs(Close - Close[29])/(Highest(High,30) - Lowest(Low,30))*100;

trendLokBuy = Average(Low,3);

trendLokSell= Average(High,3);

keyOfDay = (High + Low + Close)/3;

buyEasierDay = False;

sellEasierDay = False;

If(Close[1] > keyOfDay[1]) sellEasierDay = True;

If(Close[1] <= keyOfDay[1]) buyEasierDay = True;

myATR = AvgTrueRange(atrLength);

If(buyEasierDay == True)

{

swingBuyPt = Open + swingPrcnt1*myATR[1];

swingSellPt = Open - swingPrcnt2*myATR[1];

}

If(sellEasierDay == True)

{

swingBuyPt = Open + swingPrcnt2*myATR[1];

swingSellPt = Open - swingPrcnt1*myATR[1];

}

swingBuyPt = Max(swingBuyPt,trendLokBuy[1]);

swingSellPt = Min(swingSellPt,trendLokSell[1]);

MidLine = AverageFC(Close,bollingerLengths);

Band = StandardDev(Close,bollingerLengths,2);

upBand = MidLine + numStdDevs*Band;

dnBand = MidLine - numStdDevs*Band;

trendBuyPt = upBand;

trendSellPt = dnBand;

If(cmiVal[1] < swingTrendSwitch)

{

If(MarketPosition != -1 And Low <= swingSellPt)

{

SellShort(Lots,Min(Open,swingSellPt));

swingEntry = True;

}

If(MarketPosition == -1 And BarsSinceEntry >= 1 And High >= swingBuyPt)

{

BuyToCover(0,Max(Open,swingBuyPt));

swingEntry = False;

}

}

swingProtStop = 3*myATR;

trendProtStop = Average(Close,trendLiqLength);

If(cmiVal[1] >= swingTrendSwitch)

{

If(swingEntry == True)

{

If(MarketPosition == -1 And BarsSinceEntry >= 1 And High >= (EntryPrice + swingProtStop[1]))

{

BuyToCover(0,Max(Open,EntryPrice + swingProtStop[1]));

swingEntry = False;

}

}

If(swingEntry == False)

{

If(MarketPosition != -1 And BarsSinceExit >= 1 And Low <= trendSellPt[1])

{

SellShort(Lots,Min(Open,trendSellPt[1]));

}

If(MarketPosition == -1 And BarsSinceEntry >= 1 And High >= Min(trendBuyPt[1],trendProtStop[1]))

{

BuyToCover(0,Max(Open,Min(trendBuyPt[1],trendProtStop[1])));

}

}

}

End[/code]

[attach]25967[/attach]

骄天龙 发表于 2021-2-9 21:07

谢谢楼主!新年快乐!

龙听小虎 发表于 2023-11-11 10:03

{:115:}

页: [1]