以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://www.weistock.com/bbs/index.asp)
--  金字塔软件问题提交  (http://www.weistock.com/bbs/list.asp?boardid=2)
----  止损和移动止盈  (http://www.weistock.com/bbs/dispbbs.asp?boardid=2&id=161349)

--  作者:wei0619789
--  发布时间:2018/1/29 15:42:35
--  止损和移动止盈
请老师编写一个策略:用趋势线和EXPMA交叉来完成开仓 平仓 反手交易的策略,趋势线要可以动态调整,但不影响交叉的自动交易,EXPMA的周期和交易手数要可以更改。谢谢
--  作者:gxx978
--  发布时间:2018/1/30 9:46:51
--  

实现功能:

1、ema均线上破水平线即平空开多,下破水平线即平多开空。

2、开仓后,如果亏损,且亏损n1个点即进行止损平仓。

3、开仓后,如果盈利,且盈利最大超过n2个点位,并回落n3个点即进行平仓,并反手开仓。

 

 

 

本策略仅供参考,切勿直接用于实盘。

variable:maxprofit=0;              //记录仓位的最大获利
input:A(3800,1,100000,100);  //定义的水平线
input:ss(1,1,50,1);                 //手数
input:p1(5,1,100,1);              //均线变量
input:n1(10,1,100,1);            //止损点位
input:n2(100,10,1000,1);       //止盈点位
input:n3(25,10,1000,1);         //回调点位

 

m1:ema(close,p1);
conpkkd:=cross(m1,A);
conpdkk:=cross(A,m1);

 

if conpkkd then                    //平空开多
  begin
  sellshort(holding<0,holding,market);
  buy(holding=0,ss,market);
  maxprofit:=0;
  end
 
if conpdkk then                  //平多开空
   begin
   sell(holding>0,holding,market);
   buyshort(holding=0,ss,market);
   maxprofit:=0;
   end
  
if holding>0 and enterprice-low>n1   then sell(1,holding,market);          //多头止损
if holding<0 and high-enterprice>n1  then sellshort(1,holding,market);  //空头止损

 

win:=0;    //最大盈利变量
win2:=0;    //最大回调变量
if holding>0 then
  begin
  win:=high-enterprice;      //记录多头最大盈利
  if win>maxprofit then maxprofit:=win;
  win2:=maxprofit-win;     //记录多头最大盈利后的回调
  end

 

if holding<0 then
   begin
   win:=enterprice-low;//记录空头最大盈利
   if win>maxprofit then maxprofit:=win;
   win2:=maxprofit-win;   //记录空头最大盈利后的回调
   end
  
if holding>0 and maxprofit>=n1 and win2>=n2 then    //多头止盈,并反手开空
   begin
   sell(1,holding,market);
   buyshort(1,ss,market);
   end
  
if holding<0 and maxprofit>=n1 and win2>=n2 then     //空头止盈,并反手开多
   begin
   sellshort(1,holding,market);
   buy(1,ss,market);
   end

 

line1:A,linethick2,colorwhite;    //水平线
line2:enterprice-n1*mindiff,linethick2,colorgreen;         //止损线
line3:enterprice+n2*mindiff,linethick2,colorred;           //止盈线
line4:enterprice+(n2-n3)*mindiff,linethick2,coloryellow;   //止盈回落线

[此贴子已经被作者于2018/2/1 14:59:28编辑过]

--  作者:wei0619789
--  发布时间:2019/5/29 17:03:59
--  
老师好,这个程序好像不对,说 语句未尾缺少分号,还有就是这个水平线能不能可以是趋势线的形式,在行情页面上可以用划线形式去设置,方便我去设置,谢谢
--  作者:banzhuan
--  发布时间:2019/5/29 17:21:40
--  
1、您是复制完整的代码吗?本地核实了没有缺分号的情况;
2、是这4条水平线吗? 除了第一根水平线是固定值,后面3根都是根据上次开仓价计算得出,直接修改这边的参数即可
line1:A,linethick2,colorwhite;    //水平线
line2:enterprice-n1*mindiff,linethick2,colorgreen;         //止损线
line3:enterprice+n2*mindiff,linethick2,colorred;           //止盈线
line4:enterprice+(n2-n3)*mindiff,linethick2,coloryellow;   //止盈回落线