Coding chat transcript from 18/11/2021

Thanks again to all the participants of the last coding chat.

The next coding session will be on 25th November at 14:00 CET time, which is 13:00 London time, 8am New York time, 5am San Francisco time, 0:00 am Sydney Time.

All people who filled the coding session interest form will be notified about every next session (until they unsubscribe from session mailing list), if you want to get an invitation, please fill the form here.

Transcript of coding session – it is not 100% match, it is filtered and grouped by the question theme for better reading.

 

 

beetrader
is it possible to change the colour coding on the correlation matrix, extreme negative numbers are shown as green. I want to have the same colour shades as the positive numbers when the negative move away from zero. Is there are way to do this in the code?

Mark – SQ
I believe it is not possible to change the colors right now, they are hardcoded
but I understand. everything is in principle possible to customize, including the colors in the correlation matrix table, but we cannot dd configuration to every single thing in the program. I doubt there will be a lot of other users who would benefit fro this feature, so it has a small priority for us. We must focus on more important things with the biggest impact

 

 

beetrader
I want to implement a database for saving the xml results, are they any changes you expect in the next few months or I am safe saving them in current specification?

Mark – SQ
no, XML should not change. It can be extended (new tags or attributes) but it shouldn’t affect any code that is processing it

 

 

beetrader
are we able to have a different price data source other than the ones in the ones listed in the data manager e.g. can I consume prices from a mongodb or sql db?

Mark – SQ
this is not easily extendable right now. the simplest solution for now would be to export the prices from your DB into a CSV format, you can then easily import any CSV format into SQ

 

 

sebasfiorent 
Just looking how to implement a FormulaBlock to implement fixed Amount in (USD/EUR,i.e. account currency) for TakeProfit

Mark – SQ
it should be a formula in SQ.Formulas.SLPT package. But to be honest we haven’t tried extending this part externally, there are some dependencies that could make a problem – you can create a new formula in SQ, but you’d need to add also its “translation” to MT4/5 MQL and/or TS EasyLanguage to make it work in the final generated code for these platforms

 

 

beetrader
open ended question: There are a few John Ehlers indicators in the SQX, are his other signal processing based indicators difficult or impossible to implement in SQX?

Mark – SQ
they are possible to be implemented, there just wasn’t time to do it. There are thousands of possible indicatrs that could be implemented in SQ, we picked the ones we prefer. We are adding a few now and then

clonex
This should be not problem

It is not so hard. Pls Send me here indicators from Ehlers you meant to have implemented.
I have something in process of work Autocorrelation , something is done ( Reflex ) but there are many possible.

beetrader
ok thanks, we can implement some of them. Maybe what I wanted to know is a list of gotchas to watch out for. Like if you know something definitely doesn’t work when trying to implement them, then it’s useful for the SQX power developers/extenders to know beforehand.

Mark – SQ
I’m not sure if there are some gotchas in implementing the indicators if they are not some special multi-timeframe indicators.
Indicators in SQ are quite simple, their logic is similar to NinjaTrader C# indicators – I recommend you to look for NT indicato rimplementation, it could be very simple to convert this to SQ

beetrader
great thanks, that’s a gotcha

 

 

beetrader
Is there a way to extend SPP so that it uses the median profit and not average profit?

Mark – SQ
I’m not sure what you mean, SPP doesn’t use median or avg value to pick the parameter value, but it looks for the most stable region

beetrader
Do I need to raise a change request or its too complicated to change on current architecture?

beetrader
I have marked on picture

Mark – SQ
I see, it is not SPP but Optimization profile. The average is used there because it is used in the original paper, also standard deviation is usually measured from average. I’m not sure how it would behave in case of Median

beetrader
Of coz I understand. The problem is that since SPP is based on median values, are we not then over and under estimated when we switch to using the average profits and not the median profit. I can play around with settings to find the best StdDev numbers so its not a high priority item.

 

 

beetrader 
Did you manage to find a way to implement Martingale in QuantAnalyser?

clonex
Understand 1) easier way it to implement it in what if scenarion where you can loop troght orderslist 2) harder way is to do this in money management plugin in QA

 

 

beetrader
I would like to ask if there is any readymade metric (like sharpe, or sqn), which would claculate stats on more frequent “mark to market” pnl, than just completed trades.
For example in equities space is pretty standard tp do daily marking to market for multiday trades and calculate Sharpe ratio from daily PNL.

clonex
You mean something like : Compute Sharpe for last 20 trades?

