Topics
Replies
john123321
31 Oct 2017, 13:43
not working algo published which was working before
HI,
please fix this algo /algos/cbots/show/257
in the above link the c algo published news trading with trailing stop loss is not working can you look into it
we want it to be fixed soon.please
@john123321
john123321
30 Oct 2017, 22:37
thanks for your time and effort but still not working
tradermatrix said:
Hello
now it should workusing System; using cAlgo.API; namespace cAlgo.Robots { [Robot(AccessRights = AccessRights.None)] public class TradingNewsRobot : Robot { private PendingOrder _buyOrder; private bool _ordersCreated; private PendingOrder _sellOrder; private Position position; [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("Seconds Before", DefaultValue = 5, MinValue = 1)] public int SecondsBefore { get; set; } [Parameter("Seconds Timeout", DefaultValue = 10, MinValue = 1)] public int SecondsTimeout { get; set; } [Parameter("One Cancels Other", DefaultValue = 1, MinValue = 0, MaxValue = 1)] public int Oco { get; set; } [Parameter("Pips away", DefaultValue = 10)] public int PipsAway { get; set; } [Parameter("Volume", DefaultValue = 10000, MinValue = 1000)] public int Volume { get; set; } [Parameter("Take Profit", DefaultValue = 80)] public int TakeProfit { get; set; } [Parameter("Stop Loss", DefaultValue = 10)] public int StopLoss { get; set; } [Parameter("Trigger (pips) if > 0", DefaultValue = 0)] public int Trigger { get; set; } [Parameter("Trailing Stop (pips) if > 0 ", DefaultValue = 0)] public int TrailingStop { get; set; } protected override void OnStart() { MarketData.GetMarketDepth(Symbol).Updated += MarketDepth_Updated; } protected override void OnTick() { if (position == null) return; TRAILING(); } private void TRAILING() { foreach (var position in Positions) { if (TrailingStop > 0 && Trigger > 0) { if (position.TradeType == TradeType.Sell) { double distance = position.EntryPrice - Symbol.Ask; if (distance >= Trigger * Symbol.PipSize) { double newStopLossPrice = Symbol.Ask + TrailingStop * Symbol.PipSize; if (position.StopLoss == null || newStopLossPrice < position.StopLoss) { ModifyPosition(position, newStopLossPrice, position.TakeProfit); } } } else { double distance = Symbol.Bid - position.EntryPrice; if (distance >= Trigger * Symbol.PipSize) { double newStopLossPrice = Symbol.Bid - TrailingStop * Symbol.PipSize; if (position.StopLoss == null || newStopLossPrice > position.StopLoss) { ModifyPosition(position, newStopLossPrice, position.TakeProfit); } } } } } } private void MarketDepth_Updated() { 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; DateTime expirationTime = triggerTime.AddSeconds(SecondsTimeout); double sellOrderTargetPrice = Symbol.Bid - PipsAway * Symbol.PipSize; Trade.CreateSellStopOrder(Symbol, Volume, sellOrderTargetPrice, sellOrderTargetPrice + StopLoss * Symbol.PipSize, sellOrderTargetPrice - TakeProfit * Symbol.PipSize, expirationTime); double buyOrderTargetPrice = Symbol.Ask + PipsAway * Symbol.PipSize; Trade.CreateBuyStopOrder(Symbol, Volume, buyOrderTargetPrice, buyOrderTargetPrice - StopLoss * Symbol.PipSize, buyOrderTargetPrice + TakeProfit * Symbol.PipSize, expirationTime); } } } protected override void OnPendingOrderCreated(PendingOrder newOrder) { if (newOrder.TradeType == TradeType.Buy) _buyOrder = newOrder; else _sellOrder = newOrder; } protected override void OnPositionOpened(Position openedPosition) { position = openedPosition; if (Oco == 1) { Trade.DeletePendingOrder(_buyOrder); Trade.DeletePendingOrder(_sellOrder); _ordersCreated = false; } } protected override void OnPositionClosed(Position closedPosition) { position = null; } } }Hi bro.
i really appreciate your time and effort but still it does not place order and does not work...i request you to please look into it and help me.
The following news robot works /algos/cbots/show/199 but it does not have trailling stop triger and trail pips option.
please help me in order to have trailing stop triger pips and trail stop by option to work.
thanks you so much
@john123321
john123321
30 Oct 2017, 17:10
https://ctdn.com/algos/cbots/show/257
fix the algo /algos/cbots/show/257....we are c trader users we require good support or we will stop using...look into to the algo its not working....
@john123321
john123321
02 Nov 2017, 14:59
tradermatrix thanks
Hi,
I tested on a demo account in normal market itseems to work fine. thank you so much...but during news event the platform hangs while using this algo...will try again for few more news events..i will keep you posted....i appreciate your help a lot....may god bless you...tcare..i wish you all the best for your life....
@john123321