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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Sep 27 22:16:37 CEST 2012


Author: braverock
Date: 2012-09-27 22:16:37 +0200 (Thu, 27 Sep 2012)
New Revision: 1196

Modified:
   pkg/quantstrat/R/orders.R
Log:
- make threshold sign indifferent, if !is.null(side) by checking to see if threshold needs to be reversed to avoid crossing

Modified: pkg/quantstrat/R/orders.R
===================================================================
--- pkg/quantstrat/R/orders.R	2012-09-26 23:09:09 UTC (rev 1195)
+++ pkg/quantstrat/R/orders.R	2012-09-27 20:16:37 UTC (rev 1196)
@@ -260,9 +260,19 @@
                     stoptrailing = {
                         if(isTRUE(tmult))
                         {
-                            if(threshold<1) threshold = price*threshold
+                            threshold = price*threshold
                             tmult=FALSE
                         } 
+                        if(!is.null(side)&& ordertype!='iceberg'){
+                            #check to make sure the order wouldn't instantly cross, reverse threshold if that's the case
+                            if(side=='long') {
+                                #this is a stop exit, so it will sell *lower* than the current market
+                                if(price+threshold>price) threshold=-threshold 
+                            } else { #side=='short'
+                                #this is a stop exit, so it will buy *higher* than the current market
+                                if(price+threshold<price) threshold=-threshold 
+                            }
+                        }
                         price = price+threshold                        
                     }
             ) #end type switch



More information about the Blotter-commits mailing list