I wanted to post some past
ADL logic suggestions for capturing data sets over user defined time intervals.
This kind of logic is very useful when creating Technical Indicator type
calculations and behaviors:

- -
**MIN of the MIN’s of the past ‘x’ bars, with 'x' being a user-defined variable.**

Basically, the trick
is to use a Value Bucket (VB) Block with internal setting Store Type set to
'Last' along with a 'Bucket Hole Formula' input for the VB Block that is a modulo, or in this example you are setting this as the “result output” from the DivRem
calculation in the Math Block. Modulo is a mathematical function that outputs the
remainder when you divide total bars by window. For example, let's say the
look back window is 5. If 4 bars have completed: 4 / 5 = 0 r 4 so the output of
this calc is 4. Now let's say 23 bars have completed: 23 / 5 = 4 r 3 so the
output of this calc is 3.

If you use this as
your Bucket Hole Formula input in the VB Block, then you will be *replacing *old
values (b/c of the 'Last' setting) such that the last x min values are always
stored, though not in the correct order. However, this doesn't matter since the
min of a set of values is not determined by their order! As an example, if
look back window is 5 and the 6th bar has just completed, 6 / 5 = 1 r 1 such
that the 6th bar will be stored in the 1st slot, replacing the 1st bar value.
Now, the VB block has stored the 6th, 2nd, 3rd, 4th, and 5th values in that
order. This will continue on infinitum.

Finally, downstream
from properly populating the VB Block, you can run a Loop Block that checks all
values in the VB Block by using the Loop Block's 'CurrIndex' as the Hole input
for the VB Block. Use the discrete message from the Loop Block to trigger the
capturing of the VB Block value in a Discrete Min Block. After the Loop Block
has completed, you can use the Exit output from it to trigger a Value Extractor
Block to capture the Discrete Min's output which will at this point be your
desired value.

*Please keep in mind that this stores the
last x values in the VB Block in the wrong order so certain computations can be
effected by this (for example an exponential moving average). Min and max are
OK here.*

In the below screen shot example of the logic, you will see it is set
for a look back period of 4. You can see how the values are logged and stored.

thub.nodes.view.add-new-comment

modulo.jpg
(241.9 kB)

How do you get the preview of your picture to appear?

I use the "Insert Image" Icon from the Text Window when replying to a post

Aha. Thank you again, kind sir. I was using the paperclip icon next to it. "Missed it by... that much."

Great post! I am trying to follow your advice but keep getting a NAN error on my Discrete MIN blockvb-

I have the time interval set up to shoot a message every so often. That message goes to a "counter" (Value Accumulator set to 1). Goes to the DIVREM block to be calculated and goes to the VB MSG input port. VB value formula is referencing the value extractor block labeled "Trade Price" above. The loop block is set up per your instructions, I think. I can't see what I am doing wrong. Can you see the error in my algo?

Thank you

vb-modulo.png
(76.2 kB)

Your Discrete MIN Block 0 that is down stream from the Loop Block output is also being "reset" after each time trigger interval. Meaning you will always visually see on the canvas that NaN output. If you were to log or record the output of that block, you would see it is capturing a value. If you look in my screen shot example...... look at the "LOWS Output" logged value.

I have found out what the issue is. The loop block CurrIndex is not updating. Could this be a glitch? Or is my configuration wrong?

The way you have it set from your screen shot..... nothing looks wrong. You have a look back period of 10. So that means you will have 9 output/updates from the "CurrIndex" output value. On the 10th..... you will trigger the Exit output discrete message. Then you start all over again. But now if you notice in the DivRem calculation out puts..... your top output value will now show a value of 1, because you have gone through 1 complete "lookback period".

Thanks for all the help Damon. It's a problem with the Loop Block in Xtrader. I built the algo on the web version and it seems to work fine. I sent the issue to support.

I built this and it works until the loop block resets i.e. when the 6 period begins.

It seems like when the DivRem resets to 1 it will send one loop through the Discrete Min block before exiting. This means that the Discrete Min block will only capture the value associated with key hole value 1. It won't look at the other values.

Am I missing something?

Basic over view of the DivRem math function..... you have a MIN and MAX random number generator triggered from a generator block set for a time. Every discrete message is counted by ValAccBlock. In the Math (DivRem) Block you are simply using a UDV set look back period.. (in this case 4), and the accumulated number output from ValAccBlock. The Math Block output is dividing these numbers and outputs result...along with showing the number of completed "LookBack"periods. Basically... 3 captured values and 1 reset period.

Ask questions and share ideas about the TT^{®} and X_TRADER^{®} platforms.

First time here? See our Getting Started Guide and FAQs.

Follow
### Follow this article

Execution Algos are available on the TT Platform

BVMF Exchange... FRA DI Butterfly logic example for ADL

The new Terminal block with Pause or Stop capabilities in TT ADL

Easy way to test OMA algo logic from the design canvas..

Time Series Bars for OHLC and VWAP values

Exit Block functionality and it's importance

Importance of Virtualization functionality when building ADL logic

ASE Order Block and Quote / Hedge/ Fill messages and using Alert Blocks for recording

© 2017 Trading Technologies International, Inc. All rights reserved.

Powered by AnswerHub