Help with AND function

#1
I'm trying to set up a Short condition where if the current bar's high is the highest high of the last 10 bars, and if the current bar closes in the bottom 30% of the current bars range.

I can get the following to work:

Short = IIf( HHV(Close,10),1,0);

This marks every bar on the chart. I tried to to add the AND function as below:

Short = IIf( HHV(Close,10),1,0) AND (Close <= ((H-L) * .3)+ L);

This marks every bar that closed in the bottom 30% of range but ignores the highest high of the last 10 days.

Can anyone help?

Thanks
 
#3
I'm trying to set up a Short condition where if the current bar's high is the highest high of the last 10 bars, and if the current bar closes in the bottom 30% of the current bars range.

I can get the following to work:

Short = IIf( HHV(Close,10),1,0);

This marks every bar on the chart. I tried to to add the AND function as below:

Short = IIf( HHV(Close,10),1,0) AND (Close <= ((H-L) * .3)+ L);

This marks every bar that closed in the bottom 30% of range but ignores the highest high of the last 10 days.

Can anyone help?

Thanks
Use this
Short = (H== HHV(H,10)) AND (Close <= ((H-L) * .3)+ L);
Because you want to short on the highest high of the last 10 days, so you have to use H instead of C in HHV();
 
#7
Strade, I tried to add a buy signal by using the opposite of the string you provided me, but I get an error 29 "variable 'cond2' used without having been initialized".
Here's the code as I've got it now:

shortMA = (MA (C,10));
LongMA = (MA (C,20));

Cond1 = (H== HHV(H,10)) AND (Close <= ((H-L) * .3)+ L);
Cond2 = (L== LLV(L,10)) AND (Close >= (H-((H-L) * .3));

Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
Plot (shortMa, "shortMA",colorBlue,styleLine);
Plot (longMa, "longMA",colorRed,styleLine);

Buy = IIf ((Cond2),1,0);
Sell = IIf(Cross(LongMA,ShortMA),1,0);
Short = IIf ((Cond1),1,0);
Cover = IIf(Cross(ShortMA,LongMA),1,0);
 
#8
Here is ur code

shortMA = (MA (C,10));
LongMA = (MA (C,20));

Cond1 = (H== HHV(H,10)) AND (Close <= ((H-L) * .3)+ L);
Cond2 = (L== LLV(L,10)) AND (Close >= (H-(H-L) * .3));

Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
Plot (shortMa, "shortMA",colorBlue,styleLine);
Plot (longMa, "longMA",colorRed,styleLine);

Buy = IIf ((Cond2),1,0);
Sell = IIf(Cross(LongMA,ShortMA),1,0);
Short = IIf ((Cond1),1,0);
Cover = IIf(Cross(ShortMA,LongMA),1,0);
 

Similar threads