图一调用图2的均线参数,但是无论图二是5分钟 30分钟 还是日线,图一的交易都从8月22号开始,,,很奇怪
代码如下
Params
Numeric FastLen(28); // 分钟线
Numeric SlowLen(30); //分钟
Numeric NomLen(10); //日线
Numeric Ch(30); // 通道200根K线
Numeric Length(10); //用于计算ATR和新高价的Bar数
Numeric StopLength(50);
Numeric StopSLength(30);
Numeric ReBars(200);
Numeric dh(500);
Numeric TrailingStart1(30); // 声明变量TrailingStart1,初始值为50,这是止盈启动设置1。
Numeric TrailingStart2(50); // 声明变量TrailingStart2,初始值为80,这是止盈启动设置2。
Numeric TrailingStart3(300);
Numeric TrailingStop1(1); // 声明变量TrailingStop1,初始值为30,这是真正跟踪止盈设置1。
Numeric TrailingStop2(5); // 声明变量TrailingStop2,初始值为20,这是真正跟踪止盈设置2。
Numeric TrailingStop3(15);
Vars
Numeric MinPoint(0); // 声明变量MinPoint,一个最小变动单位,也就是一跳。
Numeric MyEntryPrice(0); // 声明变量MyEntryPrice,英文好的,看英文意思都知道的,开仓价格,本例是开仓均价,也可根据需要设置为某次入场的价格。
Series<Numeric> FastMA; // 快速均线
Series<Numeric> SlowMA; // 慢速均线
Numeric NomMA;
Series<Numeric> ReEntryCount; // 跟踪止损后记录BAR序号
Numeric MyExitPrice; // 声明变量MyExitPrice,平仓价格。
Series<Numeric> ATR;
Series<Numeric> StopPri; //跟踪止损价
Series<Numeric> StopSPri;
Series<Numeric> stopwin;
Series<Numeric> HighValue; //多头进场之后的盈利峰值价
Series<Numeric> AF; //跟踪Acceleration
Series<Numeric> HighestAfterEntry; //声明序列变量HighestAfterEntry,开仓后出现的最高价。
Series<Numeric> LowestAfterEntry; //声明序列变量LowestAfterEntry,开仓后出现的最低价。
Numeric StopPrice(0);
Series<Bool> Condition1(False);
series<Bool> Yun(False);
Numeric StopATR;
Numeric HH; // 最近N根BAR的高点
Numeric LL;
Numeric PP; // 最近N根BAR的低
Numeric Bigbar;
Series<Numeric> CCC;
Series<Numeric> PPP;
Series<Numeric> LLD;
Series<Numeric> HHD;
Series<Bool>HD;
Series<Bool>LD;
Series<Bool> Yang; //锤子线阳
Series<Bool> yin;// 吊头线阴
// Series<Bool> Condition1; // 条件1
// Series<Bool> Condition2; // 条件2
Numeric MyRange; //K线幅度
Events
OnBarclose(ArrayRef<Integer> indexs)
{ Range[1:1]
{LL = Lowest(Low[1],Ch);
data0.Yun= (High[1]<=High[2] and low[1]>=low[2]);
data0.NomMA = Average(Close, NomLen);
}
range[0:0]
{HD=High>=Highest(high[1],dh);
LD=LOW<=Lowest(Low[1],dh);
Commentary(\"CCC=\"+Text(CCC));
// Commentary(\"LL=\"+Text(LL));
Commentary(\"ReEntryCount=\"+Text(ReEntryCount));
FastMA = Average(Close, FastLen);
SlowMA = Average(Close,SlowLen);
PlotNumeric(\"FastMA\",FastMA);
PlotNumeric(\"SlowMA\",SlowMA);
PlotNumeric(\"NomMA\",NomMA);
StopPri=EntryPrice+StopLength*MinMove*PriceScale;
StopSPri=EntryPrice+StopSLength*MinMove*PriceScale;
stopwin=EntryPrice- StopLength*MinMove*PriceScale;
MyRange = High - Low; //K线幅度
Yang=(open-Low)>=(close-open) and Close>=open;
yin=(high-open)>=(open-close) And open>=Close;
// K线形态判断的2个条件
// Condition1 = Close <= Low + 0.25 * MyRange; //实体较大阴线
//Condition2 = Close >= High - 0.25 * MyRange; //实体较大阳线
// 触发止损
LL = Lowest(Low[1],Ch);
HH = Highest(High[1],Ch);}
Range[0:0]
{ // 触发止损
If(MarketPosition == -1 And Vol > 0 )
{
If(high >=StopSPri and BarsSinceentry >= 5) //止损
{
BuyToCover(0,StopSPri);
ReEntryCount = CurrentBar;
}
IF( Close >= NomMA AND BarsSinceentry >= 5)
{
BuyToCover(0, Close);
ReEntryCount = CurrentBar;
}
if (high >=StopPri And BarsSinceentry >= 5)
{BuyToCover(0,StopPri);
ReEntryCount = CurrentBar;}
// If(Close<=SlowMA)
// {return;}
}
If(BarsSinceentry == 0 )//获得当前持仓的第一个建仓位置到当前位置的Bar计数,这里就是开仓的那根k线了。
{
HighestAfterEntry = Close;//开仓后的最高价为收盘价。
LowestAfterEntry = Close;//开仓后的最低价为收盘价。
If(MarketPosition <> 0)//假如有持仓的情况下。
{
HighestAfterEntry = Max(HighestAfterEntry,AvgEntryPrice); // 开仓的Bar(通常说的k线了),将开仓价和当时的收盘价的较大值保留到HighestAfterEntry。
LowestAfterEntry = Min(LowestAfterEntry,AvgEntryPrice); // 开仓的Bar,将开仓价和当时的收盘价的较小值保留到LowestAfterEntry。
}
}
else//这个对应着不是开仓k线之后的情况。
{
HighestAfterEntry = Max(HighestAfterEntry,High); // 这个是逐个判断的,即开仓那条K线,跟下一根k线最高价对比,记录当前的最高点;再接着继续对比,直到符合止盈启动设置条件,这样好用于下一个Bar的跟踪止盈判断。
LowestAfterEntry = Min(LowestAfterEntry,Low); // 简略说就是,记录下当前k线的最低点,用于下一个K线的跟踪止盈判断。
}
Commentary(\"HighestAfterEntry=\"+Text(HighestAfterEntry));//在超级图表当前Bar添加一行注释信息,解读意思就是在K线图上显示最高价HighestAfterEntry等于多少的。
Commentary(\"LowestAfterEntry=\"+Text(LowestAfterEntry));//解读同上,显示最低价。
MinPoint = MinMove*PriceScale;//固定的最小跳动价公式。
MyEntryPrice = AvgEntryPrice;//把开仓均价赋值给MyEntryPrice。
if(MarketPosition==-1 And Vol > 0 ) // 有空仓的情况
{
If(LowestAfterEntry[1] <= MyEntryPrice - TrailingStart2*MinPoint) // // 启动二级止盈,即最低价小于等于开仓价减去止盈启动设置2乘以最小跳动价。
{
If(High >= MyEntryPrice - TrailingStop2*MinPoint)//假如高价大于等于最低价加上真正止盈设置2乘以最小跳动价。
{
MyExitPrice = MyEntryPrice - TrailingStop2*MinPoint;
BuyToCover(0,MyExitPrice);//平仓。
}
}
else if(LowestAfterEntry[1] <= MyEntryPrice - TrailingStart1*MinPoint)// 第一级跟踪止盈的条件表达式,基本就是把止盈设置2都改成设置了,解读同上了。
{
If(High >= MyEntryPrice - TrailingStop1*MinPoint)//解读同上。
{
MyExitPrice = MyEntryPrice - TrailingStop1*MinPoint;
BuyToCover(0, MyExitPrice);//平仓。
}
}
}
你看一下的指标计算周期,没达到计算周期自然是没有
比如60天均线,没到60天的情况那就不会有60天均线
1分钟的20线 当天就可以完成了吧 但是实际中不管是图层是1分5分还是30分钟K线,都要20天以后出现信号