# Timing Trigger vs Entry Prices

Hello

I am trying to create an entry rule so that the entry is only executed the following day if the high exceeds the previous days high by \$0.10 (buy). I haven't even got to the \$0.10 yet, just working on exceeding the previous high.

My question:

If I am using (buytriggered, -1) for an entry signal, and also have the setup referencing previous bars, do I need to account for that in the bar setting, so for example, if I am wanting 3 lower lows, this would normally be Ref(-1/2/3), but since I am using a the -1buytrigger do I need to drop these back one (Ref(-2/3/4) ?

And if anyone can help me with the code for only executing when the high exceeds previous high by \$X that would be greatly appreciated ...

``````//The Trend
X=MA(C,10);
Y=MA(C,50);
Z=MA(C,200);

Uptrend1 = C > X AND X > Y;
Uptrend2 = Z > Ref(Z,-1);
Uptrend = Uptrend1 AND Uptrend2;
Downtrend1 = C < X AND X < Y;
Downtrend2 = Z < Ref(Z,-1);
Downtrend = Downtrend1 AND Downtrend2;

// The Setuo
id = H < Ref(H,-1) AND L > Ref(L,-1);
LLL = L < Ref(L,-1) AND Ref(L,-2) < Ref(L,-3) AND Ref(L,-3) < Ref(L,-4);
LLI = id AND Ref(L,-2) < Ref(L,-3) AND Ref(L,-3) < Ref(L,-4);
HHH = H > Ref(H,-1) AND Ref(H,-2) > Ref(H,-3) AND Ref(H,-3) > Ref(H,-4);
HHI = id AND Ref(H,-2) > Ref(H,-3) AND Ref(H,-3) > Ref(H,-4);

buytriggered = Uptrend AND (LLL OR LLI);
selltriggered = Downtrend AND (HHH OR HHI);

Short = Ref(selltriggered, -1) AND L < Ref(Low,-1);
Sell = Short;

``````

Thanks

Modify below code to suit your specific logic.

``````// The Trend
X=MA(C,10);
Y=MA(C,50);
Z=MA(C,200);

Uptrend1 = C > X AND X > Y;
Uptrend2 = Z > Ref(Z,-1);
Uptrend3 = H > Ref(High,-1);
Uptrend = Uptrend1 AND Uptrend2 AND Uptrend3;

Downtrend1 = C < X AND X < Y;
Downtrend2 = Z < Ref(Z,-1);
Downtrend3 = L < Ref(Low,-1);
Downtrend = Downtrend1 AND Downtrend2 AND Downtrend3;

// The Setup
id = H < Ref(H,-1) AND L > Ref(L,-1);

Low_3 = LLV(Low < Ref(Low, -1), 3);
Low_2_startOneBack = LLV(Ref(Low, -1) < Ref(Low, -2), 2);
LLI = id AND Low_2_startOneBack;

High_3 = LLV(High < Ref(High, -1), 3);
High_2_startOneBack = LLV(Ref(High, -1) < Ref(High, -2), 2);
HHI = id AND High_2_startOneBack;

buytriggered = Uptrend AND (Low_3 OR LLI);
selltriggered = Downtrend AND (High_3 OR HHI);

buyLimitPrice = Ref(High, -1) + 0.10;

Short = Ref(selltriggered, -1);
Sell = Short;
``````
3 Likes

FWIW,

``````LLL(Low < Ref(Low, -1), 3)
``````

is not the same as

``````LLL = L < Ref(L,-1) AND Ref(L,-2) < Ref(L,-3) AND Ref(L,-3) < Ref(L,-4);
``````

See below pic of comparing `buytriggered ` and `selltriggered` of each version.

Here is correction using Sum() function.

``````/// The Trend
X=MA(C,10);
Y=MA(C,50);
Z=MA(C,200);

Uptrend1 = C > X AND X > Y;
Uptrend2 = Z > Ref(Z,-1);
Uptrend = Uptrend1 AND Uptrend2;
Downtrend1 = C < X AND X < Y;
Downtrend2 = Z < Ref(Z,-1);
Downtrend = Downtrend1 AND Downtrend2;

rc_L = ROC(L,1);
rc_H = ROC(H,1);

// The Setup
/// correction to LLV
period = 2;
id = rc_H < 0 AND rc_L > 0;
prev_sumL = Ref(Sum(rc_L<0, period),-2) == period;
LLL = rc_L < 0 AND prev_sumL;
LLI = id AND prev_sumL;
prev_sumH = Ref(Sum(rc_H>0, period),-2) == period;
HHH = rc_H > 0 AND prev_sumH;
HHI = id AND prev_sumH;

buytriggered = Uptrend AND (LLL OR LLI);
selltriggered = Downtrend AND (HHH OR HHI);

// etc. below
``````

And with little bit further simplification

``````//The Trend
X=MA(C,10);
Y=MA(C,50);
Z=MA(C,200);

Uptrend1 = C > X AND X > Y;
Uptrend2 = Z > Ref(Z,-1);
Uptrend = Uptrend1 AND Uptrend2;
Downtrend1 = C < X AND X < Y;
Downtrend2 = Z < Ref(Z,-1);
Downtrend = Downtrend1 AND Downtrend2;

rc_L = ROC(L,1);
rc_H = ROC(H,1);

/// The Setup
/// correction to LLV
period = 2;
id = rc_H < 0 AND rc_L > 0;
LLL = rc_L < 0;
LLI = id;
HHH = rc_H > 0;
HHI = id;

prev_sumL = Ref(Sum(LLL, period),-2) == period;
prev_sumH = Ref(Sum(HHH, period),-2) == period;
buytriggered = Uptrend AND (LLL OR LLI) AND prev_sumL;
selltriggered = Downtrend AND (HHH OR HHI) AND prev_sumH;

// etc. below
`````` 4 Likes

Big thanks to both, very helpful and insightful. Just when I think I am getting okay at writing my code, you poets show how much more there is to learn 2 Likes