Untitled
unknown
plain_text
a year ago
2.8 kB
0
Indexable
Never
using cAlgo.API; using cAlgo.API.Indicators; using System; namespace cAlgo { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class ImprovedRSIcBot : Robot { [Parameter("Quantity (Lots)", Group = "Volume", DefaultValue = 1, MinValue = 0.01, Step = 0.01)] public double Quantity { get; set; } [Parameter("Supertrend Period (ATR 10)", DefaultValue = 10)] public int SupertrendPeriod10 { get; set; } [Parameter("Supertrend Multiplier (ATR 10)", DefaultValue = 1.0)] public double SupertrendMultiplier10 { get; set; } private Supertrend supertrend10; [Parameter("Maximum Allowed Spread", DefaultValue = 0.00003, MinValue = 0.0)] public double MaxSpread { get; set; } public Supertrend supertrend; public AverageTrueRange atr; protected override void OnStart() { supertrend = Indicators.Supertrend(10, 3); atr = Indicators.AverageTrueRange(10, MovingAverageType.WilderSmoothing); supertrend10 = Indicators.Supertrend(SupertrendPeriod10, SupertrendMultiplier10); } protected override void OnTick() { int lastIndex = MarketSeries.Close.Count - 1; double stop = 1; if (Symbol.Spread > MaxSpread) { foreach (var order in PendingOrders) { CancelPendingOrder(order); } foreach (var position in Positions) { ClosePosition(position); } } // Check conditions for Supertrend 10 (ATR 10, Multiplier 1) bool isUpTrend10 = supertrend10.UpTrend.IsRising(); double minATR = 0.0001; // Set your desired minimum ATR value bool hasMinATR = atr.Result[lastIndex] > minATR; if (Symbol.Spread <= MaxSpread && supertrend.UpTrend.IsRising() && Positions.Count == 0 && isUpTrend10 && hasMinATR) { foreach (var order in PendingOrders) { CancelPendingOrder(order); } // Calculate stop-loss and take-profit levels here double entryPrice = MarketSeries.Open[lastIndex]; double stopLoss = entryPrice - (stop * Symbol.PipSize); double takeProfit = entryPrice + (2 * stop * Symbol.PipSize); // Check the current spread before placing the limit order double currentSpread = Symbol.Spread; if (currentSpread <= MaxSpread) { Print("Spread: " + Symbol.Spread); PlaceLimitOrder(TradeType.Buy, SymbolName, Symbol.QuantityToVolumeInUnits(Quantity * 10), supertrend.UpTrend.LastValue, "Buy", stopLoss, takeProfit, null, null, true); } } } } }