Help with order cancel after x bars
Help with order cancel after x bars
26 Jan 2021, 01:48
Hi, I'm new to coding so was wondering if someone could help me get this code working. Thanks
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class NewcBot : Robot
{
private RelativeStrengthIndex Rsi;
private SimpleMovingAverage High;
int GetBarsAgo(Position position);
protected override void OnStart()
{
Rsi = Indicators.RelativeStrengthIndex(Bars.ClosePrices, 14);
High = Indicators.SimpleMovingAverage(Bars.HighPrices, 1);
}
protected override void OnBar()
{
for (var i = MarketSeries.OpenTime.Count - 1; i >= 0; i--)
{
if (position.EntryTime > MarketSeries.OpenTime[i])
return MarketSeries.OpenTime.Count - 1 - i;
}
return -1;
//Rsi
if (Rsi.Result.LastValue < 60)
{
PlaceStopLimitOrder(TradeType.Buy, SymbolName, 10000, High.Result.Last(2), 0.5, "StopOrder", 5, 5);
}
foreach (var order in PendingOrders)
var barsAgo = GetBarsAgo(position);
{
if (order.Label == "StopOrder")
if (barsAgo > 2)
{
CancelPendingOrder(order);
}
}
}
}
}