CGC_Codes

ChannelStrategy

Jun 7th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.44 KB | None | 0 0
  1. using QuantSys.Analytics.Timeseries.Indicators.Averages;
  2. using QuantSys.Analytics.Timeseries.Indicators.Channels;
  3. using QuantSys.Analytics.Timeseries.Indicators.Misc;
  4. using QuantSys.Analytics.Timeseries.Indicators.Transforms;
  5. using QuantSys.MarketData;
  6. using QuantSys.TradeEngine.Simulation.Account;
  7.  
  8. namespace QuantSys.TradeEngine.Strategy
  9. {
  10.     public class ChannelStrategy : AbstractStrategy
  11.     {
  12.         private QSPolyChannel channel;
  13.  
  14.         private Tick prevTick;
  15.  
  16.         private const double STOPLEVEL = 0.005;
  17.  
  18.         public ChannelStrategy()
  19.         {
  20.             channel = new QSPolyChannel();
  21.             AttachIndicator("EMA", new EMA(15));
  22.             AttachIndicator("HVOL", new PercentileRank(100, new HistoricalVol(20)));
  23.         }
  24.         public override void OnTick(params Tick[] t)
  25.         {
  26.             channel.HandleNextTick(t[0]);
  27.  
  28.             foreach (var indicator in indicatorList)
  29.             {
  30.                 indicator.Value.HandleNextTick(t[0]);
  31.             }
  32.  
  33.             if (prevTick != null)
  34.             {
  35.  
  36.                 if (IAccountManager.ExistsLongPositionForSymbol(t[0].Symbol))
  37.                 {
  38.  
  39.                     if (indicatorList["EMA"][0] < channel.LOW(0))
  40.                         IAccountManager.ClosePosition(t[0].Symbol);
  41.  
  42.                 }
  43.                 if (IAccountManager.ExistsShortPositionForSymbol(t[0].Symbol))
  44.                 {
  45.  
  46.                     if (indicatorList["EMA"][0] > channel.HI(0))
  47.                         IAccountManager.ClosePosition(t[0].Symbol);
  48.                 }
  49.  
  50.                
  51.                 if (indicatorList["HVOL"][0] > 40)
  52.                 {
  53.                     if (!IAccountManager.ExistsPositionForSymbol(t[0].Symbol))
  54.                     {
  55.                         if (indicatorList["EMA"][0] > channel.HI(0) && indicatorList["EMA"][1] < channel.HI(1))
  56.                             IAccountManager.PlaceMarketOrder(t[1].Symbol, 10000, Position.PositionSide.Long, STOPLEVEL);
  57.                     }
  58.  
  59.                     if (!IAccountManager.ExistsPositionForSymbol(t[0].Symbol))
  60.                     {
  61.                         if (indicatorList["EMA"][0] < channel.LOW(0) && indicatorList["EMA"][1] > channel.LOW(1))
  62.                             IAccountManager.PlaceMarketOrder(t[1].Symbol, 10000, Position.PositionSide.Short, STOPLEVEL);
  63.                     }
  64.  
  65.                 }
  66.  
  67.             }
  68.  
  69.             prevTick = t[0];
  70.         }
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment