|
本帖最後由 GnuHomot 於 11-7-26 10:16 PM 編輯
小弟也是入門初學者,來拜碼頭。
參考ashell大的文章改了一下程式碼,利用paramtrigger()可以在參數界面用按按鈕的方式來測試下單大師是否有收到訊號。
原先ashell大沒有處理時間格式的問題,小弟用笨方法也有處理了。
但是我有發現這個地方有個問題,就算我送出"2011/7/26 下午 08:45:30"的字串,下單大師照樣可以收到訊號,但我懷疑其實它會沒作用???不曉得這點有沒有前輩試過了?
程式碼裡面的辨識碼我是用ABMTX,按鈕如果沒反應,最有可能就是這裡和下單大師那裡沒設定好。
- function newDateTimeStr()
- {
- newNowDateTime=Now(0);
- sYear=StrLeft(Now(1),4);
- //_TRACE("sYear: "+sYear);
- sDate=StrRight(Now(1),StrLen(Now(1))-5);
- //_TRACE("sDate: "+sDate);
- iMonth=StrToNum(sDate);
- if(iMonth<10)
- sMonth="0"+NumToStr(iMonth,1.0);
- else
- sMonth=NumToStr(iMonth,1.0);
- //_TRACE("sMonth: "+sMonth);
- if(iMonth<10)
- sDay=StrMid(sDate,2,2);
- else
- sDay=StrMid(sDate,3,2);
- iDay=StrToNum(sDay);
- if(iDay<10)
- sDay="0"+NumToStr(iDay,1.0);
- else
- sDay=NumToStr(iDay,1.0);
- //_TRACE("sDay: "+sDay);
-
- newNowDateTime=sYear+"/"+sMonth+"/"+sDay+" "+Now(4);
- //_TRACE("newNowDateTime: "+newNowDateTime);
- return newNowDateTime;
- }
- _SECTION_BEGIN("OrderMaster_Initialize");
- trigger=ParamTrigger("OrderMaster Initialize", "Initialize");
- if(trigger)
- {
- OMComAPI = CreateStaticObject("OMSignAPI.OMCOMAPI");
- NowPosition = OMComAPI.GetNowPosition("ABMTX");
- if(NowPosition>99990)
- NowPosition=0;
- OMactive=OMComAPI.IniDllAndPosition("ABMTX", NowPosition);
- _TRACE(WriteIf(OMactive, "Success Set: " +WriteVal(NowPosition,1.0), "fail"));
- }
- _SECTION_END();
- _SECTION_BEGIN("OrderMaster_BuyOrder");
- trigger=ParamTrigger("OrderMaster Buy Order", "Buy");
- if(trigger)
- {
- TimeFormat=1;
- //TimeFormat==0; Format like this: 2011/7/1 13:40:45
- NowDateTime=Now(0);//before using, change OS system datetime format first.
- //TimeFormat==1;//Format like this: 2011/7/1 XXXX 01:40:45
- if(TimeFormat==1)
- NowDateTime=newDateTimeStr();
- OMComAPI = CreateStaticObject("OMSignAPI.OMCOMAPI");
- NowPosition = OMComAPI.GetNowPosition("ABMTX")+1;
- NowClose=0.1;
- rtn=OMComAPI.GoOrder("ABMTX","",NowDateTime,Nowposition,Nowclose);
- _TRACE(WriteIf(rtn, "Buy "+NumToStr(NowPosition,1.0)+"@"+WriteVal(NowClose)+"@"+NowDateTime, "fail"));
- }
- _SECTION_END();
- _SECTION_BEGIN("OrderMaster_SellOrder");
- trigger=ParamTrigger("OrderMaster Sell Order", "Sell");
- if(trigger)
- {
- TimeFormat=1;
- //TimeFormat==0; Format like this: 2011/7/1 13:40:45
- NowDateTime=Now(0);//before using, change OS system datetime format first.
- //TimeFormat==1;//Format like this: 2011/7/1 XXXX 01:40:45
- if(TimeFormat==1)
- NowDateTime=newDateTimeStr();
- OMComAPI = CreateStaticObject("OMSignAPI.OMCOMAPI");
- NowPosition = OMComAPI.GetNowPosition("ABMTX")-1;
- NowClose=0.1;
- rtn=OMComAPI.GoOrder("ABMTX","",NowDateTime,Nowposition,Nowclose);
- _TRACE(WriteIf(rtn, "SELL "+NumToStr(NowPosition,1.0)+"@"+WriteVal(NowClose)+"@"+NowDateTime, "fail"));
- }
- _SECTION_END();
- _SECTION_BEGIN("OrderMaster_GetNowPosition");
- trigger=ParamTrigger("OrderMaster GetNowPosition", "Get Now Position");
- if(trigger)
- {
- OMComAPI = CreateStaticObject("OMSignAPI.OMCOMAPI");
- Nowposition= OMComAPI.GetNowPosition("ABMTX");
- _TRACE( "Now Position: "+NumToStr(Nowposition,1.0) );
- }
- _SECTION_END();
複製代碼 |
評分
-
查看全部評分
|