[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Re: question about manipulating individual array elements



PureBytes Links

Trading Reference Links

for anyone who likes to comment or suggest improvements here one on 
my test codes in AFL (it seems to work OK ...):

what it does: it buys at the open the day AFTER a buy signal. The buy 
signal is not very important here. I was struggling to get the sell 
signals and the sell price right.

After the buy signal is known a high en a low threshold level are 
defined and will determine where to take a profit or a loss. Sell 
rules are:
1) take profit if high is above high threshold at high threshold price
2) take loss if low is below low threshold at low threshold price
3) use (2) if both 1 and 2 apply
4) take profit if open is above high threshold at open price
5) take a loss if open is below low threshold at open price
6) sell position if trades takes longer than maxdur bars at the close 
price except if during that bar sell condition 1,2,3 or 4 occurs then 
we will use these exit prices. 



----------------------------------------------------------
// overide default Settings, set buy delay at 1 bar
SetTradeDelays(1,0,0,0);

// generate buy signals
Buy = Cross(RSI(),30);

// high threshold
hit = ValueWhen(Ref(Buy,-1),Open)*1.02;
// low threshold
lot = ValueWhen(Ref(Buy,-1),Open)*0.80;
// max duration of the trade in bars
maxdur = 5; 

// setting the buy price at open overides the value in Settings
BuyPrice = Open;

// define the sell conditions
sc1 = H > hit;
sc2 = L < lot;
sc1 = IIF( sc1 == 1 AND sc2 == 1, 0, sc1 );
sc3 = O > hit;
sc1 = IIF( sc1 == 1 AND sc3 == 1, 0, sc1 );
sc4 = O < lot;
sc2 = IIF( sc2 == 1 AND sc4 == 1, 0, sc2 );
sc5 = Cross(BarsSince(Buy), maxdur );
sc5 = IIF( sc5 == 1 AND sc1 == 1, 0, sc5 );
sc5 = IIF( sc5 == 1 AND sc2 == 1, 0, sc5 );
sc5 = IIF( sc5 == 1 AND sc3 == 1, 0, sc5 );
sc5 = IIF( sc5 == 1 AND sc4 == 1, 0, sc5 );

// combined sell signals
Sell = sc1 + sc2 + sc3 + sc4 + sc5;

// define the sellprice
sp1 = sc1 * hit;
sp2 = sc2 * lot;
sp3 = sc3 * O;
sp4 = sc4 * O;
sp5 = sc5 * C;

// setting the sell price overides the value in Settings
SellPrice = sp1 + sp2 + sp3 + sp4 + sp5;

// remove excessive signals
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);

// for the indicator builder window
Plot(C,"",1,64);
PlotShapes(shapeDownArrow*Sell,colorRed,0,SellPrice);
PlotShapes(shapeUpArrow*Ref(Buy,-1),colorGreen,0,BuyPrice);
X=hit;
Y=lot;
Plot(X,"",colorWhite,1);
Plot(Y,"",colorYellow,1);
title=name()+ ", O:"+writeval(o)+ ", H:"+writeval(h)+ ", L:"+writeval
(l)+ ", C:"+writeval(c)
+ ", High Threshold:"+writeval(hit)
+ ", Low Threshold:"+writeval(lot);

// for the automatic analysis window
Filter = 1;
AddColumn(sc1,"sc1");
AddColumn(sc2,"sc2");
AddColumn(sc3,"sc3");
AddColumn(sc4,"sc4");
AddColumn(sc4,"sc5");
AddColumn(Buy,"buy");
AddColumn(BuyPrice,"buyprice");
AddColumn(Sell,"sell");
AddColumn(SellPrice,"sellprice");
----------------------------------------------------------


------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for your HP, Epson, Canon or Lexmark
Printer at MyInks.com. Free s/h on orders $50 or more to the US & Canada.
http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/mOAaAA/3exGAA/qnsNAA/GHeqlB/TM
---------------------------------------------------------------------~->

Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx 
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/