Category Other  Published on 05/11/2014

News Robot

Description

Robot places buy and sell STOP orders at specific time. Supports TP, SL, OCO and expiration time.

Parameters:

  • News Hour - Hour when news will be published (your local time)
  • News Minute - Minute when news will be published (your local time)
  • Pips away - The number of pips away from the current market price where the pending buy and sell orders will be placed.
  • Take Profit - Take Profit in pips for each order
  • Stop Loss - Stop Loss in pips for each order
  • Volume - trading volume
  • Seconds before - Seconds Before News when robot will place Pending Orders
  • Seconds timeout - Seconds After News when Pending Orders will be deleted
  • One Cancels Other - If "Yes" then when one order will be filled, another order will be deleted

News Robot PRO with Trailing Stop and Slippage Control

http://news-robot.net

 

 

 

 


using System;
using System.Linq;
using System.Text;
using cAlgo.API;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewsRobot : Robot
    {
        [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; }

        [Parameter("ShowTimeLeftNews", DefaultValue = false)]
        public bool ShowTimeLeftToNews { get; set; }

        [Parameter("ShowTimeLeftPlaceOrders", DefaultValue = true)]
        public bool ShowTimeLeftToPlaceOrders { get; set; }

        private bool _ordersCreated;

        private DateTime _triggerTimeInServerTimeZone;

        private const string Label = "News Robot";

        protected override void OnStart()
        {
            Positions.Opened += OnPositionOpened;
            Timer.Start(1);

            var triggerTimeInLocalTimeZone = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, NewsHour, NewsMinute, 0);
            if (triggerTimeInLocalTimeZone < DateTime.Now)
                triggerTimeInLocalTimeZone = triggerTimeInLocalTimeZone.AddDays(1);
            _triggerTimeInServerTimeZone = TimeZoneInfo.ConvertTime(triggerTimeInLocalTimeZone, TimeZoneInfo.Local, TimeZone);
        }

        protected override void OnTimer()
        {
            var remainingTime = _triggerTimeInServerTimeZone - Server.Time;
            DrawRemainingTime(remainingTime);

            if (!_ordersCreated)
            {
                var sellOrderTargetPrice = Symbol.Bid - PipsAway * Symbol.PipSize;
                ChartObjects.DrawHorizontalLine("sell target", sellOrderTargetPrice, Colors.Red, 1, LineStyle.DotsVeryRare);
                var buyOrderTargetPrice = Symbol.Ask + PipsAway * Symbol.PipSize;
                ChartObjects.DrawHorizontalLine("buy target", buyOrderTargetPrice, Colors.Blue, 1, LineStyle.DotsVeryRare);

                if (Server.Time <= _triggerTimeInServerTimeZone && (_triggerTimeInServerTimeZone - Server.Time).TotalSeconds <= SecondsBefore)
                {
                    _ordersCreated = true;
                    var expirationTime = _triggerTimeInServerTimeZone.AddSeconds(SecondsTimeout);

                    PlaceStopOrder(TradeType.Sell, Symbol, Volume, sellOrderTargetPrice, Label, StopLoss, TakeProfit, expirationTime);
                    PlaceStopOrder(TradeType.Buy, Symbol, Volume, buyOrderTargetPrice, Label, StopLoss, TakeProfit, expirationTime);

                    ChartObjects.RemoveObject("sell target");
                    ChartObjects.RemoveObject("buy target");
                }
            }

            if (_ordersCreated && !PendingOrders.Any(o => o.Label == Label))
            {
                Print("Orders expired");
                Stop();
            }
        }

        private void DrawRemainingTime(TimeSpan remainingTimeToNews)
        {
            if (ShowTimeLeftToNews)
            {
                if (remainingTimeToNews > TimeSpan.Zero)
                {
                    ChartObjects.DrawText("countdown1", "Time left to news: " + FormatTime(remainingTimeToNews), StaticPosition.TopLeft);
                }
                else
                {
                    ChartObjects.RemoveObject("countdown1");
                }
            }
            if (ShowTimeLeftToPlaceOrders)
            {
                var remainingTimeToOrders = remainingTimeToNews - TimeSpan.FromSeconds(SecondsBefore);
                if (remainingTimeToOrders > TimeSpan.Zero)
                {
                    ChartObjects.DrawText("countdown2", "Time left to place orders: " + FormatTime(remainingTimeToOrders), StaticPosition.TopRight);
                }
                else
                {
                    ChartObjects.RemoveObject("countdown2");
                }
            }
        }

        private static StringBuilder FormatTime(TimeSpan remainingTime)
        {
            var remainingTimeStr = new StringBuilder();
            if (remainingTime.TotalHours >= 1)
                remainingTimeStr.Append((int)remainingTime.TotalHours + "h ");
            if (remainingTime.TotalMinutes >= 1)
                remainingTimeStr.Append(remainingTime.Minutes + "m ");
            if (remainingTime.TotalSeconds > 0)
                remainingTimeStr.Append(remainingTime.Seconds + "s");
            return remainingTimeStr;
        }

        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();
            }
        }
    }
}


