Hi,
Am trying to add a simple condition to filter entries using Larry William's %R indicator. In the attached pic the correct behavior is highlighted in purple for a long entry when it crosses below overbought to oversold then crosses above the buyTrigger. Am trying to avoid conditions highlighted in yellow, basically don't buy multi times during a consolidation.
What's the right code to define crosses below overbought to oversold to crosses above buyTrigger? For the condition to be true it has to start from crosses below overbought for each entry.
This is the current code:
conditionLE1 = var0 crosses over Buytrigger ;
If conditionLE1 then Buy ( "%RDipBuy" ) next bar at market;
When I add a crosses below overbought it has zero entries.
conditionLE1 = var0 crosses below overbought and var0 crosses over Buytrigger;
If conditionLE1 then Buy ( "%RDipBuy" ) next bar at market;
Any help is appreciated.
simple filter for %R signal
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2222 times
Re: simple filter for %R signal
Thanks TJ.
I attempted to add a 4th condition to filter the entries, but it's not doing as desired. I understand the AND statement is stating all 4 conditions have to be met at the same time, how I can add conditionLE4 after the first 3 conditions have been met?
I attempted to add a 4th condition to filter the entries, but it's not doing as desired. I understand the AND statement is stating all 4 conditions have to be met at the same time, how I can add conditionLE4 after the first 3 conditions have been met?
Code: Select all
inputs:Price(Close),
ConsecutiveBarsUp(3),
ConsecutiveBarsDown(3),
Length( 7 ),
OverSold( 8.4 ),
OverBought( 84 ),
BuyTrigger( 24 ),
SellTrigger(62),
LBarL(1),
LBarS(4),
MaxTradesPerDay(1);
if Price > Price[1] then
Value1 = Value1 + 1
else
Value1 = 0 ;
if Price < Price[1] then
Value2 = Value2 + 1
else
value2 = 0 ;
variables: MP(0),
conditionLE1(true), conditionLE2(true), conditionLE3(true),conditionLE4(true), conditionLE(true),
conditionSE1(true), conditionSE2(true), conditionSE3(true), conditionSE4(true), conditionSE(true);
//Long conditions
ConditionLE1= Close > VTI_VALUES;
ConditionLE2 = var0 crosses above BuyTrigger;
ConditionLE3 = price > price[LBarL];
//ConditionLE4 = Value1 >= ConsecutiveBarsUp;
ConditionLE= ConditionLE1 and ConditionLE2 and ConditionLE3;
//Short Conditions
conditionSE1= Close < VTI_VALUES;
conditionSE2 = var0 crosses under SellTrigger;
ConditionSE3 = price < price[LBarS];
//conditionSE4 = Value2 >= ConsecutiveBarsDown;
ConditionSE= ConditionSE1 and ConditionSE2 and ConditionSE3;
//Order Entry
if EntriesToday(d) < MaxTradesPerDay then begin
If ConditionLE then Buy ( "%RDipBuy" ) next bar at market;
If ConditionSE then sellshort ( "%RtopSell" ) next bar at market;
End;
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2222 times
Re: simple filter for %R signal
Code: Select all
If ConditionLE and conditionLE4
then Buy ( "%RDipBuy" ) next bar at market;
Re: simple filter for %R signal
That worked for minute bars, but not range bars. With the conditionLE4 the range bar only produced one trade without conditionLE4 it had 24. Is back testing not reliable with range bars?