simple filter for %R signal

Questions about MultiCharts and user contributed studies.
gatg50
Posts: 3
Joined: 03 Nov 2020

simple filter for %R signal

Postby gatg50 » 28 Jan 2021

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.
2021-01-28_114921.jpg
(192.72 KiB) Not downloaded yet
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.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: simple filter for %R signal

Postby TJ » 28 Jan 2021

See post #1 & #2
1. [FAQ] How to Post Codes ... so that people can read.
viewtopic.php?t=11713

gatg50
Posts: 3
Joined: 03 Nov 2020

Re: simple filter for %R signal

Postby gatg50 » 04 Feb 2021

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?

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;

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: simple filter for %R signal

Postby TJ » 04 Feb 2021

Code: Select all

If ConditionLE and conditionLE4 then Buy ( "%RDipBuy" ) next bar at market;

gatg50
Posts: 3
Joined: 03 Nov 2020

Re: simple filter for %R signal

Postby gatg50 » 05 Feb 2021

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?


Return to “MultiCharts”