New DebugConsole for Snippets

Author: Mark Fric

January 30th, 2016

Rating:
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading...

DebugConsole was added in version 4.10 to allow for easier debugging/logging during Snippets development. It is very simple to use and allows you to see what’s going on “behind the scene” when your snippet is executed.

Debug console is available from the toolbar:

This displays debug/log console that displays both normal program logs and a special debug messages.

How to use it

Before using it add include of this package to the beginning of the snippet, for exmaple


import com.strategyquant.lib.snippets.WhatIf;
import com.strategyquant.lib.debugging.DebugConsole;

public class ByDirection extends WhatIf {

Now you can call method DebugConsole.log(“category”, “message”); that will send this message with given category to a debug console.

Let’s add some debug message to a WhatIf snippet ByDirection.java, that can filter teh trades by direction:

public void filter(SQOrderList originalOrders) throws Exception {
    int direction = getStringParameterValue("Direction").equals("Long") ? SQConst.ORDER_BUY : SQConst.ORDER_SELL;
    int count = 0;

for(Iterator<SQOrder> i = originalOrders.listIterator(); i.hasNext();) {
count++;
SQOrder order = i.next();

DebugConsole.log(“WhatIf-direction”, “Order number #”+count+” has direction: “+(order.Type == SQConst.ORDER_BUY ? “Long” : “Short”));

if(order.Type != direction) {
i.remove();
}
}
}

After you’ll run WhatIf case on some strategy you’ll see the following output in the debug console:

< Previous: List of programsNext: Getting started extending the programs >

0 Comments
Inline Feedbacks
View all comments