[Blotter-commits] r1029 - pkg/quantstrat/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri May 25 19:19:32 CEST 2012


Author: opentrades
Date: 2012-05-25 19:19:32 +0200 (Fri, 25 May 2012)
New Revision: 1029

Modified:
   pkg/quantstrat/R/ruleOrderProc.R
Log:
fixed stoplimit order bug (order sometimes executed immediately)

Modified: pkg/quantstrat/R/ruleOrderProc.R
===================================================================
--- pkg/quantstrat/R/ruleOrderProc.R	2012-05-21 03:15:05 UTC (rev 1028)
+++ pkg/quantstrat/R/ruleOrderProc.R	2012-05-25 17:19:32 UTC (rev 1029)
@@ -131,7 +131,7 @@
                                 stop("iceberg orders only supported for BBO data")
                             } 
                             # check to see if price moved through the limit                        
-                            if(orderQty > 0 || (orderQty < 0 && orderType == 'stoplimit') ) {  
+                            if((orderQty > 0 && orderType != 'stoplimit') || (orderQty < 0 && orderType == 'stoplimit') ) {  
                                 # buy limit, or sell stoplimit
                                 if( (has.Lo(mktdata) && orderPrice > as.numeric(Lo(mktdataTimestamp))) || 
                                     (!has.Lo(mktdata) && orderPrice >= as.numeric(getPrice(mktdataTimestamp, prefer=prefer))))
@@ -139,7 +139,7 @@
                                     txnprice = orderPrice
                                     txntime = timestamp
                                 } else next() # price did not move through my order, should go to next order  
-                            } else if(orderQty < 0 || (orderQty > 0 && orderType == 'stoplimit')) { 
+                            } else if((orderQty < 0 && orderType != 'stoplimit') || (orderQty > 0 && orderType == 'stoplimit')) { 
                                 # sell limit or buy stoplimit
                                 if ( (has.Hi(mktdata) && orderPrice < as.numeric(Hi(mktdataTimestamp))) ||
                                      (!has.Hi(mktdata) && orderPrice <= as.numeric(getPrice(mktdataTimestamp,prefer=prefer))) )



More information about the Blotter-commits mailing list