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


Reply via email to