Advertisement
enheton

Untitled

Dec 13th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using cAlgo.API;
  4. using cAlgo.API.Indicators;
  5. using cAlgo.API.Internals;
  6. using cAlgo.Indicators;
  7.  
  8. namespace cAlgo
  9. {
  10. [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
  11. public class SampleRSIcBot : Robot
  12. {
  13. [Parameter("Source")]
  14. public DataSeries Source { get; set; }
  15.  
  16. [Parameter("Periods", DefaultValue = 14)]
  17. public int Periods { get; set; }
  18.  
  19. [Parameter("Quantity (Lots)", DefaultValue = 1, MinValue = 0.01, Step = 0.01)]
  20. public double Quantity { get; set; }
  21.  
  22. private RelativeStrengthIndex rsi;
  23.  
  24. protected override void OnStart()
  25. {
  26. rsi = Indicators.RelativeStrengthIndex(Source, Periods);
  27. }
  28.  
  29. protected override void OnTick()
  30. {
  31. if (rsi.Result.LastValue < 30)
  32. {
  33. Close(TradeType.Sell);
  34. Open(TradeType.Buy);
  35. }
  36. else if (rsi.Result.LastValue > 70)
  37. {
  38. Close(TradeType.Buy);
  39. Open(TradeType.Sell);
  40. }
  41. }
  42.  
  43. private void Close(TradeType tradeType)
  44. {
  45. foreach (var position in Positions.FindAll("SampleRSI", Symbol, tradeType))
  46. ClosePosition(position);
  47. }
  48.  
  49. private void Open(TradeType tradeType)
  50. {
  51. var position = Positions.Find("SampleRSI", Symbol, tradeType);
  52. var volumeInUnits = Symbol.QuantityToVolume(Quantity);
  53.  
  54. if (position == null)
  55. ExecuteMarketOrder(tradeType, Symbol, volumeInUnits, "SampleRSI");
  56. }
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement