Last active
August 29, 2015 14:20
-
-
Save josgraha/9ffe46393f3ab5b42509 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define(function(require) { | |
var System = {}; | |
System.Events = require("./core/events"), | |
System.Strategy = require("./core/strategy"), | |
System.Analytics = require("./core/analytics"), | |
System.Indicators = require("./core/indicators"), | |
System.Market = require("./rules/market"), | |
System.Timeseries = require("./data/timeseries"), | |
System.Symbols = require("./pairs/symbols"), | |
System.Portfolio = require("./manager/portfolio"); | |
// strategy fires when 4hr time window velocity is in line with accelleration indicator | |
return { | |
isEnabled: function(tick) { | |
return System.Market.isAvailable(tick.timewindow, tick.symbol); | |
}, | |
enterRules: function(tick) { | |
return System.Strategy.RuleBuilder | |
.onCriteria( | |
// create criteria | |
System.Strategy.CriteriaBuilder.create( | |
// when accellerator is near zero | |
System.Indicators.AC.isNearZero(tick) | |
).and( | |
// match 1m and 4h velocity | |
System.Analytics.Direction.equals( | |
// get velocity (up/down) on 1m window | |
System.Analytics.velocity(System.Timeseries.Windows['1m'], tick), | |
// get velocity (up/down) on 4h window | |
System.Analytics.velocity(System.Timeseries.Windows['4h'], tick) | |
) | |
).build() // return criteria for strategy | |
).thenReturn( | |
// return position event (buy/sell/ignore) | |
System.Strategy.enterWithDirection( | |
// return buy/sell when velocity (up/down) matches above criteria | |
System.Analytics.Direction.fromVelocity( | |
System.Analytics.velocity(System.Timeseries.Windows['1m'], tick) | |
) | |
) | |
).build(); // build and return rules | |
}, | |
exitRules: function(tick) { | |
return System.Strategy.RuleBuilder | |
.onCriteria( | |
System.Strategy.CriteriaBuilder.create( | |
// exit if accelleration is reversed | |
System.Indicators.AC.isReversed(tick) | |
).or( | |
// exit if velocity is reversed in 1m (current) window | |
System.Analytics.Direction.isReversed( | |
System.Analytics.velocity(System.Timeseries.Windows['1m'], tick), | |
) | |
).or( | |
// exit if velocity is reversed in 5m (current + 1 level) window | |
System.Analytics.Momentum.isSlowed( | |
System.Analytics.velocity(System.Timeseries.Windows['5m'], tick), | |
) | |
).or( | |
// exit if portfolio manager says limit is reached for symbol | |
System.Portfolio.positionForSymbol(System.Symbols.symbolFor(tick)) | |
.hasReachedLimit(tick) | |
).build() // return exit criteria | |
).thenReturn( | |
//return close event if above criteria are met | |
System.Strategy.exitWithDirection( | |
System.Analytics.Direction.fromVelocity( | |
System.Analytics.velocity(System.Timeseries.Windows['1m'], tick) | |
) | |
) | |
).build(); // build and return rules | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment