Using Stop Limit orders
Using Stop Limit orders
09 Mar 2022, 12:35
Hi all,
My bot should do the following. Every New York Open it should place a Stop Limit order both to the the buy and sell side. Also the orders should expire the same day, ensuring the bot places a trade every day. However when I backtest, the bot doesn't place a trade everyday. Any idea why?
source code:
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 NYOpen : Robot
{
[Parameter("Entry Time (Hours)", DefaultValue = 14)]
public double EntryTime { get; set; }
[Parameter("Entry", DefaultValue = 5)]
public int Entry { get; set; }
[Parameter("Quantity (Lots)", Group = "Volume", DefaultValue = 1, MinValue = 0.01, Step = 0.01)]
public double Quantity { get; set; }
[Parameter("Stop Loss (Pips)", DefaultValue = 20)]
public int SL { get; set; }
[Parameter("Take Profit (Pips)", DefaultValue = 10)]
public int TP { get; set; }
protected override void OnStart()
{
}
protected override void OnTick()
{
var Hour = Server.Time.TimeOfDay.TotalHours;
//Enter Trade
if (Hour == EntryTime)
{
PlaceStopLimitOrder(TradeType.Buy, SymbolName, VolumeInUnits, Symbol.Ask + (Entry * Symbol.PipSize), 0.0, "NY Open", SL, TP, Server.Time.AddHours(12));
PlaceStopLimitOrder(TradeType.Sell, SymbolName, VolumeInUnits, Symbol.Bid - (Entry * Symbol.PipSize), 0.0, "NY Open", SL, TP, Server.Time.AddHours(12));
}
//Close Trades
}
private double VolumeInUnits
{
get { return Symbol.QuantityToVolumeInUnits(Quantity); }
}
protected override void OnStop()
{
// Put your deinitialization logic here
}
}
}
amusleh
10 Mar 2022, 10:21
Hi,
Try this:
@amusleh