以下示例为图表程序化交易,推荐您先从图表开始做起
【金字塔使用技巧】----目标:当日亏损交易次数超过3次,则不再开仓如何写?----图表交易 新交易函数
variable:lossnum=0;// 全局变量,平仓时判断一下是盈利/亏损,若亏损lossnum就加1
if cond1 and holding>0 then
begin
sell(1,1,thisclose);
if c<enterprice then lossnum:=lossnum+1;
end
if cond2 and holding=0 and lossnum<3 then buy(1,1,thisclose);
if time= closetime(0) then lossnum:=0;// 商品期货,收盘的同时,lossnum赋值为0
//收盘lossnum不赋值为0,后面就不再开仓了
【金字塔使用技巧】----次交易日起卖出如何编写?
N分钟周期下,买入后,要求从次一个交易日起开始卖出(不能从下一根K线起),这个“次交易日起”条件如何实现?
variable:flag=0;// 全局变量,买开仓时赋值为1
if cond1 and holding=0 then
begin
buy(1,1,market);
flag:=1;
end
if cond2 and holding>0 and flag=0 then sell(1,1,thisclose);
if time=CLOSETIME(0) then flag:=0;//收盘的同时,flag赋值为0