clonex
Not yet and truly this is not priority for me. There are much more better things in front of us with all due the respect
Actually im working on what if snippets:
1) one will detect max DD in IS train/or test – then it will stop trading if DD treshold will be reached in OS
2) Simulation of equity trading in what if ( together with account control snippets in MT4/MT5 (( they are done but not relased )

beetrader
yea I know you are snowed under. I just need guidance on how to refer to previous trades in QA code,

Mark – SQ
no, there is no such metric In SQ we compute metrics only after the strategy backtest, so it doens’t haveaccess to every move in the trade. It stores MAE/MFE, this can use used to compute this kind of metrics to some extent

beetrader
he means while a trade is open, he wants the in-play statistics like this MAFE https://strategyquant.com/codebase/mafe-profit-factor/

os
I mean computing it from daily pnl for example, including “unrealized” part

Problem with all “risk adjusted returns” metric in SQX I found (sharpe, sqn, return over dd) is that you can have some “broken” strategy which stays in some loosing position long term (weeks, months), it can have huge unrealized drawdown (like 50%+), but of you calculate your statistics (sharpe) just from realized PNL (not marking to market), it will look unrealisticly good..

@beetrader yes, something like MAE is workaround. This is what I am using now as a fitness function, some combination of return, sharpe/sqn and MAE.
This is fine, but I would like to implement something better ideally..

clonex
I don’t know how to do this at this moment but i did plenty unreleased snippet with MAE / MFE , I don’t know how to do this now
Overall edge ratio , mfe , mae analysis can tell us a lot much more then ive expected
Pls keep this question for mark for tomorrwov @os os.

clonex
Im not sure if this is possible in QA now. There are missing in MoneyManagementTypes package
It should be possible to track order before as an instance variable i really dont know

os
Ok thanks.

For example this question and first answer is exactly about that problem..
It make sense to look at unrealized pnl (opened trades pnl) daily, because otherwise you can have opened trade for a year and don’t see what happen in the meantime with your account value from your statistics..
https://quant.stackexchange.com/questions/9935/calculate-daily-returns-for-sharpe-ratio

clonex
Or mybe it is possible

 

 

martinx
(translated by Mark) Is there a function that measures how many seconds the bar lasted ? I want to use it for range and volume bars

Mark – SQ
martinx – please in English only. no, there is no function that measures how many seconds the bar lasted. I’m not even sure there is this kind of information stored for volume and range bars

martinx
function exist in standart platform(i am using tradestation or multicharts) for instance in ms ,in your platform isnt way measure this basic stuff? thanks

Mark – SQ
ok, I understand. I’m not 100% sure now, but the times in SQ are also stored in miliseconds. So the times you are showing should be accessible from Time block/series. S you need to make only Time(0) – Time(1) to get a difference between previous and current bar

 

 

EmmanuelE
I would like to create multiple positions strategies, like multiple Buy/ short,
hedging position. Where can I develop this snippets in the CodeEditor ?

I see we can create a new “Order Action” or is it a new “Money Management” ?

Where can I develop a trade management with multiple position ?

Mark – SQ
you can open multiple orders using Enter At Market/Stop/Limit. It is not done this way in standard strategies, but when you create the strategy logic you can do it in AlgoWizard editor.
Making snippet for it in Code editor is not that simple

EmmanuelE
I saw it in the algowizard but not in the code editor

Mark – SQ
yes, you can create a new Order Action snippet, but you’d have to add also the way how to translate it to MT4/5 or EasyLanguage code – whichever you use.
CodeEditor is for development of trading blocks, I don’t fully understand what you want to make. It should be easy in AlgoWizard by adding more EnterAtXXX blocks

EmmanuelE
do we have an example of new order action snippet ?
how do we add it to the translator in easy language ?

Mark – SQ
you can look at EnterAtMarket, and there is a source code for every building block in Code Editor – package SQ.Blocks.Order.Open

look at example of adding an indicator, the principle is the same: https://strategyquant.com/doc/programming-for-sq/adding-envelopes-indicator-step-by-step/#adding-pseudo-code-template-for-a-new-block
it is a step-by-step tutorial on how to add a new indicator block to SQ.
all the templates for all building blocks are defined in Freemarker language in Code section

EmmanuelE
for example, I would like to be able add an hedging position , when SQX look for strategies (not in algowizard)

or more
I developped multiple trade management strategies . I
would like to add them in SQX
in the code editor

Mark – SQ
there are generally two ways:
1. create custom snippets – indicators, order actions – that would deal wit this, but this is quite complex
2. create your own strategy template – SQ can then generate strategies based on your template
https://strategyquant.com/doc/strategyquant/strategy-templates/

EmmanuelE
I am willing to develop customs snippets.

Mark – SQ
All the default blocks in SQ have their full code in Snippets in Code Editor

EmmanuelE
I am studying each one

EmmanuelE
if I create a template in a algowizard with multiple position, it will not allow to create strategy in SQX with random indicator strategies
the only solution it to code it is the code editor

I willing to try templating to start

if I create a template in algowizard with multiple positions, it will not allow to create strategy in SQX with random block indicator strategies, only the indicator selected in algowizard

the only solution it to code it is the code editor

Mark
I don’t see why it shouldn’t work with templating, I believe it is possible.

 

 

Poker1
Hi How do I import indicators from tradestation (easylanguage) to SQ.
does any additional coding required (or can I copy paste from TS?

Mark – SQ
I’m sorry, it is not that simple. TS uses EasyLangiuage and SQ uses Java. So any indicator you want to transfer has to be implemented in SQ.
you can do it alone, or you can ask/order this kind of service from somebody – maybe clonex

Poker1
Ok. Because I have a couple of indicators that I would like support with.
If it works for Clonex?

Mark – SQ
you can ask Clonex:
Contact Ivan Hudec StrategyQuantX consultant
Fill out this form.

 

 

oliverhowton
the post https://strategyquant.com/doc/programming-for-sq/example-per-databank-custom-analysis/ does this function replace functions in quant analyzer. ive tried to save a particular run from a walk forward matix test in a csv file and importto quant analyzer but its not possible so am a little lost to the benefits of this feature? thanks

Mark – SQ
Oliver, this example is for StrategyQuant, it wouldn’t work in QuantAnalyzer. I haven’t programmed for QA for some time, but you should be able to do something similar with Scripter in QA – select strategies in databank (or load them from disc) and then do something on topn of them.
What exactly do you want to do?

oliverhowton
so ive found a stable run/params settings in a walkforward and so the unique equity curve i want to import to quant analyzer but the csv file when trying to import to QA does not work….. any ideas how i can achieve this? thanks

Mark
ok, I see now. the problem is that QA only loads the main result from strategy, not WF results.
I think there is a solution, but not a simple one.
In SQ you can go to List of trades for your given WF result, and export the trades to CSV file
in QA you can then load this list of trades. The only thing is that you’ll need to specify a custom format: https://strategyquant.com/doc/quantanalyzer/formats-supported-in-quantanalyzer/#format-specification
but you need to do it only once

I already added the custom format in the comment to your task: https://roadmap.strategyquant.com/tasks/sq4_8403
The added format is:
Format.4.SkipRow=1
Format.4.Separator=;
Format.4.DateFormat=yyyy.MM.dd HH:mm:ss
Format.4.LineFormat=Unused,Symbol,Action,OpenTime,OpenPrice,Size,CloseTime,ClosePrice,PL,Unused,Unused,Unused,Unused,Unused,Unused,Comment

beetrader
From looking at your result file I think its best to just get the optimum settings you have found and rerun the strategy in AW, save your file as new filename and then import into QA. That way you don’t get the other stuff because QA is treating your results as a portfolio. and then you can easily see or analyse your results which I have marked with the arrows in the chart.

oliverhowton
thanks. ill take another look. yes the issue is i plan to reoptimize my strategies and the wfm advises to use certain settings into the future for future data settings which i plan to use. this equity curve which has been optimized in succession i plan to compare with others so i can build a portfolio. and so its not possible to construct appropriately. the only way i can work out is to replicate the settings on the wfm time period and step through each period with the settings and combine in a portfolio to get the true back test but this seems like a lot of work for just one strategy

Mark Fric

Mark Fric

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Emmanuel
Emmanuel(@emmanuel1)
November 27, 2021 4:43 pm

this is helpful to read again the answer

Continue reading

An interview with succesful trader Grant

Kornel MazurNovember 16, 2021

There is always a big story behind when someone achieves success in markets. I am glad for the opportunity to share with you an interview with trader Grant who is …

Coding session transcript from 26/10/2021

Mark FricNovember 12, 2021

The first coding session was a successful experiment, thank you EmanuelE, beetrader, clonex for your questions and the chat. We will continue with coding sessions it will be bi-weekly, always …