algotrader's avatar
algotrader

Joined on 12.11.2012

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: News Robot.algo
  • Rating: 3.67
  • Installs: 15246
  • Modified: 13/10/2021 09:54
Comments
Log in to add a comment.
FR
freyrthegreat · 3 years ago

how to change to amount of lot to be open?

TG
tgjobscv · 5 years ago

New ver ?

SK
skuza.tomasz · 6 years ago

hi it is posible to place this order by hand ???not on specific time ?

HA
hagenevents2013@gmail.com · 7 years ago

Can someone help me to add a Slippage control. Like to set maximum negative slippage allowed for a triggered order.

 

ME
mert.19.04 · 7 years ago

ALGO Turn to me its urgent 

EA is not work it starts take order 5 secondes later 

it was closed all orders

how can be possible 

Also why we are waiting every time allmost 21 hours ?

HELP ME

ME
mert.19.04 · 7 years ago

Hi.I have 2 questions about your EA first one is How can i change UTC for my Republic of Turkey(we are using UTC+3)And seconde question is when i tried to use this code the system gave eror how can i fix ?

 Trade.CreateBuyStopOrder(Symbol, Volume, buyOrderTargetPrice, buyOrderTargetPrice - StopLoss * Symbol.PipSize, buyOrderTargetPrice+ TakeProfit * Symbol.PipSize, expirationTime);PlaceStopOrder(TradeType.Buy, Symbol, Volume, buyOrderTargetPrice, Label, StopLoss, TakeProfit, expirationTime);

LU
luis_q · 7 years ago

What can I do to buy the News Robot PRO with Trailing Stop and Slippage Control?

 

Thanks.

BU
bulatsergiu83 · 7 years ago

Hello!

Great work!

Can you help me, please , to change this bot to work just for BUY or SELL orders , NOT for BOTH in the same time!?

Thank you for your time and help!!!

Have a nice day and STAY GREEN!!!

MA
Marek.Hurkens · 7 years ago

Hey Algotrader,

I love this bot it works smooth and perfect.

How much do i need to pay you to offer us the same one with money management and trailing Stop?

nice greeds

BH
bhagya3udana856 · 7 years ago

Allgotrader,

I love this cbot.

Can you please add this to trailing stop.

 

Timmi's avatar
Timmi · 8 years ago

Is it possible, to set both, a move to break even (+pips), and thereafter have a trailing stop after specified number of minutes?  the parameters would not be the same for the two.  in cTrader you can only set one or the other, but most of the time I have to go back and set a trailing (with different parameters) once break-even has been locked in. 

Because of high volatility, I would not want a trailing stop in the first few minutes, so I am not thrown out prematurely. Once things settle down, than let it trail.  For example, after 3 minutes, or 5 minutes, commence a trailing stop. 

For example: Move to break-even plus 10 after a 50 pip gain, then trail for 10 after the 5 minutes mark.  (that would allow for the fast fluctuations while protecting against a loss, and later capture an additional move)

 

JS
jsulus · 9 years ago

Thank you man!!!!!

80
8088297 · 9 years ago

Amzing!!
Thank you sir

AK
akkoakko · 9 years ago

Hi Im New to Ctrade Can Anyone tell me what should I do to setup this Bot because Im back testing it and showing no results for almost 2 H 

thanks 

SwapBridgeCapital's avatar
SwapBridgeCapital · 9 years ago

You can use trade copier from ctrader to your mt4, but I don't see the reason to do so because this platform is better for news trading.  

David's avatar
David · 9 years ago

kestkam - October 08, 2014 @ 12:03

Anybody tell me please if I can use the News Robot on my MT4 platform? If it's possible how can I do that?

