Hi Guys,
Is there an easier way to code the below?
and is it possible to define a search criteria for REF or timeframegetprice?
IE i would like to be able to return the last 20 highs when the stochastics above 50?
Code://get last 20 highs wh1 = Ref( H, -1 ); wh2 = Ref( H, -2 ); wh3 = Ref( H, -3 ); wh4 = Ref( H, -4 ); wh5 = Ref( H, -5 ); wh6 = Ref( H, -6 ); wh7 = Ref( H, -7 ); wh8 = Ref( H, -8 ); wh9 = Ref( H, -9 ); wh10 = Ref( H, -10 ); wh11 = Ref( H, -11 ); wh12 = Ref( H, -12 ); wh13 = Ref( H, -13 ); wh14 = Ref( H, -14 ); wh15 = Ref( H, -15 ); wh16 = Ref( H, -16 ); wh17 = Ref( H, -17 ); wh18 = Ref( H, -18 ); wh19 = Ref( H, -19 ); wh20 = Ref( H, -20 ); //get last 20 lows wl1 = Ref( L, -1 ); wl2 = Ref( L, -2 ); wl3 = Ref( L, -3 ); wl4 = Ref( L, -4 ); wl5 = Ref( L, -5 ); wl6 = Ref( L, -6 ); wl7 = Ref( L, -7 ); wl8 = Ref( L, -8 ); wl9 = Ref( L, -9 ); wl10 = Ref( L, -10 ); wl11 = Ref( L, -11 ); wl12 = Ref( L, -12 ); wl13 = Ref( L, -13 ); wl14 = Ref( L, -14 ); wl15 = Ref( L, -15 ); wl16 = Ref( L, -16 ); wl17 = Ref( L, -17 ); wl18 = Ref( L, -18 ); wl19 = Ref( L, -19 ); wl20 = Ref( L, -20 ); adr1 = (wh1+wh2+wh3+wh4+wh5+wh6+wh7+wh8+wh9+wh10+wh11+wh12+wh13+wh14+wh15+wh16+wh17+wh18+wh19+wh20)-(wl1+wl2+wl3+wl4+wl5+wl6+wl7+wl8+wl9+wl10+wl11+wl12+wl13+wl14+wl15+wl16+wl17+wl18+wl19+wl20); //20 period average tadr = ((adr1)/20);
_SECTION_BEGIN("unknown");
sto1 = Ref(StochK(20,14),-0 );
sto2 = Ref(StochK(20,14),-1 );
IIf(sto1>=sto2, indic=sto1>=sto2, indic=sto1<=sto2);
dire = WriteIf(sto1>=sto2, "L" , "S");
indis=indic;
//get last 20 opens
wo1 = ValueWhen(indis,O, -1 );
wo2 = ValueWhen(indis,O, -2 );
wo3 = ValueWhen(indis,O, -3 );
wo4 = ValueWhen(indis,O, -4 );
wo5 = ValueWhen(indis,O, -5 );
wo6 = ValueWhen(indis,O, -6 );
wo7 = ValueWhen(indis,O, -7 );
wo8 = ValueWhen(indis,O, -8 );
wo9 = ValueWhen(indis,O, -9 );
wo10 = ValueWhen(indis,O, -10 );
wo11 = ValueWhen(indis,O, -11 );
wo12 = ValueWhen(indis,O, -12 );
wo13 = ValueWhen(indis,O, -13 );
wo14 = ValueWhen(indis,O, -14 );
wo15 = ValueWhen(indis,O, -15 );
wo16 = ValueWhen(indis,O, -16 );
wo17 = ValueWhen(indis,O, -17 );
wo18 = ValueWhen(indis,O, -18 );
wo19 = ValueWhen(indis,O, -19 );
wo20 = ValueWhen(indis,O, -20 );
//get last 10 weekly lows
wl1 = ValueWhen(indis,L, -1 );
wl2 = ValueWhen(indis,L, -2 );
wl3 = ValueWhen(indis,L, -3 );
wl4 = ValueWhen(indis,L, -4 );
wl5 = ValueWhen(indis,L, -5 );
wl6 = ValueWhen(indis,L, -6 );
wl7 = ValueWhen(indis,L, -7 );
wl8 = ValueWhen(indis,L, -8 );
wl9 = ValueWhen(indis,L, -9 );
wl10 = ValueWhen(indis,L, -10 );
wl11 = ValueWhen(indis,L, -11 );
wl12 = ValueWhen(indis,L, -12 );
wl13 = ValueWhen(indis,L, -13 );
wl14 = ValueWhen(indis,L, -14 );
wl15 = ValueWhen(indis,L, -15 );
wl16 = ValueWhen(indis,L, -16 );
wl17 = ValueWhen(indis,L, -17 );
wl18 = ValueWhen(indis,L, -18 );
wl19 = ValueWhen(indis,L, -19 );
wl20 = ValueWhen(indis,L, -20 );
wh1 = ValueWhen(indis,H, -1 );
wh2 = ValueWhen(indis,H, -2 );
wh3 = ValueWhen(indis,H, -3 );
wh4 = ValueWhen(indis,H, -4 );
wh5 = ValueWhen(indis,H, -5 );
wh6 = ValueWhen(indis,H, -6 );
wh7 = ValueWhen(indis,H, -7 );
wh8 = ValueWhen(indis,H, -8 );
wh9 = ValueWhen(indis,H, -9 );
wh10 = ValueWhen(indis,H, -10 );
wh11 = ValueWhen(indis,H, -11 );
wh12 = ValueWhen(indis,H, -12 );
wh13 = ValueWhen(indis,H, -13 );
wh14 = ValueWhen(indis,H, -14 );
wh15 = ValueWhen(indis,H, -15 );
wh16 = ValueWhen(indis,H, -16 );
wh17 = ValueWhen(indis,H, -17 );
wh18 = ValueWhen(indis,H, -18 );
wh19 = ValueWhen(indis,H, -19 );
wh20 = ValueWhen(indis,H, -20 );
wc1 = ValueWhen(indis,C, -1 );
wc2 = ValueWhen(indis,C, -2 );
wc3 = ValueWhen(indis,C, -3 );
wc4 = ValueWhen(indis,C, -4 );
wc5 = ValueWhen(indis,C, -5 );
wc6 = ValueWhen(indis,C, -6 );
wc7 = ValueWhen(indis,C, -7 );
wc8 = ValueWhen(indis,C, -8 );
wc9 = ValueWhen(indis,C, -9 );
wc10 = ValueWhen(indis,C, -10 );
wc11 = ValueWhen(indis,C, -11 );
wc12 = ValueWhen(indis,C, -12 );
wc13 = ValueWhen(indis,C, -13 );
wc14 = ValueWhen(indis,C, -14 );
wc15 = ValueWhen(indis,C, -15 );
wc16 = ValueWhen(indis,C, -16 );
wc17 = ValueWhen(indis,C, -17 );
wc18 = ValueWhen(indis,C, -18 );
wc19 = ValueWhen(indis,C, -19 );
wc20 = ValueWhen(indis,C, -20 );
//Open to low av
otolow = (wo1-wl1 + wo2-wl2 + wo3-wl3 + wo4-wl4 + wo5-wl5 + wo6-wl6 + wo7-wl7 + wo8-wl8 + wo9-wl9 + wo10-wl10 + wo11-wl11 + wo12-wl12 + wo13-wl13 + wo14-wl14 + wo15-wl15 + wo16-wl16 + wo17-wl17 + wo18-wl18 + wo19-wl19 + wo20-wl20) /20;
//Open to high av
otohigh = (wh1-wo1 + wh2-wo2 + wh3-wo3 + wh4-wo4 + wh5-wo5 + wh6-wo6 + wh7-wo7 + wh8-wo8 + wh9-wo9 + wh10-wo10 + wh11-wo11 + wh12-wo12 + wh13-wo13 + wh14-wo14 + wh15-wo15 + wh16-wo16 + wh17-wo17 + wh18-wo18 + wh19-wo19 + wh20-wo20)/20;
//Open to close av crude
otoclosec = (wo1-wc1 + wo2-wc2 + wo3-wc3 + wo4-wc4 + wo5-wc5 + wo6-wc6 + wo7-wc7 + wo8-wc8 + wo9-wc9 + wo10-wc10 + wo11-wc11 + wo12-wc12 + wo13-wc13 + wo14-wc14 + wo15-wc15 + wo16-wc16 + wo17-wc17 + wo18-wc18 + wo19-wc19 + wo20-wc20)/20;
Title = EncodeColor(colorWhite)+" "+ Date()+" "+EncodeColor(colorWhite)+ dire + "\n"+
EncodeColor(37) + " open to low = " + EncodeColor(37)+ otolow + " " +"\n"+
EncodeColor(37) + " open to high = " + EncodeColor(37)+ otohigh + " " +"\n"+
EncodeColor(37) + " open to close crude = " + EncodeColor(37)+ otoclosec + " " +"\n";
GraphXSpace=5;
_SECTION_END();
I'm trying to find the maximum result of several statements.
It appears the MAX statement is only good for 2 conditions?
PriceAtBuy = BuyPrice;//simple number (no array)
In the line above, BuyPrice is an array not a simple number so it changes with each bar.
I think that no, captain black. The command "if" doesn't accept array.
The main problem with this code has been mentioned in previous post. It works, but not the way that I want. It is the question.
Thanks.
Edilson
It takes an exit the next bar after the buy because the variable "BuyPrice" is a reserved variable which is an array. You assign "Close" to the BuyPrice at the beginning of the formula outside the loop so on every iteration of the loop the variable "PriceatBuy" is assigned the close price of that particular bar. That's why your exits are triggered immediately after your entry.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?