Schematic (only) for a coding idea

I don't expect anyone to write code for me, but I am hoping someone can point me toward some useful functions or references to solve the following problem:

First, Event A must occur which creates condition A.
Enter trade the FIRST time Event B occurs following Event A, (which may be several days later).
AND Enter only if Condition A continues to be true.

Thanks for any clues

CondA = Close > MA(Close,200);
CondB = Cross(Close, MA(Close, 20));
Buy = CondB and CondA;
2 Likes

@JohnHoward, another function that you can evaluate/study for your purposes is Hold().

Here is an example of its usage.

Thanks, awilson, for your suggestion. It does not, however deal with the problem of time delay. After EventA, days may pass before the FIRST instance of EventB during which ConditionA may reverse so that EventB would no longer trigger an entry.

I can fake this scheme as follows:

  1. Explore for instances of EventA (which results in ConditionA) and store them all in WatchlistA.
  2. Next day, Explore only in WatchlistA for instances of ConditionA and eliminate any that are no longer in ConditionA.
  3. Then explore again only in WatchlistA for EventB. This will result in finding First instance of EventB after EventA only if ConditionA continues. If any such are found, enter trade and eliminate them from WatchlistA.
  4. Continue each day with steps 2 & 3. This could continue to find trades in WatchlistA for several days.

Thanks again for your time.

Thank you beppe. However, if I read that function correctly it is holding as true that which may no longer be true, whereas I need to find if it has remained true over time while waiting for EventB.

1 Like

@JohnHoward, yes. You understood well. Hold() has a different purpose than what you are pursuing. Unfortunately I didn't read your first post carefully.

If Condition A reverse, it will no longuer be true and no Buy would occurr

1 Like

Correct. As I wrote previously, "ConditionA may reverse so that EventB would no longer trigger an entry.

@JohnHoward that is what @awilson is telling you. If Condition A is no longer true then the Buy statement will also be Untrue, so no buying occurs (just like you wrote).

Buy = CondB and CondA;

That line requires both conditions to be simultaneously true.

2 Likes