no. cTrader bots cannot be used with mt4.

 

 

95
9570316 · 9 years ago

@Algotrader.

First, thanks for your job. :)

Then, can I ask you something...What and where should I write in your source code to have a daily repeat of the action?

For example, if I want the same parameters repeat every day at 7pm? Like if I have the same news every day at the same hour?

I know it s sound unusual, but you can imagine that I have my reason. And I will share it if it works.

Thanks in advance.

MO
moneyfred2014 · 10 years ago

Installed on two pairs and it executed a few buy and sell orders, none of which were successful. The log message is that they "expired". I use the default settings. Any hints?

ME
megamemo · 10 years ago

by the way man thanks the other time for the help with the bot i when the 3th place on that contest thanks to your bot!!

ME
megamemo · 10 years ago

hi one question again man this robot shoot the orders until it gets a server confirmation or do not?

have a nice day!

kestkam's avatar
kestkam · 10 years ago

Anybody tell me please if I can use the News Robot on my MT4 platform? If it's possible how can I do that?

95
9541321 · 10 years ago

Hi there. I´m in Portugal so time zone is UTC+1. It wont work when I place this in the bot. Any ideas on the correct time zone configuration? Kind regards

95
9541321 · 10 years ago

I need help... The system makes the orders, but then deletes them immediately. What is up? How can I solve this problema?

L0
L0pg · 10 years ago

BigStack,

I am running this on a SUPER micro account, I took 3$ up to 35$, then got a 22 pip slip on stop loss, and went back to 3$. One trade after that massive loss and it is back to 6$. So, I will continue my experiment until I am rich beyond my dreams (lol) or until I implode the account trading as much as I can at 1:500. Either way, I only risk 3$.

L0
L0pg · 10 years ago

Tosabrown,

 

You are missing the point, they are PENDING orders, waiting for the initial move so you don't have to pick buy or sell. It sets both orders, and whichever is triggered gets the pips.

BigStackBully's avatar
BigStackBully · 10 years ago

Results??

Hey Guys,

Jompa asked Dec 2012 for results. Would be my #1 question, too.

MyFXBook real money account? Or at least demo? Backtests?

thx

 

 

KA
kaffum · 10 years ago

the only lines showing is the pip away lines, 

KA
kaffum · 10 years ago

Hello, algotrader, how do I set up this robot, it seems it unable to execute orders during news times

TO
tosabrown · 10 years ago

THIS ROBOT IS GARBAGE

What's the purpose of it when it hedges in two directions? You should have separated the buy and sell into separate robots. Or you could have made it into one robot but allowed the buy and sell to be changed by the user. I really don't see the purpose of a robot that initiates a trade in opposite directions by the same number of pips. The least you could have done is make the take profit pips adjustable on each side. I'm surprised no one one this thread brought these things up.

ME
megamemo · 10 years ago

hi great im startimg to really love it but would be grat if you put a trailing stop or breakeven 

BA
barrenwuffett · 10 years ago

it's also missing the day to trade field 

BA
barrenwuffett · 10 years ago

Could you please add a custom label field to this?

algotrader's avatar
algotrader · 10 years ago

News Robot has been updated. Now you don't need to specify TimeZone. Robot also prints remaining time to chart.

ME
megamemo · 10 years ago

hi to everyone im neewbie on the bot side and 2 years of trading wich i love it and i can tell you how great work you got here this is beautyfull people sharing there passion one cuestion about changing the time zone i know where to put it but i dont know what shut i write im form venezuela and is caracas time i will really thanks if someone cut helpme and else what framework and pair do you people of here find it more profitable thanks again 

JE
jeed2424 · 10 years ago

Sorry, but I don't see it working... Is this normal?

 

JE
jeed2424 · 10 years ago

Hey, I tried different ways to write my time zone, but it doesn't seems to work.

*I live in Canada: Eastern Canadian time zone

10
1023881 · 10 years ago

Thanks a lot...I will let you know the outcome

 

 

algotrader's avatar
algotrader · 10 years ago

In Australia you need to specify one of these time zones: CenAustraliaStandardTime, EAustraliaStandardTime, WAustraliaStandardTime.

10
1023881 · 10 years ago

Hi there,

I'm from Australia (Sydney) and tried your robot but didn't trigger the trade. I tried to change the time zone to Australia and Eastern Australia time zone in the parameter but there is an error coming up which say "does not contain the definition for Australia or Eastern Australia".

 

