以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  公式模型编写问题提交  (http://weistock.com/bbs/list.asp?boardid=4)
----  麻烦客服帮我把一个简单的均线模型改为金字塔的  (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=145084)

--  作者:sunywell
--  发布时间:2016/12/21 15:24:54
--  麻烦客服帮我把一个简单的均线模型改为金字塔的

麻烦客服帮我把一个简单的均线模型改为金字塔的

//------------------------------------------------------------------------
// 简称:DualMA
// 名称:双均线交易系统
// 类别: 交易指令
// 类型: 用户应用
//------------------------------------------------------------------------
Params
 Numeric FastLength(3);  //短周期
 Numeric SlowLength(10);  //长周期
  
 Numeric StopPoint(30);  //止损点
 Numeric WinPoint(100);   //止赢点
 
 Numeric FlostStopStartPoint(50);   //浮动止损启动条件
 Numeric FlostStopPoint(20);   //浮动止损点
 
 Numeric TradeUint(5); //每次交易手数
 
Vars
 NumericSeries AvgValue1;
 NumericSeries AvgValue2;
 BoolSeries bCrossOver(false);
 BoolSeries bCrossDn(False);
Begin
 AvgValue1 = AverageFC(CLOSE,FastLength);
 AvgValue2 = AverageFC(CLOSE,SlowLength);
 PlotNumeric("MA1",AvgValue1);
 PlotNumeric("MA2",AvgValue2);
 
 
  
 bCrossOver = CrossOver(AvgValue1,AvgValue2);
 bCrossDn   = CrossUnder(AvgValue1,AvgValue2);
 
 //均线交叉时开仓
 if(bCrossOver[1])
 {
  if(MarketPosition != 1)
   Buy(TradeUint,Open);
  
 }
 Else if(bCrossDn[1])
 {
  if(MarketPosition != -1)
   SellShort(TradeUint,Open);
 }
 
 //止盈止损
 SetWinPoint(WinPoint);
 //止损点
 SetStopPoint(StopPoint);
 //浮动止损
 SetFloatStopPoint(FlostStopStartPoint,FlostStopPoint);
 
 PlotNumeric("Assets",Available+PositionProfit+Margin);
 SetOwnAxis("Assets");
End


--  作者:jinzhe
--  发布时间:2016/12/21 15:29:32
--  
麻烦每句话都注释一下
--  作者:sunywell
--  发布时间:2016/12/21 15:55:45
--  

麻烦客服帮我把一个简单的均线模型改为金字塔的

//------------------------------------------------------------------------
// 简称:DualMA
// 名称:双均线交易系统
// 类别: 交易指令
// 类型: 用户应用
//------------------------------------------------------------------------
Params //参数
Numeric FastLength(3); //短周期
Numeric SlowLength(10); //长周期

Numeric StopPoint(30); //止损点
Numeric WinPoint(100); //止赢点

Numeric FlostStopStartPoint(50); //浮动止损启动条件
Numeric FlostStopPoint(20); //浮动止损点

Numeric TradeUint(5); //每次交易手数

Vars 变量
NumericSeries AvgValue1; 平均线
NumericSeries AvgValue2;平均线
BoolSeries bCrossOver(false);是否上穿
BoolSeries bCrossDn(False);是否下穿
Begin开始
AvgValue1 = AverageFC(CLOSE,FastLength);
AvgValue2 = AverageFC(CLOSE,SlowLength);
PlotNumeric("MA1",AvgValue1);
PlotNumeric("MA2",AvgValue2);绘制均线



bCrossOver = CrossOver(AvgValue1,AvgValue2);判断是否上穿
bCrossDn = CrossUnder(AvgValue1,AvgValue2);判断是否下穿

//均线交叉时开仓
if(bCrossOver[1])
{
if(MarketPosition != 1)
Buy(TradeUint,Open);上穿买入开仓

}
Else if(bCrossDn[1])
{
if(MarketPosition != -1)
SellShort(TradeUint,Open);下穿卖出开仓
}

//止盈止损
SetWinPoint(WinPoint);达到止盈点平仓
//止损点
SetStopPoint(StopPoint);达到止损点平仓
//浮动止损
SetFloatStopPoint(FlostStopStartPoint,FlostStopPoint);达到浮动止损平仓

PlotNumeric("Assets",Available+PositionProfit+Margin);
SetOwnAxis("Assets");
End


--  作者:sunywell
--  发布时间:2016/12/21 16:03:55
--  
PlotNumeric("Assets",Available+PositionProfit+Margin);
SetOwnAxis("Assets");绘制资产曲线
--  作者:jinzhe
--  发布时间:2016/12/21 16:04:51
--  

//Numeric FastLength(3); //短周期
//Numeric SlowLength(10); //长周期
fastlength:=3;
slowlength:=10;
//Numeric StopPoint(30); //止损点
//Numeric WinPoint(100); //止赢点
stoppoint:=30;
winpoint:=100;
//Numeric FlostStopStartPoint(50); //浮动止损启动条件
//Numeric FlostStopPoint(20); //浮动止损点
floststopstartpoint:=50;
floststoppoint:=20;

//Numeric TradeUint(5); //每次交易手数
tradernint:=5;
//Vars 变量
//NumericSeries AvgValue1; 平均线
//NumericSeries AvgValue2;平均线
//BoolSeries bCrossOver(false);是否上穿
//BoolSeries bCrossDn(False);是否下穿
//Begin开始
AvgValue1:  ma(CLOSE,FastLength),linethick3;
AvgValue2:  ma(CLOSE,SlowLength),linethick3;
//PlotNumeric("MA1",AvgValue1);
//PlotNumeric("MA2",AvgValue2);绘制均线
bCrossOver: = Cross(AvgValue1,AvgValue2);//判断是否上穿
bCrossDn: = Cross(AvgValue2,AvgValue1);//判断是否下穿

//均线交叉时开仓
//if(bCrossOver[1])
{
if(MarketPosition != 1)
Buy(TradeUint,Open);上穿买入开仓

}
//Else if(bCrossDn[1])
{
if(MarketPosition != -1)
SellShort(TradeUint,Open);下穿卖出开仓
}
if bcrossover then buy(holding=0,5,marketr);
if bcrossdn then buyshort(holding=0,5,marketr);

if c-enterprice>100 then sell(1,0,marketr);
if enterprice-c>100 then sellshort(1,0,marketr);

if enterprice-c>30 then sell(1,0,marketr);
if c-enterprice>30 then sellshort(1,0,marketr);

if hhv(h,enterbars+1)>enterprice+50 and c<hhv(h,enterbars+1)-20 then sell(1,0,marketr);
if llv(l,enterbars+1)<enterprice-50 and c>llv(l,enterbars+1)+20 then sellshort(1,0,marketr);

 


--  作者:sunywell
--  发布时间:2016/12/22 9:12:20
--  

均线交叉平仓同时反向开仓怎么写?


--  作者:jinzhe
--  发布时间:2016/12/22 9:18:19
--  

if bcrossover then buy(holding=0,5,marketr);
if bcrossdn then buyshort(holding=0,5,marketr);

改为:

 

if bcrossover then begin

   sellshort(1,0,marketr);

   buy(holding=0,5,marketr);

end
if bcrossdn then begin

   sell(1,0,marketr);

   buyshort(holding=0,5,marketr);

end