Mike:
Thanks for responding. I went through the code to send it to you. I was
putting something simple together for illustration purposes using Keltner Bands
instead of BB. I had lifted the Keltner Band code from my indicator folder.
As such, it had "Param" fields. I thought I had gone through them all and
changed them from "Param" to "Optimize" but apparently I missed one. That one
Param statement caused the problem. When I changed it to Optimize it worked.
At any rate, for anyone else who may be interested in a similar filter or
permission switch (can use with envelopes, channels, Bollinger Bands, etc.),
below is the code.
Thanks again.
-Joe
// Keltner Band BreakOut Permission switch
//
//
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g,
Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle |
ParamStyle("Style") | GetPriceStyle() );
// Keltner Bands For Permission Switch
Periods = Optimize ("Periods", 10, 2, 40, 2 );
Width = Optimize ("Width", 1.25, 0.5, 5, 0.25 );
CenterLine = MA( C, Periods );
KTop = CenterLine + Width * ATR( Periods );
KBot = CenterLine - Width * ATR( Periods );
PermitLong = Cross( EMA(C, 3),KTop);
PermitShort = Cross(KBot, EMA(C, 3));
PermitLong = Flip(PermitLong, PermitShort);
PermitShort = Flip(PermitShort, PermitLong);
// Any buy or sell criteria... I use these just
// to generate many signals to illustrate on chart.
Buy = C > Ref(C, -1) AND PermitLong;
Sell = BarsSince(Buy) >=1;
Short = C < Ref (C, -1) AND PermitShort ;
Cover = BarsSince(Short) >=1;
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Short = ExRem(Short,Cover);
Cover = ExRem(Cover,Short);
// Plot the switches and the Keltner bands along with the EMA
// Run a trade list and select "show actual trade arrows"
// Longs should be when PermitLong (Blue) is 1 and
// Shorts should be when PermitShort (Gold) is 1.
Plot(PermitLong, "PermitLong", colorBlue, styleOwnScale);
Plot(PermitShort, "PermitShort", colorGold, styleOwnScale);
Plot(KTop, "KeltnerTop", colorBrown);
Plot(KBot, "KeltnerBot", colorYellow);
Plot(EMA(C, 3), "EMA(C, 3)", colorWhite);
GraphXSpace = 5;
--- In [email protected], "Mike" <sfclimb...@...> wrote:
>
> Hi,
>
> You will need to post some actual parsable code. What you have posted will
> not parse and would not produce the plots that you describe, even if it did
> parse.
>
> Based on your description of the plots, it sounds like you have correctly
> assigned the value of Flip back into the PermitShort and PermitLong
> variables, though you did not do so in your posted code. Similarly, I assume
> that BBtop was the result of BBandTop(...), etc.
>
> Anyway, it all works as expected when I clean it up.
>
> PermitLong = Cross (EMA (C, 3), BBandTop(Close, 15, 1)); // set the switch to
> Long
> PermitShort = Cross (EMA (C, 3), BBandBot(Close, 15, 1)) ;// set the switch
> to Short
>
> PermitLong = Flip(PermitLong, PermitShort);
> PermitShort = Flip(PermitShort, PermitLong);
>
> Plot(Close, "Close", colorBlack, styleBar);
> Plot(PermitLong, "PermitLong", colorRed, styleOwnScale, 10);
> Plot(PermitShort, "PermitShort", colorBlue, styleOwnScale, 10);
>
> /* So I notice when I run the backtest that the switching plots look fine. The
> plots show that when a PermitLong condition occurs and generates a 1, it stays
> at 1 until a PermitShort condition occurs. Then PermitShort remain at 1 until
> a
> PermitLong condition returns, etc. The plots show two square waves oscillating
> between 0 and 1 at the appropriate times of the breakouts/breakdowns. So far
> so
> good.
>
> Then when I combine any trading system with the switches, they do not work
> properly. For simplicity lets just use the following:
> */
>
> Buy = C > Ref(C, -1) AND PermitLong;
> Sell = BarsSince(Buy) >=3;
> Short = C < Ref (C, -1) AND PermitShort ;
> Cover = BarsSince(Short) >=3;
>
> PlotShapes(shapeUpArrow * Buy, colorGreen);
> PlotShapes(shapeDownArrow * Short, colorRed);
>
> Mike
>
> --- In [email protected], "venturerider2" <venturerider2@> wrote:
> >
> > Any advice would be greatly appreciated.
> >
> > I am trying to code a basic permission switch that remains on (1) when a
> > specific condition is met and remains on even though that condition no
> > longer exists, until a different condition changes it.
> > I tried the following but could not get it to work properly.
> >
> > /* Parameters for Bolinger band top and bottom would precede this. */
> >
> > // Permission Switch
> > /* Permit a Long entry when the EMA crosses above the Bollinger Band Top.
> > Permit only long entries until EMA crosses below Bollinger Band Bottom, and
> > then permit only short entries. Then permit only short entries until EMA
> > crosses back above BBTop, etc. */
> >
> > /* Parameters for Bolinger band top and bottom would precede this. */
> >
> > PermitLong = Cross (EMA (C, 3), BBTop; // set the switch to Long
> > PermitShort = Cross (EMA (C, 3), BBBot ;// set the switch to Short
> >
> > Flip(PermitLong, PermitShort);
> > Flip(PermitShort, PermitLong);
> >
> > Plot(PermitLong, "PermitLong", colorRed, styleOwnScale);
> > Plot(PermitShort, "PermitShort", colorBlue, styleOwnScale);
> >
> > /* So I notice when I run the backtest that the switching plots look fine.
> > The plots show that when a PermitLong condition occurs and generates a 1,
> > it stays at 1 until a PermitShort condition occurs. Then PermitShort
> > remain at 1 until a PermitLong condition returns, etc. The plots show two
> > square waves oscillating between 0 and 1 at the appropriate times of the
> > breakouts/breakdowns. So far so good.
> >
> > Then when I combine any trading system with the switches, they do not work
> > properly. For simplicity lets just use the following:
> >
> > Buy = C > Ref(C, -1) AND PermitLong;
> > Sell = BarsSince(Buy) >=3;
> > Short = C < Ref (C, -1) AND PermitShort ;
> > Cover = BarsSince(Short) >=3;
> >
> > It will allow short trades during both PermitLong and PermitShort and will
> > do the same for long trades. I think it may be the way I am using Flip.
> >
> > I am open to doing this without Flip - whatever works.
> >
> > I do not want PermitLong and NOT(PermitLong) since sometimes my parameters
> > may allow trading in both directions. So I like having separate switches.
> >
> > Thanks for any help,
> >
> > Joe
> >
>