请教nopain,写了5小时,实在是很为难啊。
求教了,这个该怎样编写啊。如果获利达到2R了那么后面行情无论涨跌我都采取一种立场方式。但是到3R后我又采取另外一种方式立场。比如KDJ指标。
因为收盘价达到2R后,后面有可能下一个BAR 有没有2R了,但是只要前面达到一次我就必须采用一种策略出场。 其实很简单,就是记住开仓后的最高价或最低价,然后判断相应的处理。类似于多级跟踪止损。
先建两个序列变量:
NumericSeries HigherAfterEntry;
NumericSeries LowerAfterEntry;
在程序开始的地方初始化:
If(BarsSinceEntry == 1)
{
HigherAfterEntry = AvgEntryPrice;
LowerAfterEntry = HigherAfterEntry;
}Else If(BarsSinceEntry > 1)
{
HigherAfterEntry = max(HigherAfterEntry[1],High[1]);
LowerAfterEntry = min(LowerAfterEntry[1],Low[1]);
}
最后进行处理:
If(MarketPosition==1)
{
MaxProfit = HigherAfterEntry-AvgEntryPrice;
Commentary("MaxProfit="+Text(MaxProfit));
If(MaxProfit > 60*MinPoint)
{
StopLine = HigherAfterEntry-MaxProfit*0.4;
Commentary("启动二级跟踪");
}Else If(MaxProfit > 30*MinPoint)
{
StopLine = HigherAfterEntry-MaxProfit*0.5;
Commentary("启动一级跟踪");
}Else
{
StopLine = AvgEntryPrice - StopLoss*MinPoint;
Commentary("启动原始止损");
}
If(Low <= StopLine)
{
MyPrice = StopLine;
If(Open < MyPrice ) MyPrice = Open;
Sell(1,MyPrice);
Commentary("触发止损");
}
}else if(MarketPosition==-1)
{
MaxProfit = AvgEntryPrice-LowerAfterEntry;
Commentary("MaxProfit="+Text(MaxProfit));
If(MaxProfit > 60*MinPoint)
{
StopLine = LowerAfterEntry+MaxProfit*0.4;
Commentary("启动二级跟踪");
}Else If(MaxProfit > 30*MinPoint)
{
StopLine = LowerAfterEntry+MaxProfit*0.5;
Commentary("启动一级跟踪");
}Else
{
StopLine = AvgEntryPrice + StopLoss*MinPoint;
Commentary("启动原始止损");
}
If(High >= StopLine)
{
MyPrice = StopLine;
If(Open > MyPrice ) MyPrice = Open;
BuyToCover(1,MyPrice);
Commentary("触发止损");
}
} 楼主的R是指什么??? R是风险值。
可以通过设置全局变量来实现这一部分吗?
If(MarketPosition==1)
{
MaxProfit = HigherAfterEntry-AvgEntryPrice;
Commentary("MaxProfit="+Text(MaxProfit));
If(MaxProfit > 60*MinPoint)
{
StopLine = HigherAfterEntry-MaxProfit*0.4;
Commentary("启动二级跟踪");
}Else If(MaxProfit > 30*MinPoint)
{
StopLine = HigherAfterEntry-MaxProfit*0.5;
Commentary("启动一级跟踪");
}Else
{
StopLine = AvgEntryPrice - StopLoss*MinPoint;
Commentary("启动原始止损");
}
If(Low <= StopLine)
{
MyPrice = StopLine;
If(Open < MyPrice ) MyPrice = Open;
Sell(1,MyPrice);
Commentary("触发止损");
} 只要前面达到一次我就必须采用一种策略出场。至于是不是一定出场那要看策略来说。这里的逻辑关系有点模糊
回复 #4 thjyqr 的帖子
这里是用序列变量啊。没有全局变量 谢谢NOPAIN的细心解答。但是我想这有必要设置两个变量吗?用SetGlobalVar(HIGH,BarsSinceEntry),SetGlobalVar(LOW,BarsSinceEntry就搞定了这样有什么不妥吗?我是一手一手交易的。交易频繁。
回复 #7 thjyqr 的帖子
你这写的什么,看不懂? 我写错了,是这样写的。SetGlobalVar(0,highest(HIGH,BarsSinceEntry)),SetGlobalVar(1,lowest(LOW,BarsSinceEntry))
回复 #9 thjyqr 的帖子
1、这样运算慢2、这样最后一个Bar的High/Low 也算进去了。 多级跟踪止损 good!!!!!!!!! 尽量不要在不是非常必要的时候用全局变量。
一般的用序列完全能解决问题了。
全局会弄的很乱。逻辑不清楚。
如何在历史测试中在一分钟线天的最高价啊
如何在历史测试中在一分钟线上调用任何前面任何一天的最高价啊 highD() 只要1分钟K线数据足够多 If(BarsSinceEntry == 1){
HigherAfterEntry = AvgEntryPrice;
LowerAfterEntry = HigherAfterEntry;
}Else If(BarsSinceEntry > 1)
{
HigherAfterEntry = max(HigherAfterEntry[1],High[1]);
LowerAfterEntry = min(LowerAfterEntry[1],Low[1]);
}
如果是日内交易的话,这里的High[1]是指开仓BAR以后的high[1]还是从开盘以后的第一根BAR算起至当前BAR当中的最高? High[1]是指图表上前一个bar的最高价
回复 3# 高架桥 的帖子
If(MarketPosition==1){
MaxProfit = HigherAfterEntry-AvgEntryPrice;
Commentary("MaxProfit="+Text(MaxProfit));
If(MaxProfit > 60*MinPoint)问题1::这里是指盈利有60个点吗?
{
StopLine = HigherAfterEntry-MaxProfit*0.4;问题2:这里是最高价回撤40%吗?需要计算各个品种吗?
Commentary("启动二级跟踪");
} }Else
{
StopLine = AvgEntryPrice - StopLoss*MinPoint;问题3:StopLoss这里指什么意思?
Commentary("启动原始止损");
}
请回答,谢谢! 1.是的
2.是的,不是各个计算的
3.设置的止损的点数 这个跟踪系统牛!
先收集,等有空好好琢磨下。 一级跟踪,二级跟踪,人间大炮发射!
页:
[1]
2
