趋势线教学视频划线
我从官网教学视频上抄了个趋势线划线指标,代码一模一样,为啥显示划线不一样,哪位老师帮忙看一下
我从官网教学视频上抄了个趋势线划线指标,代码一模一样,为啥显示划线不一样,哪位老师帮忙看一下
回复:Vars Series<Numeric> FstBotIndex; //第一个底的最低价 Series<Numeric> SecBotIndex; //第二个底的最低价 Series<Numeric> Bottom1; Series<Numeric> Bottom2; Series<Numeric> TrendLine; //趋势线的值 Numeric i; Series<Numeric> LowAfterEntry; //持仓后盈利峰值价 Series<Numeric> StopPrice; //止损价 Series<Numeric> BarsSinceLAE; //上个持仓盈利峰值到现在的BAR数虽然不知道你怎么抄的变量定义的内容换一下,变量类型看上去不对然后2个底的参数要设
很早的视频,代码可能有点老你写成什么样了可以贴一下
回复:不是我写的,是我看视频学习时抄的老师的课件,练练手。 Params Numeric Bot1_Index(0); //第一个底的CurrentBar Numeric Bot2_Index(0); //第二个底的CurrentBar Numeric StopLoss(300); //保护性止损比例万分之N; Numeric TrailStop(300); //跟踪止盈比例万分之N Numeric Lots(0); //交易手数 Vars Numeric FstBotIndex; //第一个底的最低价 Numeric SecBotIndex; //第二个底的最低价 Numeric Bottom1; Numeric Bottom2; Series<Numeric> TrendLine; //趋势线的值 Numeric i; Series<Numeric> LowAfterEntry; //持仓后盈利峰值价 Numeric StopPrice; //止损价 Numeric BarsSinceLAE; //上个持仓盈利峰值到现在的BAR数 Begin Commentary("CurrentBar ="+Text(CurrentBar)); //第一根BAR把两个底的位置从参数中读取 If(CurrentBar == 0) { FstBotIndex = Bot1_Index; SecBotIndex = Bot2_Index; } //如果没有指定两个底的位置,则返回 If(FstBotIndex == 0 Or SecBotIndex == 0) { Return; } //第一个底,最低价保存到序列变量,画它的趋势线 If(CurrentBar == FstBotIndex) { Bottom1 = L; //TrendLine = Bottom1; //PlotNumeric("TrendLine",TrendLine), } //第二个底,最低价保存到序列变量,画自第一个底以来的趋势线 If(CurrentBar == SecBotindex) { Bottom2 = L; For i = 0 To SecBotindex-FstBotIndex-1 { TrendLine = Bottom1 + i*Round((Bottom2-Bottom1)/(SecBotindex-FstBotindex),2); //Unplot("TrendLine" SecBotindex-FstBotindex-i); PlotNumeric("TrendLine",TrendLine,0,-1,SecBotindex-FstBotIndex-i); } } //画自第二个底以来的趋势线,显示趋势线的斜率 If(CurrentBar >= SecBotIndex) { TrendLine = Bottom2+(CurrentBar-SecBotindex)* Round((Bottom2-Bottom1)/(SecBotindex-FstBotIndex),2); PlotNumeric("TrendLine",TrendLine); Commentary("斜率="+Text(Round((Bottom2-Bottom1)*100/((SecBotIndex-FstBotindex)*Bottom1),2))); } //进场收盘跌破趋势做空 If(MarketPosition == 0 And CurrentBar >= SecBotindex And Close[1] < TrendLine[1] And Open < TrendLine) { SellShort(Lots,Open); } //记录盈利峰值 If(MarketPosition == -1 And BarsSinceEntry == 0) { LowAfterEntry = Low; BarsSinceLAE = 0; } Else If(MarketPosition == -1 And BarsSinceEntry > 0) { If(Low <= LowAfterEntry[1]) { LowAfterEntry = Low; BarsSinceLAE = 0; } Else BarsSinceLAE = BarsSinceLAE + 1; } //收回趋势线上止损 If(MarketPosition == -1 And Close[1] > TrendLine[1] And Open > TrendLine) { BuyToCover(0,Open); Commentary("收回趋势线上止损"); } //跟踪止盈(止盈时必需是盈利) If(MarketPosition == -1 And BarsSinceEntry > 0 And H >= LowAfterEntry[1]*(1+TrailStop/10000)) { StopPrice = Max(Open,LowAfterEntry[1]*(1+TrailStop/10000)); If(StopPrice < EntryPrice) { BuyToCover(0,StopPrice); Commentary("跟踪止盈"); } } //保护性止损 StopPrice = EntryPrice*(1+StopLoss/10000); If(MarketPosition == -1 And BarsSinceEntry > 0 And H >= StopPrice) { BuyToCover(0,Open); Commentary("保护性止损"); } //出场后调整趋势线第二个底 If(MarketPosition == 0 And BarsSinceExit == 0 And TotalTrades > 0) { //第二个底必须高于第一个底 If(LowAfterEntry > Bottom1) { SecBotIndex = CurrentBar - BarsSinceLAE; Bottom2 = LowAfterEntry; } Else //否则,之后不交易 { FstBotIndex = 0; SecBotIndex = 0; } } Commentary("BarsSinceLAE = "+Text(BarsSinceLAE)); End