Execute Trigger Once Daily


Category:
0
0

I have a simple backtest I’m trying to build that simply prints an arrow above the first candle the break out of the 5 minute opening range either high or low. I want to visually see it working before I move onto a strategy test.

<code>def short_trigger_candle = if close < ORLow and close[1] > ORLow then close else double.NaN;

plot STO_flag = short_trigger_candle;
STO_flag.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
STO_flag.SetDefaultColor(Color.RED);
STO_flag.SetLineWeight(3);</code>

My problem is that this will happen more than once but I’m stuck as I can’t figure out how to evaluate if it’s already triggered or not before it’s called again on the next candle. Hope this makes sense and truly appreciate any help. Thank you!

Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on April 19, 2020 4:26 pm
176 views
0
Private answer

What you have here is a chart study that does not include any alerts. So I have moved this post out of the "Alerts and Notifications" topic and into the "Chart Studies" topic. Since you did not provide a fully functional set of code I cannot provide a solution that fits your particular scenario. What I can do is to create a fully functional section of code that accomplishes something similar to what you have requested.

def testCondition = close > open;
def newDay = GetDay() <> GetDay()[1];
rec trackCondition = if newDay then 0 else if testCondition then 1 else trackCondition[1];
plot oneTimePerDay = trackCondition and !trackCondition[1];

Explanation:

  1. Test condition is for green candle
  2. Create variable that is true on the first bar of each new day
  3. Use recursive variable which resets value to zero on first bar of each day and then changes it's value to one on the first bar that the test condition is true then holds the most recent value for each of the following bars until a new day has begun
  4. Plot the value of true when the recursive variable has changes from a value of zero to a value of one
Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on April 19, 2020 5:08 pm