Looping Query - Variable loops

Hi There! Forgive me if this is obvious as I am a newbie to Knime.

I am having an issue with a ‘variable’ loop. The process is that I have a dataset of generic financial information and I have created a testing environment by inserting logic. Through a ‘table row to variable loop start’, I tag certain rows that meet the required logic. It will then provide the information such as when the ‘trade’ opened > When ‘trade’ closed > How long/many rows until close (See Screenshot). That specific loop runs well very well.

I am getting stuck on the next part. I need to ‘lock out’ trades so only one is valid at a time. This means that if a ‘trade’ is opened on row 1 and closes on row 3 - Row 2 cannot open a trade. I was trying it with a recursive loop, generic loop start with no luck.

I have been stuck on this for quite some time - hence my Hail Mary for a post.
Any help would be very appreciative.

Hi there,

First, welcome onboard. If I understood it correctly, I had a challenge with allowing only one active trade at a time (i.e., preventing overlapping trades). Instead of using a recursive loop, I (think) managed to solve it in a simpler way.

Here’s a quick summary of what I did:

  1. I added a dummy control column to tag specific trade types (e.g., “Stop Hit”).
  2. Then I used a Column Comparator + Java Snippet to control flow logic and filter rows accordingly.
  3. I applied Missing Value logic with forward filling to define trade blocks.
  4. A GroupBy node helped ensure that only valid trade sequences with at least two rows were included.
  5. I used a Row Filter to remove isolated signals and a Joiner to reconstruct valid sequences.
  6. Then trade blocks’ first and low rows’ data only applicable by grouping them likewise.

This approach worked for me without needing a recursive loop. It’s lighter and easier to debug.

Feel free to ask if you’d like a sample screenshot or workflow logic — happy to help!

Best,

Alpay

Trade_Analysis_Output.xlsx (6.1 KB)

tradedata.knwf (23.3 KB)

1 Like

Hi Alpay,

Thanks for the solution - I really appreciate it!
I also managed to find a solution that is simpler than my previously thought looping structure by using a mixture of Lag Column nodes and a Rule Engine. Upon further reflection, I though the best way was to lag the TradeStart by 1 and the TradeEnd by 1 then proceed into the Rule engine ($TradeStart$ >
$TradeStart(-1)$ AND $TradeStart$ < $TradeEnd(-1)$ => 1
TRUE => 0 ). From there I filtered for 0 to find the valid trades.

I really appreciate the support!


Screenshot 2025-06-05 080030

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.