Advertisement
CGC_Codes

genesisstrategy

Jun 7th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.71 KB | None | 0 0
  1. using System;
  2. using QuantSys.Analytics.Timeseries.Indicators.Averages;
  3. using QuantSys.Analytics.Timeseries.Indicators.Channels;
  4. using QuantSys.Analytics.Timeseries.Indicators.Misc;
  5. using QuantSys.Analytics.Timeseries.Indicators.Transforms;
  6. using QuantSys.MarketData;
  7. using QuantSys.TradeEngine.AccountManagement;
  8. using QuantSys.TradeEngine.Simulation.Account;
  9.  
  10. namespace QuantSys.TradeEngine.Strategy
  11. {
  12.     public class GenesisStrategy : AbstractStrategy
  13.     {
  14.         private double indNumber;
  15.         private double rindNumber;
  16.  
  17.         private QSPolyChannel QSP;
  18.  
  19.         public GenesisStrategy()
  20.         {
  21.             AttachIndicator("GENESIS", new Genesis(40));
  22.             AttachIndicator("RGENESIS", new ReversalGenesis(40));
  23.             AttachIndicator("EMA", new EMA(5));
  24.             AttachIndicator("HVOL", new PercentileRank(80, new HistoricalVol(40)));
  25.             AttachIndicator("ROC", new PercentileRank(400, new ROC(50)));
  26.             AttachIndicator("GDEMA", new GDEMA(252, 0.75));
  27.  
  28.             QSP = new QSPolyChannel();
  29.             indNumber = Genesis.indNumber;
  30.             rindNumber = ReversalGenesis.indNumber;
  31.         }
  32.  
  33.         private double STOPLEVEL;
  34.         private double LIMITLEVEL;
  35.  
  36.         public override void OnTick(params Tick[] t)
  37.         {
  38.             STOPLEVEL = 50 * t[0].BidOpen/10000;
  39.             LIMITLEVEL = 100 * t[0].BidOpen/10000;
  40.             int POSIZE = (int) (((AccountManager) IAccountManager).CurrentBalance);
  41.  
  42.             QSP.HandleNextTick(t[0]);
  43.             foreach (var indicator in indicatorList)
  44.             {
  45.                 indicator.Value.HandleNextTick(t[0]);
  46.             }
  47.  
  48.             //Check Spread Cost before trading
  49.             if ((t[0].AskClose - t[0].BidClose <= .0005))
  50.             {
  51.  
  52.                 //Volatility high
  53.                 if (indicatorList["HVOL"][0] > 90)
  54.                 {
  55.  
  56.                    
  57.  
  58.                     if (indicatorList["GENESIS"][0] < -1 * (indNumber - 0.5) &&
  59.                         indicatorList["GENESIS"][1] > -1 * (indNumber - 0.5) &&
  60.                         indicatorList["EMA"][0]  < indicatorList["GDEMA"][0])
  61.                     {
  62.                         if (!IAccountManager.ExistsPositionForSymbol(t[0].Symbol))
  63.                         {
  64.                             IAccountManager.PlaceMarketOrder(t[0].Symbol, POSIZE, Position.PositionSide.Short, STOPLEVEL, LIMITLEVEL);
  65.                         }
  66.                     }
  67.                 }
  68.  
  69.             }
  70.  
  71.             if (IAccountManager.ExistsLongPositionForSymbol(t[0].Symbol))
  72.             {
  73.  
  74.             }
  75.  
  76.             if (IAccountManager.ExistsShortPositionForSymbol(t[0].Symbol))
  77.             {
  78.  
  79.             }
  80.  
  81.  
  82.         }
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement