Exits that key off SignalBar technical indicators
Author: topcat77
Creation Date: 10/30/2008 12:00 PM
profile picture

topcat77

#1
The short-trending strategy below has several Exit conditions, three of which key off technical indicators that belong to the SignalBar (the bar that generates the Signal. These are, EXIT at market IF 1) Rsi is higher than the rsi at the SignalBar by a specific number, for example +20rsi 2) Rsi is lower than the rsi at the SignalBar by a specific number, for example -20rsi 3 the lower Bollinger Band 10 bars from the SignalBar is lower than the lowerBollinger Band at the SignalBar.

The script works fine except for these exits. I am thinking that I have set up the Signal Bar :

int signalBar = 0

incorrectly, and have tried several alternatives to rectify this, including using EntryBar. Help much appreciated:

CODE:
Please log in to see this code.
profile picture

Eugene

#2
signalBar is flagged on entry bar, right? In your case, it was 0.

CODE:
Please log in to see this code.
profile picture

topcat77

#3
Thanks . . . . .but, as written, the script exits (virtually) every position after
one bar; the vast majority of those (1 bar) exits happen if the first bar has a
loss from entry. There seems to be no logic to the trades that last longer

QUOTE:
signalBar is flagged on entry bar, right? In your case, it was 0.

I take Signalbar to mean the bar that shows the signal and Entrybar to mean the open of the next bar
(at which the signal is executed). It doesn't matter (too much) to the logic of
the strategy whether the rsi and bb differentials are keyed off the Signalbar or the Entrybar

any thoughts on why this script is not behaving?
profile picture

Eugene

#4
QUOTE:
but, as written, the script exits (virtually) every position after
one bar; the vast majority of those (1 bar) exits happen if the first bar has a
loss from entry.

Instead of troubleshooting your exit conditions, when they are allowed to trigger once too often (thanks to the OR divider), try to process one condition at a time. It will let you identify the problematic one(s) in this exit logic.

QUOTE:
I take Signalbar to mean the bar that shows the signal and Entrybar to mean the open of the next bar (at which the signal is executed).

Then you would need this snippet instead of the fragment used above:
CODE:
Please log in to see this code.
profile picture

topcat77

#5
Right, I should have run the diagnostic before I wrote.

Anyway, this is the errant line that prompts exits at the next bar:

QUOTE:
( bbL[signalBar] > (bbL[signalBar+10])


when eliminated, all other Exit conditions work fine
if changed to:

QUOTE:
if ((bbL[signalBar]>(bbL[signalBar]+10)


it does not function, but all other Exit conditions still work fine
This Exit condition was meant to prompt an exit if the bbL at the 10th bar
forward from the signalBar was lower than the bbL at the signalBar. What is
the correct syntax for this?

I was using this as a surrogate for the Exit condition that I really wanted but could
not find a way of writing: if there is a consecutive decline in the bbLs of the 10 bars
following signalBar, then Exit. Can the CumDown command be utilised for this? If so, how

Thanks



profile picture

Eugene

#6
QUOTE:
I was using this as a surrogate for the Exit condition that I really wanted but could
not find a way of writing: if there is a consecutive decline in the bbLs of the 10 bars
following signalBar, then Exit. Can the CumDown command be utilised for this? If so, how


CODE:
Please log in to see this code.
profile picture

topcat77

#7
Brilliant

but

1)how do I fit this segment in with my other Exits:

CODE:
Please log in to see this code.


2) to introduce a tolerance in the consecutive declines (nothing works in a 10 bar straight line)
so that "down" in the series for each bar is defined as, for example, "lower than
(previous bar bbL*1.0002)would it be correct to alter the CumDown statement to:

CumDown.Series(bbL*1.0002,1)[bar]>=10) ..... ?

3) It would be helpful to find the answer to

QUOTE:
This Exit condition was meant to prompt an exit if the bbL at the 10th bar
forward from the signalBar was lower than the bbL at the signalBar. What is
the correct syntax for this?


Apologies for making a meal of this
This will be the fifth of eight patterns that the program will run concurrently in WL

Thanks


profile picture

topcat77

#8
Eugene

I would much appreciate guidance with these three questions.
On 2) every combination of script that I try with the OR divider
is disliked by the compiler

Thanks in advance
profile picture

Eugene

#9
QUOTE:
1)how do I fit this segment in with my other Exits:

Just the same as done by you before -- using the regular C# operator.
QUOTE:
2) to introduce a tolerance in the consecutive declines (nothing works in a 10 bar straight line)

...you could, instead, specify a larger value for the period parameter. It would not be consecutive any more, but that's the price to pay for "tolerance".
QUOTE:
(previous bar bbL*1.0002)would it be correct to alter the CumDown statement to:

CumDown.Series(bbL*1.0002,1)[bar]>=10) ..... ?

No. It seems to me that when you want to go "lower", you need not to use a multiplier larger than 1.

As to #3, right now there are some other tasks that prevent me from performing this custom coding.
profile picture

topcat77

#10
QUOTE:
Just the same as done by you before -- using the regular C# operator.


Here's the problem:

if written as

CODE:
Please log in to see this code.


the script compiles, but eliminates all trades

if written as:

CODE:
Please log in to see this code.


it does not compile

In my (short) walk with WL I haven't dealt with an IF statement within an OR
divider so I figure that : if (bar==signalBar+10) may be out of place , but
haven't been able to work through its correct position



profile picture

Cone

#11
It doesn't compile because of syntax errors. See the little red "squiggles" in the Editor? It's telling you that it's expecting something (like a parenthesis) to be there.

You need a set of parentheses around the entire "if" argument. In between, you don't need any parentheses to delimit statements, as was required in Pascal. My advice is don't use them unless required for logical order -

CODE:
Please log in to see this code.

profile picture

topcat77

#12
Cone

thanks much, especially for the tutorial. the script compiles ok

but

every trade exits at the first bar after entry (!!)

here is the full script:

CODE:
Please log in to see this code.


can you tell why?
profile picture

Cone

#13
Looks like we need to continue the lesson. Here's how the if's work:

CODE:
Please log in to see this code.

Now can you fix your code?