Candle Prices at specific time
Created at 17 Apr 2020, 22:44
SA
Candle Prices at specific time
17 Apr 2020, 22:44
Hi all
I am creating a breakout bot which opens a pending order at 7am on the hourly timeframe. I want the submitted price of the buy order to be at the previous candles high and the sell order at previous candles low.
See code below:
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 BreakoutBot : Robot
{
[Parameter("Instance Name", DefaultValue = "Breakout")]
public string InstanceName { get; set; }
[Parameter("Start Time", DefaultValue = 7, MinValue = 0, MaxValue = 24)]
public double startTime { get; set; }
[Parameter("Expiry in hours", DefaultValue = 2, MinValue = 0, MaxValue = 24)]
public double expHrs { get; set; }
protected override void OnStart()
{
// Put your deinitialization logic here
}
protected override void OnTick()
{
//Last closed bar open price
var open = MarketSeries.Open.Last(1);
//Last closed bar close price
var close = MarketSeries.Close.Last(1);
//Last closed bar high price
var high = MarketSeries.High.Last(1);
//Las closed bar low price
var low = MarketSeries.Low.Last(1);
var buyPrice = high;
var sellPrice = low;
var expiredtime = Server.Time.AddHours(expHrs);
if (Positions.Count == 0 && PendingOrders.Count(item => item.OrderType == PendingOrderType.Stop && item.TradeType == TradeType.Buy) == 0)
{
if (Server.Time.Hour == startTime)
{
PlaceStopOrder(TradeType.Sell, SymbolName, 1000, sellPrice, InstanceName, 50, 50, expiredtime);
PlaceStopOrder(TradeType.Buy, SymbolName, 1000, buyPrice, InstanceName, 50, 50, expiredtime);
}
}
if (Positions.Count == 1)
{
foreach (var order in PendingOrders)
{
CancelPendingOrder(order);
}
}
}
}
}
Any help would be greatly appreciated
Samuel
samuelbreezey
17 Apr 2020, 22:54
RE:
samuelbreezey said:
Sorry it looks like I have figured it out:
@samuelbreezey