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" <venturerid...@...> 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 >
