cBot Robot_Forex & SendNotifications

Created at 27 Jan 2014, 22:30
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
Forex19's avatar

Forex19

Joined 13.06.2013

cBot Robot_Forex & SendNotifications
27 Jan 2014, 22:30


Hi all, 
with reference to this cBot: 

/algos/cbots/show/225 

after the line 131, I added these lines of code: 

switch (Account.Positions.Count)
            {
                case 1:
                    Notifications.SendEmail("from@somewhere.com" , "to@somewhere.com", "RF P1", "Position 5k Open");
                    break;
                case 2:
                    Notifications.SendEmail("from@somewhere.com" , "to@somewhere.com", "RF P2", "Position 10k Open");
                    break;
                case 3:
                    Notifications.SendEmail("from@somewhere.com" , "to@somewhere.com", "RF P3", "Position 15k Open");
                    break;
                case 4:
                    Notifications.SendEmail("from@somewhere.com" , "to@somewhere.com", "RF P4", "Position 20k Open");
                    break;
                case 5:
                    Notifications.SendEmail("from@somewhere.com" , "to@somewhere.com", "RF P5", "Position 25k Open");
                    break;
                case 6:
                    Notifications.SendEmail("from@somewhere.com" , "to@somewhere.com", "RF P6", "Position 30k Open");
                    break;
            }

to be able to receive email at the opening of each new location. 

But I would like to receive emails with a string similar to the one shown in this example: 

/forum/calgo-reference-samples/2237 

with info: Entry Price, Direction, Vol. 

How to change the code? 

thanks


@Forex19
Replies

Spotware
28 Jan 2014, 11:09

To be able to receive email at the opening of each new position you would have to subscribe an event that is triggered on opening of a new position:

    protected override void OnStart()
    {
        Positions.Opened += PositionsOnOpened;

    }

Then use code similar to that example to send a notification in the subscribed event:

    private void PositionsOnOpened(PositionOpenedEventArgs args)
    {
        Position position = args.Position;
        string emailBody = string.Format("Position {0} {1} Opened at {2}",position.Volume, 
                                         position.TradeType, position.EntryPrice);
        string subject = string.Format("RF P{0}", Positions.Count);
        Notifications.SendEmail("from@somewhere.com", "to@somewhere.com", subject, emailBody);
    }

 


@Spotware

Forex19
28 Jan 2014, 17:57

RE:

Spotware said:

    private void PositionsOnOpened(PositionOpenedEventArgs args)
    {
        Position position = args.Position;
        string emailBody = string.Format("Position {0} {1} Opened at {2}",position.Volume, 
                                         position.TradeType, position.EntryPrice);
        string subject = string.Format("RF P{0}", Positions.Count);
        Notifications.SendEmail("from@somewhere.com", "to@somewhere.com", subject, emailBody);
    }

 


Code added, so good.

It should however replace

string body  

with

string emailBody

Thanks, good job.


@Forex19

Spotware
30 Jan 2014, 10:33

Thank you. It has been corrected.


@Spotware