首页 > > 详细

开拓者随机发买卖单的模型源码、代写股票选股公式、股票选股公式代写、代写公式选股

思路: 投资学里经典的一句话 - 限制损失,让盈利奔跑。只要盈亏比达到一个理想的值,那胜率低也一样能赚到钱。为了验证这个理论,我写了一个随机发买卖单的模型,并且限制每次损失的上限,对盈利进行追踪止损。模型为日内交易,每3分钟发一个单。

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) // 有多仓的情况()
{
StopLine = AvgEntryPrice * (1-InitialStop/1000);

If(HighestAfterEntry[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开盘价有跳空触发,则用开盘价代替 来源
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: 88652583
© 2014 www.93stock.com
代写选股公式网!
声明:警惕假冒分子冒充本站提供证券咨询服务,选股公式网为非证券咨询机构,本站不提供有关股评、投资分析报告、股市预测,证券咨询等服务。本站仅提供股票、期货、黄金、外汇的软件技术交流与分享。本站文章为互联网文章,其仅供参考,并不构成投资建议。