Disliked{quote} Hi Alan111S, can you change Amazing EA into cAlgo ? I tried trading using cTrader (sorry my bad english)Thanks beforeIgnored
Inserted Code
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class NewsRobot : Robot
{
[Parameter("News Day (1-5)", DefaultValue = 1, MinValue = 1, MaxValue = 5)]
public int NewsDay { get; set; }
[Parameter("News Hour", DefaultValue = 14, MinValue = 0, MaxValue = 23)]
public int NewsHour { get; set; }
[Parameter("News Minute", DefaultValue = 30, MinValue = 0, MaxValue = 59)]
public int NewsMinute { get; set; }
[Parameter("Pips away", DefaultValue = 10)]
public int PipsAway { get; set; }
[Parameter("Take Profit", DefaultValue = 50)]
public int TakeProfit { get; set; }
[Parameter("Stop Loss", DefaultValue = 10)]
public int StopLoss { get; set; }
[Parameter("Volume", DefaultValue = 100000, MinValue = 10000)]
public int Volume { get; set; }
[Parameter("Seconds Before", DefaultValue = 10, MinValue = 1)]
public int SecondsBefore { get; set; }
[Parameter("Seconds Timeout", DefaultValue = 10, MinValue = 1)]
public int SecondsTimeout { get; set; }
[Parameter("One Cancels Other")]
public bool Oco { get; set; }
private bool _ordersCreated;
private const string Label = "News Robot";
protected override void OnStart()
{
MarketData.GetMarketDepth(Symbol).Updated += PlaceStopOrders;
Positions.Opened += OnPositionOpened;
}
protected override void OnTick()
{
PlaceStopOrders();
}
void PlaceStopOrders()
{
if ((int)Server.Time.DayOfWeek == NewsDay && !_ordersCreated)
{
var triggerTime = new DateTime(Server.Time.Year, Server.Time.Month, Server.Time.Day, NewsHour, NewsMinute, 0);
if (Server.Time <= triggerTime && (triggerTime - Server.Time).TotalSeconds <= SecondsBefore)
{
_ordersCreated = true;
var expirationTime = triggerTime.AddSeconds(SecondsTimeout);
var sellOrderTargetPrice = Symbol.Bid - PipsAway * Symbol.PipSize;
PlaceStopOrder(TradeType.Sell, Symbol, Volume, sellOrderTargetPrice, Label, StopLoss, TakeProfit, expirationTime);
var buyOrderTargetPrice = Symbol.Ask + PipsAway * Symbol.PipSize;
PlaceStopOrder(TradeType.Buy, Symbol, Volume, buyOrderTargetPrice, Label, StopLoss, TakeProfit, expirationTime);
}
}
}
private void OnPositionOpened(PositionOpenedEventArgs args)
{
var position = args.Position;
if (position.Label == Label && position.SymbolCode == Symbol.Code)
{
if (Oco)
{
foreach (var order in PendingOrders)
{
if (order.Label == Label && order.SymbolCode == Symbol.Code)
{
CancelPendingOrderAsync(order);
}
}
}
Stop();
}
}
}
} Hope Alan111S and other expert coders will have a look and add more options which are available in Amazing EA to this Cbot.
Source: http://ctdn.com/algos/cbots/show/199