Event Counter / Label


Category:
0
0

First off thanks again Mr. Hahn, for all that you do. Your resources here are invaluable.

I’m an avid TOS user with a fairly large collection of scripts for specific candle patterns. I’m curious to know if there is a a way to add a label to my charts that would tell me the number of events a candle pattern is created. For example the simple bullish engulfing candle as follows :

def lo = low;
def hi = high;

def s = (hi[0] >= hi[1] and lo[0] <= lo[1]) AND CLOSE >=OPEN;

plot did = s;
did.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_up);
did.SetLineWeight(5);
did.AssignValueColor(Color.green);

If this event is true 5 times on a chart, how can I have a label showing me the number of occurrences? Or, is it even possible?

Thank you in advance

 

Marked as spam
Posted by (Questions: 2, Answers: 1)
Asked on October 2, 2020 12:07 pm
185 views
0
Private answer

Please consider the way I have written my own solution from scratch and learn to use these techniques. You will find my methods make the code much easier to read and maintain. Just follow a few very basic rules:

  1. Never create a variable for high or low unless you are referencing a higher time frame. Simply use the open, high, low and close directly. Creating variable names for those is a waste of time, effort and space and makes the code much more difficult to read and maintain.
  2. Never create variable names consisting of a single character. This makes the code extremely difficult to read and nearly impossible to maintain. You should only do this if you are intentionally trying to tick someone off or make it very difficult for others to understand how your code works.

The following code marks each candle from your example code and provides a chart label that displays the number of times each signal is present on the viewable area of the chart:

plot candlePattern = high >= high[1] and low <= low[1] and close >= open;
candlePattern.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
candlePattern.SetLineWeight(5);
candlePattern.AssignValueColor(Color.GREEN);
rec countEvents = if candlePattern then countEvents[1] + 1 else countEvents[1];
AddLabel(yes, Concat("Pattern Count: ", countEvents), Color.GRAY);

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on October 2, 2020 3:46 pm
0
Phenomenal work, and only a couple more lines of 'code'. Thank you, sir.
( at October 3, 2020 7:58 am)