开拓者随机发买卖单的模型源码[开拓者公式]
- 思路: 投资学里经典的一句话 - 限制损失,让盈利奔跑。只要盈亏比达到一个理想的值,那胜率低也一样能赚到钱。为了验证这个理论,我写了一个随机发买卖单的模型,并且限制每次损失的上限,对盈利进行追踪止损。模型为日内交易,每3分钟发一个单。
- 源码:(程序化交易网 WWW.CXH99.COM 转载请保留出处)
- Params
- Numeric InitialStop(2);
- Numeric BreakEvenStop(3);
- Numeric TrailStop(5);
- Vars
- Numeric RandNum;
- Numeric BuyOrSell;
- Numeric StopLine;
- Numeric MyEntryPrice;
- Numeric MyExitPrice;
- NumericSeries HighestAfterEntry;
- NumericSeries LowestAfterEntry;
- Begin
- If(Time>=0.1455){//如果要实盘测试,把Time改为CurrentTime
- If(MarketPosition == 1)
- Sell(0,Close);
- If(MarketPosition == -1)
- BuyToCover(0,Close);
- return;
- }
- If(BarsSinceentry == 0)
- {
- HighestAfterEntry = Close;
- LowestAfterEntry = Close;
- If(MarketPosition <> 0)
- {
- HighestAfterEntry = Max(HighestAfterEntry,AvgEntryPrice);
- LowestAfterEntry = Min(LowestAfterEntry,AvgEntryPrice);
- }
- }else
- {
- HighestAfterEntry = Max(HighestAfterEntry,High);
- LowestAfterEntry = Min(LowestAfterEntry,Low);
- }
- Commentary("HighestAfterEntry="+Text(HighestAfterEntry)); Commentary("LowestAfterEntry="+Text(LowestAfterEntry));
- MyEntryPrice = AvgEntryPrice;
- If(MarketPosition==1) // 有多仓的情况( WWW.CXH99.COM )
- {
- StopLine = AvgEntryPrice * (1-InitialStop/1000);
- If(HighestAfterEntry[1] >= MyEntryPrice *(1 + BreakEvenStop/1000))
- Stopline = MyEntryPrice;
- If(Stopline < HighestAfterEntry[1]*(1 - TrailStop/1000))
- Stopline = HighestAfterEntry[1]*(1 - TrailStop/1000);
- if(Low <= Stopline)
- {
- MyExitPrice = Stopline;
- If(Open < MyExitPrice) MyExitPrice = Open; // 如果该Bar开盘价有跳空触发,则用开盘价代替
- Sell(0,MyExitPrice);
- return;
- }
- }else if(MarketPosition==-1) // 有空仓的情况
- {
- StopLine = AvgEntryPrice * (1+InitialStop/1000);
- If(LowestAfterEntry[1] <= MyEntryPrice *(1 - BreakEvenStop/1000))
- Stopline = MyEntryPrice;
- If(Stopline > LowestAfterEntry[1]*(1 + TrailStop/1000))
- Stopline = LowestAfterEntry[1]*(1 + TrailStop/1000);
- Commentary("StopLine="+Text(Stopline));
- If(High >= Stopline)
- {
- MyExitPrice = Stopline;
- If(Open > MyExitPrice) MyExitPrice = Open; // 如果该Bar开盘价有跳空触发,则用开盘价代替 来源 CXH99.COM
- BuyToCover(0,MyExitPrice);
- return;
- }
- }
- RandNum = Rand(0,100); //产生0到100的随机数
- BuyOrSell = Mod(RandNum,2); //产生0到1的随机数
- Commentary("BuyOrSell:"+TEXT(BuyOrSell));
- If(BuyOrSell == 0 && Mod(Minute,3) == 0 && MarketPosition!= -1) //如果BuyOrSell为0,每3分钟发一次多单
- Buy(1,Close);
- else If(BuyOrSell == 1 && Mod(Minute,3) == 0 && MarketPosition!=1)//如果BuyOrSell为1,每3分钟发一次空单
- SellShort(1,Close);
- End
有思路,想编写各种指标公式,程序化交易模型,选股公式,预警公式的朋友
可联系技术人员 QQ: 262069696 进行 有偿 编写!(不贵!点击查看价格!)
相关文章
-
没有相关内容