Topics
Replies
dinodelides
30 Nov 2020, 17:36
RE:
Ευχαριστώ πολύ Panagiotis! I have added this to my bots where necessary.
Best regards
Dino
PanagiotisCharalampous said:
Hi dinodelides,
You can change the value which the cBot checks to enter the trade. Instead of the LastValue, you can check Last(1), Last(2) etc. where the number represent a backwards index of the relevant series.
Best Regards,
Panagiotis
@dinodelides
dinodelides
29 Nov 2020, 09:41
RE: RE:
prosteel1 said:
This is a modified RSI bot.
series.Count - 3 gives 2 full bars back, each new bar increases the count by 1.
You can check the print of the High to make sure it is working properly.
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("Quantity (Lots)", Group = "Volume", DefaultValue = 1, MinValue = 0.01, Step = 0.01)] public double Quantity { get; set; } [Parameter("Source", Group = "RSI")] public DataSeries Source { get; set; } [Parameter("Periods", Group = "RSI", DefaultValue = 14)] public int Periods { get; set; } [Parameter("Partial Close offset", DefaultValue = 10, MinValue = 10, Step = 10)] public int Offset { get; set; } [Parameter("Timeframe", DefaultValue = "Hour")] public TimeFrame tf { get; set; } private RelativeStrengthIndex rsi; Bars series; int BarLast; protected override void OnStart() { rsi = Indicators.RelativeStrengthIndex(Source, Periods); series = MarketData.GetBars(tf); BarLast = series.Count - 3; } protected override void OnStop() { foreach (var position in Positions) { ClosePosition(position); } } protected override void OnTick() { if (series.Count - 3 > BarLast) { Print("series.Count - 3 = " + (series.Count - 3) + " has a High of = " + series.HighPrices[series.Count - 3]); if (rsi.Result.LastValue < 30) { Close(TradeType.Sell); Open(TradeType.Buy); } else if (rsi.Result.LastValue > 70) { Close(TradeType.Buy); Open(TradeType.Sell); } if (rsi.Result.LastValue < 30 + Offset) { PartialClose(TradeType.Sell); } if (rsi.Result.LastValue > 70 - Offset) { PartialClose(TradeType.Buy); } BarLast = series.Count - 3; } } private void Close(TradeType tradeType) { foreach (var position in Positions.FindAll("SampleRSI", SymbolName, tradeType)) ClosePosition(position); } private void PartialClose(TradeType tradeType) { foreach (var position in Positions.FindAll("SampleRSI", SymbolName, tradeType)) { double newVol = Symbol.NormalizeVolumeInUnits((position.VolumeInUnits / 2), RoundingMode.Up); if (position.Quantity == Quantity) { ClosePosition(position, newVol); Print("Partial closing " + newVol + " of " + position + " due to RSI = " + rsi.Result.LastValue); } } } private void Open(TradeType tradeType) { var position = Positions.Find("SampleRSI", SymbolName, tradeType); var volumeInUnits = Symbol.QuantityToVolumeInUnits(Quantity); if (position == null) ExecuteMarketOrder(tradeType, SymbolName, volumeInUnits, "SampleRSI"); } } }
Thank you very much for the quick response Prosteel1 - I will work through it to make sure I understand what it is doing and then give it a test. Have a great day :)
@dinodelides
dinodelides
02 Dec 2020, 14:08
RE:
Thank you for the swift reply Panagiotis.
PanagiotisCharalampous said:
@dinodelides