thanks

TI
tilo10 · 10 years ago

Can you please tell me how I can add "Trailing Stop" to this Robot ,Thanks

you can reply to   " salau31@yahoo.com " .

TE
tete13 · 10 years ago

Hi algotrader,

 

Can you add Modify open price function to Robot?

Let's assume we want to open an order with 10pips away from current price, however there is not too much volatility and price just moves less than 10 pips. I think it'll better if we can modify our open price. I mean the open stop order price will constantly be modified and be 10 pips away from current market price, and our order will be filled in case PRICE MOVES EXCEED 10 pips.

Thanks.

kestkam's avatar
kestkam · 10 years ago

Hi guys,

Let  me ask you, why are you proposing the cbots which are not finished. Just take the News Robot and try it in your demo account and you will see that without resolving the slippage problem it's absolutely unuseful and even harmless. I tried it just a few times and one time I got the slippage of 11 pips another time the slippage was 6 pips. Any trader knows that in the news trading a trade opened with more than 2 pips slippage usually (with probability of 90%) went against you.

Guys, please work out the News Robot adding the slippage parameter in or take it out from here. The News Robot as it stands is just seducing traders. Sorry for saying that but it's true.

kestkam's avatar
kestkam · 10 years ago

Hi,

If anyone knows programming language #C please let me know how to add a new parameter "Slippage" into the code. Unfortunately, I am not familiar with codes. As I wrote above the ''Slippage" parameter was extremely important in the news trading. Please guys help me. Thanks in advance.

kestkam's avatar
kestkam · 10 years ago

Dear algotrader,

Could you please change the Code adding a new Parameter there? When economical events come a market volatility is quite high thus the Slippage is a very important parameter in the News trading. So, in my opinion the Max. Slippage should be set. I suppose if the Slippage exceeds 3 or 4 pips the order shouldn't be filled. At least it would be fine to have such a possibility.

I used this bot with NZD/USD pair and got the slippage of 11 pips.

kestkam's avatar
kestkam · 10 years ago

Hi,

I suppose some traders used this News Robot in their real account for quite long time. Please provide any comments on the reliability of this bot. Thanks.

algotrader's avatar
algotrader · 10 years ago

Instead of UTC+1 you need to specify the time zone name. For instance, CentralEuropeStandardTime.

TI
tilo10 · 10 years ago

please help, when i add my local time UTC+1 ,This is error message, Error CS0182: An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type

aisaac's avatar
aisaac · 10 years ago

How to get news about ctrader? I use a demo account.

ex.: 

  • News Hour - Hour when news will be published
  • News Minute - Minute when news will be published

etc.

HU
huyanji · 10 years ago

Hi , I really want to say this is a really good EA code. 

Thank you.

 

However, I just transferred  from MT4, so I have got 2 questions:

1. If someone entered the WRONG time-to-run this robot, How could they cancel this appointment in cTrader platform?

2. Where is the Trailing Stops (Which means: If the news is NOT QUITE important , the candle - bar will moved-back. So I suppose  we change the  take-profit to as low as 30 pips, if the candle-bar of GBPUSD dropping-down quickly from 1.5830 to 1.5820 after news released, then come back to 1.5830; but now the position is still open, so what should we do without the Trailing Stops Parameter?

Thanks again for this EA.

I like this EA sooooo much!

Yours,

Yenchy

You can reply me via Email: Yenchy@yenchy.com

DR
drewski · 10 years ago

Cheers :)

algotrader's avatar
algotrader · 10 years ago

put TimeZone = TimeZones.NewZealandStandardTime

DR
drewski · 10 years ago

Hi there. Hey we are in New Zealand so time zone is UTC+13. It wont work when I place this in the bot. Any ideas on the correct time zone configuration? Cheers

algotrader's avatar
algotrader · 10 years ago

News Robot is updated

CH
chiripacha · 10 years ago

Hi, how can I correct the following 4 errors ("ist veraltet" means = "is outdated")

Please can you help me?

Error CS0618: "cAlgo.API.Internals.ITrade.CreateSellStopOrder(cAlgo.API.Internals.Symbol, int, double, double?, double?, System.DateTime?)" ist veraltet: "Use PlaceStopOrder instead"

