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
Resize your new button using the corner size controls.
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.
Right-click on the button and select View Code
The VBA Editor will open with your new code macro
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:
If you need to, click on Design mode to turn it off.
You are now ready to test out your big red button!