How to add close cancel button excel trading pepperstone

Add a cancel/close all button using Pepperstone

One of the first pieces of functionality I like to add to a demo trading sheet, is a cancel/close all button. I normally make it big and easy to press!

This button will cancel all pending orders and close out open positions. This is very useful for demo accounts and testing your trading system as a quick way to reset the sheet. Remember that your P&L will naturally change when you close out your positions.

To achieve this with Pepperstone, you will need to dive into some code.

 


This post assumes you have set up Metatrader with the Pepperstone Excel RTD Expert Advisor. If not, go through this post first and come back when you’re done.

If you don’t have the Developer options available in Excel yet, go through my other post here and come back when you’re done.

Add a button to your sheet using the Developer Tab->Insert->Button
and click on your sheet to place the button

Add a button to Excel trading sheet
Adding a button through the Developer Options

Resize your new button using the corner size controls.

Cancel button in Excel trading sheet
resize the button

Right-click on the button and select Properties.
Set a name for the button, choose a background colour, font and foreground colour for the text.

set the name, background and foreground settings

Right-click on the button and select View Code

The VBA Editor will open with your new code macro

Cancel orders with Excel Pepperstone VBA

Paste the following code into your new function

Set cmd = CreateObject("FXBlueLabs.ExcelCommand")
    res = cmd.SendCommand(Range("AccountNumber").Value, "CLOSEALL", "", 20)
    ' use this to view the result:  Sheets("Trading").Range("AA5").Value = FormatDateTime(Now, 4) & " - " & res

Test your button

Ensure that you are not in Design mode using the Developer menu. Design mode will look selected like this:

Excel VBA design mode trading Pepperstone
Design mode in Developer menu

If you need to, click on Design mode to turn it off.

You are now ready to test out your big red button!

Posted in HowTo, Pepperstone.

4 Comments

  1. Greetings, I do believe your web site could possibly be having web browser compatibility problems.

    Whenever I take a look at your site in Safari, it looks fine however, when opening in IE, it has
    some overlapping issues. I merely wanted to give you a quick heads up!
    Apart from that, wonderful blog!

  2. I do not know if it’s just me or if perhaps everybody else experiencing problems with your site.
    It appears as though some of the written text in your posts are running
    off the screen. Can somebody else please comment and let me know if this is happening to them as well?
    This could be a problem with my web browser because I’ve had this happen previously.
    Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *