17. 1. 2022

5 3

Debug a variable in AlgoWizard

If we create a template or run a strategy in AlgoWizard, we need, sometimes, to output the variable on a log to be able to debug it.

We have this fdebug function in the CodeEditor, we needed a similar function in AlgoWizard.

 

Here is a function fDebug to output the variable to a log file.

 

1/    To install it, we need to import this SQExtension V2 in the CodeEditor and restart SQX.

2/    To run it in AlgoWizard, just click on “Add rule” , select If Then / OnBarUpdate   (please see Capture4a)

 

In the if conditions, select the condition where the function will print the variable to the log

please see “Capture4a” and “Capture2a” attached

 

In Then Action ,  assign a variable with the function Debug. We can select this function as we edit a new condition 

please see “Capture3” attached

 

This function is using the fdebug function in java to output it to the log of StrategyQuant in this directory : “\StrategyQuantX135\user\log\StrategyQuant”

An example of output is

19:51:54.087 [Blocking computeThread common #26 – Builder_2-Generation 3.0.61] INFO c.s.tradinglib.debug.Debugger – fDebug – Var : 0
19:51:54.087 [Blocking computeThread common #17 – Builder_2-Generation 3.0.43] INFO c.s.tradinglib.debug.Debugger – fDebug – Var : 0

 

 

I attached an example of strategy with an debug rule, you have to replace variable6 by any variable you want to watch. (Variable6 is only an empty variable to show this example)

 

You can activate the Debug mode on by switching the “DebugModeparameter to 1. StrategyQuant will slow down to write the log to the hard drive.

You can desactivate the Debug mode on by switching the “DebugModeparameter to 0 to let the computer run.

(In AlgoWizard see “Capture5” and    In the retester see “Capture6-7-8-9” attached to change the parameter of a strategy)

 

I hope this will help the StrategyQuant Community.

 

package SQ.Blocks.Functions;

import SQ.Internal.ValueBlock;

import com.strategyquant.lib.*;
import com.strategyquant.datalib.*;
import com.strategyquant.tradinglib.*;

@BuildingBlock(name="(Deb) Debug", display="Debug(#varName# , #Value#)", returnType = ReturnTypes.PriceOrNumber)
@Help("Log to file VarName , Value")
@SortOrder(1700)
@IgnoreInBuilder

public class Debug extends ValueBlock 
{

    @Parameter(defaultValue="Var : " )
    @Help("Name of the Variable")
    public String varName;

    @Parameter
    @Help("Value of the Variable")
    public IBlock Value;

    
    //------------------------------------------------------------------------
    
    @Override
    public double OnBlockEvaluate(int relativeShift) throws TradingException
    {
        fdebug("Debug ", varName + Value.evaluateBlock(relativeShift));
        return 1;  
    }
}

 

Subscribe
Notify of
3 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
ytu
ytu
29. 12. 2021 11:23 pm

It seems Capture 8 and 9 are the same.
Can you please re-upload the images?
Thanks much.