RSI auto closing bot
Created at 23 Jan 2017, 02:08
DE
RSI auto closing bot
23 Jan 2017, 02:08
Hi there.
I am looking for help making a bot that will automatically close a position when the RSI value reaches a specified level.
Example: I manually open a long (or short) and the bot will close the position when the value reaches a predetermined level (72 or 28).
Thanks in advanced.
Replies
derekszyszka
26 Jan 2017, 06:59
RE:
lucian said:
You can try this:
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 derekszyszka : Robot { [Parameter("Source")] public DataSeries Source { get; set; } [Parameter("Periods", DefaultValue = 14)] public int Periods { get; set; } [Parameter("Low RSI", DefaultValue = 28)] public int low_rsi { get; set; } [Parameter("High RSI", DefaultValue = 72)] public int high_rsi { get; set; } private RelativeStrengthIndex rsi; protected override void OnStart() { rsi = Indicators.RelativeStrengthIndex(Source, Periods); } protected override void OnTick() { if (rsi.Result.LastValue <= low_rsi) { foreach (var position in Positions) if (position.TradeType == TradeType.Sell && position.SymbolCode == Symbol.Code) ClosePosition(position); } if (rsi.Result.LastValue >= high_rsi) { foreach (var position in Positions) if (position.TradeType == TradeType.Buy && position.SymbolCode == Symbol.Code) ClosePosition(position); } } } }
This is exactly what I need, thank you very much. Just a thought, would this also be possible with MACD crossover open and closes?
@derekszyszka
... Deleted by UFO ...