怎样根据前一笔交易的状态控制下一笔交易?

Discussion in 'AmiBroker' started by rypan, Dec 27, 2010.

  1. 日内系统,当在某个品种上有一笔交易进行过开仓平仓后,就不对该品种继续交易。

    该怎么写?
     
  2. 设置一个“标志”变量不就可以了,比如未开仓/平仓,sign=0,执行后sign=1。
     
  3. 楼主太夸张啦

    这是最基本的编程技术呀
     
  4. 我想直接用BarSince(buy),取得上一根开仓的bar。

    可是在buy赋值前使用,会报告没有初始化。在buy赋值后使用,又不能控制交易。就是一个死循环。
     
  5. 如果是普通的过程式编程语言,当然没问题。

    可是数组式语言,很不习惯。
     
  6. StaticVarSet/Get行吗?
     
  7. 我的想法是在所有符合条件的bar上做标记。

    可是在当前Bar被设置标记后,就无法找到上一个被设置标记的bar了。
     
  8. HIGHESTSINCEBARS

    Returns the number of bars that have passed since highest ARRAY value since EXPRESSION was true on the Nth most recent occurrence.

    这是哪国的英语啊?我怎么看得那么晕。
     
  9. 貌似作者是波兰裔...是不是因为这段解说太拗口,导致连一个用到它的示例都没有。
     
  10. 我吧,我承认我比较笨。简单的方法我是搞不定了,只能兜个大圈了。

    Code:
    SetOption("InitialEquity", 10000000);
    
    buyCond = c > ref(c, -1);
    sellCond = c < ref(c, -1);
    
    buy = buyCond;
    sell = sellCond;
    cover = short = false; 
    dn = dateNum();
    
    SetOption("UseCustomBacktestProc", True ); 
    if(status("action") == actionPortfolio){   
    	bo = GetBacktesterObject(); 
    
    	bo.PreProcess(); 
    	lastEntryDate = 0;
    	for(bar = 0; bar < barCount; bar++)
    	{ 		
    		for (sig = bo.GetFirstSignal(bar); sig; sig = bo.GetNextSignal(bar))
    		{
    			if(sig.IsEntry())
    			{
    				if(dn[bar] == lastEntryDate)
    					sig.PosSize = 0;
    				else
    					lastEntryDate = dn[bar];
    			}
    		}
    		bo.ProcessTradeSignals(bar);
    	}
    	bo.PostProcess(); 
    }
    
     
  11. 用静态变量解决
     
  12. 也许用exrem就可以解决吧。
    buy = exrem(buy, 是否换日)
    short = exrem(short,是否换日)
     
  13. 上面的似乎无法在开平过多仓后,禁止开空仓。

    也许改成这样能好点?
    buyshort = exrem(buy or short, 是否换日)
    buy = buyshort and buy;
    short = buyshort and short;
     
  14. How about block the trades on the rest of the day if make 10 points of profit for example?