公式:DIFF := EMA(CLOSE,12) - EMA(CLOSE,26);DEA := EMA(DIFF,9);
MACD1 := 2*(DIFF-DEA);
RSV:=(CLOSE-LLV(LOW,9))/(HHV(HIGH,9)-LLV(LOW,9))*100;
K:=SMA(RSV,3,1);
D:=SMA(K,3,1);
KDJbuyCOND:=count(cross(k,d),10)>=1;
MACDbuyCOND:=count(cross(DIFF,DEA),3)>=1 and MACD1>0;
KDJsellCOND:=count(cross(d,k),10)>=1;
MACDsellCOND:=count(cross(DEA,DIFF),3)>=1 and MACD1<0;
KaiDuoCond:KDJbuyCOND and MACDbuyCOND;
KaiKongCond:KDJsellCOND and MACDsellCOND;
macd30:=MACD1;
macd30b:=REF(macd30,1);
macd30b2:=REF(macd30,2);
PingDuoCond:macd30b>macd30 and macd30b2>macd30b;
PingKongCond:macd30b<macd30 and macd30b2<macd30b;
Sub MARKETDATA_ReportNotify(ReportData) '行情触发时的操作
NewPrice = ReportData.NewPrice
'application.MsgOut cdate(time) & (NewPrice>(TraderForm_adjustPrice.value-5) and
NewPrice<(TraderForm_adjustPrice.value+5))
NewBuyPrice=ReportData.BuyPrice1
NewSellPrice=ReportData.SellPrice1
'stkLable=ReportData.Label
Set Formula=marketdata.STKINDI(Tcode,Tmarket,"TradeCond",0,17)
KaiDuoCond=Formula.GetBufData("KaiDuoCond",Formula.DataSize-1)
PingDuoCond=Formula.GetBufData("PingDuoCond",Formula.DataSize-1)
KaiKongCond=Formula.GetBufData("KaiKongCond",Formula.DataSize-1)
PingKongCond=Formula.GetBufData("PingKongCond",Formula.DataSize-1)
application.MsgOut "KaiDuoCond:" &
KaiDuoCond
application.MsgOut "KaiKongCond:" & KaiKongCond
application.MsgOut "PingDuoCond:" & PingDuoCond
application.MsgOut "PingKongCond:" & PingKongCond
set Formula=nothing
后面还有一些代码,在此省略
End Sub
问题:打印的PingKongCond的值与公式在图表中显示的值不一样,比如,公式的值已经变成0,在VBA中打印的值还是1,为何呢?
是否是行情触发的时间间隔太短导致
MARKETDATA_ReportNotify事件中的代码未能执行到?
那,一般情况要达到在MARKETDATA_ReportNotify事件中的代码能确定完全地执行,该如何处理呢?
你贴的代码没写明PingKongCond这个变量你是如何取得的
Sub MARKETDATA_ReportNotify(ReportData) '行情触发时的操作
Set Formula=marketdata.STKINDI(Tcode,Tmarket,"TradeCond",0,17)
KaiDuoCond=Formula.GetBufData("KaiDuoCond",Formula.DataSize-1)
PingDuoCond=Formula.GetBufData("PingDuoCond",Formula.DataSize-1)
KaiKongCond=Formula.GetBufData("KaiKongCond",Formula.DataSize-1)
PingKongCond=Formula.GetBufData("PingKongCond",Formula.DataSize-1)
application.MsgOut "KaiDuoCond:" & KaiDuoCond
application.MsgOut "KaiKongCond:" & KaiKongCond
application.MsgOut "PingDuoCond:" & PingDuoCond
application.MsgOut "PingKongCond:" & PingKongCond
set Formula=nothing
后面还有一些代码,在此省略
End Sub
Tcode,Tmarket是已经赋值的全局变量。值可以取出来,只是不会同步,公式中的值已经变化好久了,可VBA中打印出来,且没变
你这么调用Set Formula=marketdata.STKINDI(Tcode,Tmarket,"TradeCond",0,17)
不能保证你的参数和数据和图表上是严格一致的,导致结果不同也算正常,你试试直接取图表上的Formula对象看看
Set Grid = Technic.GetGridByName("Main")
Set Formula = Grid.GetFormulaByIndex(1)
框架和窗口根据你自己的实际情况修改