Error CS0618: "cAlgo.API.Internals.ITrade.CreateBuyStopOrder(cAlgo.API.Internals.Symbol, int, double, double?, double?, System.DateTime?)" ist veraltet: "Use PlaceStopOrder instead"

Error CS0618: "cAlgo.API.Internals.ITrade.DeletePendingOrder(cAlgo.API.PendingOrder)" ist veraltet: "Use CancelPendingOrder instead"

Error CS0618: "cAlgo.API.Internals.ITrade.DeletePendingOrder(cAlgo.API.PendingOrder)" ist veraltet: "Use CancelPendingOrder instead"

SA
Sathiya_Cool · 10 years ago

all robots are working properly. but news trading robot not working. plz help me ;-(

QW
qweqwe96 · 10 years ago

Beijing time Chinese, should be in "EEuropeStandardTime" fill in what, please enlighten. Thank you.

 

CH
chiripacha · 10 years ago

New Trading API[#1]

[Spotware]posts: 185since: 23 Sep 2013

In the new version of cAlgo we added a new trading API. The main advantage of this new trading API is the ability to choose between Synchronous and Asynchronous trade methods. The previous API allowed asynchronous methods only and although it is rather flexible, it is difficult to deal with on occasion, because one needs to implement more methods in order to handle some situations.


Question: Is the "News Robot" updated referring to this news?

algotrader's avatar
algotrader · 11 years ago

bukk530, MarketDepth.Updated event happens more often than OnTick event

bukk530's avatar
bukk530 · 11 years ago

Nice done! Can you please explain me if there is a particular reason why you are using the MarketData Update event instead of the OnTick function? Thanks!

algotrader's avatar
algotrader · 11 years ago

You can specify desired timezone in the code (see image #2)

Mocean's avatar
Mocean · 11 years ago

Is time calcualted from Ticks or Server/Local time?

algotrader's avatar
algotrader · 11 years ago

mrlilkkk, I've updated the description. Please look at the first image. Also now it is possible to specify time zone for the robot.

MR
mrlilkkk · 11 years ago

does the take profit set the specified amount of pips away from the market price  at the time the orders are placed or the specified amount of pips from the order price?

algotrader's avatar
algotrader · 11 years ago
UTC+0
AD
AdrianC52 · 11 years ago
Sorry for a noob question. For the news time, is it follow UTC+0 or broker server UTC+3, or my user time UTC+8. thanks in advance to any kind heart who reply!
ED
Eddie_Morra · 11 years ago
Oh no, sorry, was my fault, working properly, thank you for the robot
ED
Eddie_Morra · 11 years ago
Hi @algotrader , the bot isnt working anymore, since yesterday this isn't working anymore, I don't know why, can you help me please?
algotrader's avatar
algotrader · 11 years ago
Updated. Now it reacts on changing of DOM, because such event is more frequent than tick.
MaXeY's avatar
MaXeY · 11 years ago
Hello 1st thanks for sharing this EA, am still testing on demo i have a note.. can you please ADD Trailing Stop option on the robot
JO
Jompa · 11 years ago
Have anyone used this robot? Would be nice to share experiences of results and ideas about changes. Please email to forslundaren@hotmail.com
odomike's avatar
odomike · 11 years ago
Thanks Zenner. Corrected and working properly now.
algotrader's avatar
algotrader · 11 years ago
Thank you Zenner, I've changed it and it is waiting for moderation.
ZE
Zenner · 11 years ago
Hi I do not know if this has been fixed but in the issue is in the call to CreateBuyStopOrder because the takeprofit price is the same as the BuyStop and that is not possible. So if you change the code to: Trade.CreateBuyStopOrder(Symbol, Volume, buyOrderTargetPrice, buyOrderTargetPrice - StopLoss * Symbol.PipSize, buyOrderTargetPrice+ TakeProfit * Symbol.PipSize, expirationTime); it should work
odomike's avatar
odomike · 11 years ago
I always get this error while the News bot is trying to place the buy stop order "YOUR REQUEST TO BUY STOP ORDER FOR 10K OF EURUSD WAS NOT SENT DUE TO TECHNICAL ERROR" What could be causing this? It places the Sell stop order successfully all the time though.
odomike's avatar
odomike · 11 years ago
This is what I have been waiting for so long. You really dont know how grateful I am to you for this robot. Time to start trading the news on my cAlgo. Thanks a million buddy :)