以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  公式模型编写问题提交  (http://weistock.com/bbs/list.asp?boardid=4)
----  哪位高人帮忙看一下吧  (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=54370)

--  作者:武松88890
--  发布时间:2013/7/28 13:01:09
--  哪位高人帮忙看一下吧

//定义n日平仓;
input:n(3,3,20,1);
//定义单日上涨或下跌百分比;
input:m(3,3,20,0.5);
input:posNum(1,1,20,1);
//变量定义
VARIABLE:position:=0;//仓位状态,0表示没有持仓,1表示多头,-1表示空头
variable:barCount:=0;//记录信号出现日是第几根bar;
variable:lClosePrice:=0;//记录信号出来前一日收盘价;
variable:closePrice:=0;//记录信号出来当日收盘价;
llastC:=ref(close,2);//前日收盘价;
lastC:ref(close,1);//昨日收盘价;
myExitPrice:=0;


//如果当前没有持仓
if(position=0)  then  begin
 //多头进场条件
   long :=((lastC-llastC)/llastC)>0.03;
   l0:(lastC-llastC)/llastC,linethick0;
   //多头进场
   if long=1  then begin
       myEntryPrice:=if(OPEN>lastC+MINDIFF,open,lastC+MINDIFF);//判断跳空情况
       buy(1,posNum,LIMITR,myEntryPrice);
       position:=1;
       barCount:=BARPOS-1;
       lClosePrice:=llastC;//开仓时候记录开仓前日收盘价;
       closePrice:=lastC;
   end
end
 p1:position,linethick0;
 b:barCount,linethick0;
//有多头仓位的情况,3种情况,止损平仓,定时平仓,持有后移动止损获利平仓;
if  position=1  then  BEGIN 
   //止损平仓
   longX1:=low<(closePrice-(closePrice-lClosePrice)*0.65);//价格跌破信号出来时那一天长阳线的65%;
   l123:closePrice-(closePrice-lClosePrice)*0.65,linethick0;
   if(longX1=1)then  BEGIN    //无论如何,会进入,不知为何??????????????
  myExitPrice:=if(open<closePrice-(closePrice-lClosePrice)*0.65,open,closePrice-(closePrice-lClosePrice)*0.65);
  exitP:myExitPrice;
  myExitPrice:=floor(myExitPrice/MINDIFF)*MINDIFF;  //对齐到最小变动价位;
  sell(1,0,limitr,myExitPrice);//作为例子,使用限价指令,在图上标出;可以使用市价指令;
  position:=0;
   end

   //定时平仓
  { longX2:=low<(myEntryPrice-2*N);//myEntryPrice,不是局部变量吗
 if(longX2  and position=1)then  BEGIN
  myExitPrice:=if(open<myEntryPrice-2*N,open,myEntryPrice-2*N);
  myExitPrice:=floor(myExitPrice/MINDIFF)*MINDIFF;  //对齐到最小变动价位;
  sell(1,0,limitr,myExitPrice);//作为例子,使用限价指令,在图上标出;可以使用市价指令;
  position:=0;
  totolUnits:=0;
 end}
end
 p2:position,linethick0;

 

 

下面那段平仓的代码,怎么无论如何都会进入?


--  作者:武松88890
--  发布时间:2013/7/28 14:58:28
--  

还有,怎么公式调试器不好用啊,好奇怪,是因为免费版吗


--  作者:jinzhe
--  发布时间:2013/7/29 9:08:09
--  

longX2  and position=1

这个平仓条件满足后才能平仓,使用shift+q的调试功能,进行调试,查看结果是否符合预期