Hi all, I am glad to find out many auto trading high hands here like Joesan, Amkr and etc. I tried to set up buy TF orders once current bar breaking out previous bar. I run into problem of many repeating orders with each refresh market datas. I tried StatocVargetTest plus if(ordered==0), but it did not work. I would appreciate you very much if someone could point out how to fix this problem. Sorry, I have to type in English because of lack of Chinese software in my PC. Here is my short coding: -------------- Buy=High>=Ref(H, -1) AND Conditions; if( LastValue( Buy )) { ibc = GetTradingInterface("IB"); // check if we are connected OK if( ibc.IsConnected() ) { // check if we do not have already open position on this stock if( ibc.GetPositionSize( Name() ) == 0 ) { OrderID = StaticVarGetText("OrderID"+Name()); //if the OrderID field is empty if(OrderID==0) { // transmit order ibc.PlaceOrder( "TFZ8-NYBOT-FUT", "Buy", 1, "LMT", Limitprice, 0, "Day", True ); // store orderID for next run so we know which order to modify StaticVarSetText("OrderID"+Name(), OrderID); } } } }
参考一下这一段吧。我也是今天才找到解决的办法。 但是还有一个问题。这个时间最短只能设置一分钟,我测试在5分钟的里面最多有可能会出现5笔交易。还没想出来解决办法。 PrevDT = StaticVarGet("DateTime"); printf("PrevDTdddd %d",PrevDT); DT = LastValue(DateTime()); NewBar = DT != PrevDT; StaticVarSet("DateTime",DT); if( NewBar ) { StaticVarSetText("OrderID",""); } 你测试测试吧。
The ibc.PlaceOrder function returns an order id value which you should have assigned into a variable, the logical one being OrderId, so that the next line sets the static variable "OrderID"+NAME() to the order ID from the PlaceOrder function, otherwise you're just assigning "" back into the static variable, and placing a new order on every loop.
repeating orders Thank you very much for the helps! I fixed the problem. I will work on the clearing orderID with the delays. Shalang, My understanding is your formula provides delay with starting next new bar, or about 1 min lock out if you use 1 min data as the base data source. It should be good enough for me. I will try latter. If you you want to lock off the signal for certain time, maybe the idea: DT-PrevDT>=300(say, 300 sec), then set orderID==''" this is my idea only, I don't know how to do it exactly. I don't have any back ground of programing. I learn very slowly.