Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using cAlgo.API;
- using cAlgo.API.Indicators;
- using cAlgo.API.Internals;
- using cAlgo.Indicators;
- namespace cAlgo
- {
- [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
- public class SampleRSIcBot : Robot
- {
- [Parameter("Source")]
- public DataSeries Source { get; set; }
- [Parameter("Periods", DefaultValue = 14)]
- public int Periods { get; set; }
- [Parameter("Quantity (Lots)", DefaultValue = 1, MinValue = 0.01, Step = 0.01)]
- public double Quantity { get; set; }
- private RelativeStrengthIndex rsi;
- protected override void OnStart()
- {
- rsi = Indicators.RelativeStrengthIndex(Source, Periods);
- }
- protected override void OnTick()
- {
- if (rsi.Result.LastValue < 30)
- {
- Close(TradeType.Sell);
- Open(TradeType.Buy);
- }
- else if (rsi.Result.LastValue > 70)
- {
- Close(TradeType.Buy);
- Open(TradeType.Sell);
- }
- }
- private void Close(TradeType tradeType)
- {
- foreach (var position in Positions.FindAll("SampleRSI", Symbol, tradeType))
- ClosePosition(position);
- }
- private void Open(TradeType tradeType)
- {
- var position = Positions.Find("SampleRSI", Symbol, tradeType);
- var volumeInUnits = Symbol.QuantityToVolume(Quantity);
- if (position == null)
- ExecuteMarketOrder(tradeType, Symbol, volumeInUnits, "SampleRSI");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement