等级: 免费版
- 注册:
- 2021-5-20
- 曾用名:
|
如题:1、VBA
sub PKTrade
'call Application.ActiveFrame("fraTest")
sAccount=order.Account(1)
iCount=fraTest.GridCount '获取框架fraTest有几个窗格
for i=0 to iCount-1 '逐个读取窗格上的合约及公式输出
Set Grid=fraTest.GetGridByName("w" &i+1)'"w" &i+1
Set Rep=Grid.GetReportData() '获取窗格上的合约
sCode=Rep.Label '合约编码
sMarket=Rep.MarketName '市场编码
nLastPrice=rep.NewPrice '获取最新价
iFormulaCount=Grid.FormulaCount '获取窗格上的公式个数
for j=0 to iFormulaCount-1 '逐个公式读取,判断是不是你用于交易的策略,是的话,就读取该公式的输出
Set Formula=Grid.GetFormulaByIndex(j) '这个关键的地方,获取Grid上的公式,得到公式对象
if Formula.Name<>"MAIN" then '一般不是MAIN,就是自己的策略,如果有多个策略加载在图表上,最好只保留一个
iBar=round(Formula.GetBufData("iBar",Formula.DataSize-1),0) '读取策略的变量输出iBar
iBP1Flag=Formula.GetBufData("BP1",Formula.DataSize-1) '读取策略的变量输出BP1Flag
iBK1Flag=Formula.GetBufData("BK1",Formula.DataSize-1) '读取策略的变量输出BP1Flag
immHoldingFlag=Formula.GetBufData("mmHolding",Formula.DataSize-1) '读取策略的变量输出BP1Flag
imOFlag=Formula.GetBufData("mO",Formula.DataSize-1) '读取策略的变量输出BP1Flag
it0Flag=Formula.GetBufData("t0",Formula.DataSize-1) '读取策略的变量输出BP1Flag
'你自己的交易代码段,我就不写了,也无法写,每个人的想法都不一样
if iBP1Flag=1 and it0Flag=1 then
nPrice=0
iOrdVol=immHoldingFlag
call PingDuoDan(nPrice,sCode,sMarket,iOrdVol,sAccount)
end if
if iBK1Flag=1 and it0Flag=0 then
nPrice=imOFlag
iOrdVol=immHoldingFlag
call KaiDuoDan(nPrice,sCode,sMarket,iOrdVol,sAccount)
end if
end if
next
next
End sub
Sub KaiDuoDan(nPrice,sCode,sMarket,iOrdVol,sAccount) '开多单,nPrice=0时为市价,否则就是传递过来的价
'application.MsgOut "iOrdVol:" & iOrdVol & "," & sCode & "," & sMarket & "," & sAccount & "," & nPrice
If iOrdVol>0 then
If nPrice=0 then
'application.MsgOut "sCode,sMarket,AccountID:" & sCode & "," & sMarket & "," & AccountID
Call Order.Buy(1,iOrdVol,0,0,sCode,sMarket,sAccount,0) '市价开多单
Else
Call Order.Buy(0,iOrdVol,nPrice,0,sCode,sMarket,sAccount,0) '限价开多单
End If
End If
End Sub
2、pel公式加载在等价K框架之上
VARIABLE:t1=0;
qj:=open*bill/10; //----------bill/10表示幅度//-------------------------线下代码减少运行,释放资源-------------------
abb:=time0-timetot0(dynainfo(207)),nodraw;//K线结束倒计时间(秒)
t:=timetot0(time0)-timetot0(dynainfo(207)),nodraw;//当前时间结束倒计时
akk:=(timetot0(dynainfo(207))-ref(time0,1)),LINETHICK0;//k线的最开始的时间(秒)
//akk:=(timetot0(dynainfo(217))-timetot0(dynainfo(207)));//k线的最开始的时间(秒)
cd0:=not(ISLASTBAR);
cd1:=islastbar and abb>=0 and abb<=2;
cd2:=islastbar and akk>=0 and akk<=2;
cd3:=islastbar and abb>=0 and abb<=59;
cd4:=islastbar and akk>=0 and akk<=59;
if abs(close-open)>qj&&cd1 then T1:=1;
if t1=1&&cd2 then T1:=0;
T0:t1,NODRAW;
buy0:if(C>O&&T1=1,1,0);//等价K成立且时间恰为周期的最后1秒:卖
BP0:if(C<O&&cd2&&T1=0,1,0);//等价K开始且时间恰为周期的第1秒内:买
|
|