PureBytes Links
Trading Reference Links
|
Thank you so much Ed.
I'll look at your script.
There is errors for my tick/dollars count.
It is very complicated in AB a simply strategy that buy and sell at
specific price instead O H L C.
Thank you.
---
Giuseppe
--- In amibroker@xxxxxxxxxxxxxxx, "ed nl" <ed2000nl@xxxx> wrote:
> ami_trader,
>
> this is an example of how I use loopings instead of Applystop
(example is for long trades only). This is for your specific
problem. Note you have to change the stopProfitLevel and
stopLossLevel.
>
> Change:
>
> // set profit level at 2%
> stopProfitLevel = BuyPrice + BuyPrice * (2 / 100);
>
> // set stop level at 5%
> stopLossLevel = BuyPrice - BuyPrice * (5 / 100);
>
> to
>
> // profit at 6 points
> stopProfitLevel = BuyPrice + 6;
>
> // stop loss 10 points
> stopLossLevel = BuyPrice - 10;
>
> also adjust:
>
> BuyPrice = Ref(H,-1) - 0.001;
>
> to
>
> BuyPrice = Ref(H,-1) - 10;
>
>
> rgds, Ed
>
>
>
>
> procedure sell_proc
(Buy,BuyPrice,Open,High,Low,Close,stopProfitLevel,stopLossLevel) {
>
> global Sell;
> global SellPrice;
> global BuyAdjusted;
> global stopProfitLevelAdjusted;
> global stopLossLevelAdjusted;
>
> // initialise arrays
> SellPrice = 0;
> Sell = 0;
> stopProfitLevelAdjusted = 0;
> stopLossLevelAdjusted = 0;
> BuyAdjusted = 0;
>
>
> for (i = 1; i < BarCount; i++) {
>
> if (Buy[ i ] == 1) {
>
> BuyAdjusted[ i ] = 1;
> stopProfitLevelAdjusted[ i ] = stopProfitLevel[ i ];
> stopLossLevelAdjusted[ i ] = stopLossLevel[ i ];
>
> // find a sell position + sellprice
> for (j = i; j < BarCount; j++) {
>
> stopProfitLevelAdjusted[ j ] = stopProfitLevel[ i ];
> stopLossLevelAdjusted[ j ] = stopLossLevel[ i ];
>
> // test if stop loss is hit
> if((Low[ j ] <= stopLossLevelAdjusted[ j ]) AND (Open[
j ] >= stopLossLevelAdjusted[ j ])) {
>
> Sell[ j ] = 1;
> SellPrice[ j ] = stopLossLevelAdjusted[ j ];
>
> i = j;
>
> j = BarCount;
>
> // stop loss exceeded at the open
> } else if (Open[ j ] < stopLossLevelAdjusted[ j ]) {
>
> Sell[ j ] = 1;
> SellPrice[ j ] = Open[ j ];
>
> i = j;
>
> j = BarCount;
>
> // test if profit stop is hit
> } else if (High[ j ] >= stopProfitLevelAdjusted[ j ] AND
Open[ j ] <= stopProfitLevelAdjusted[ j ]) {
>
> Sell[ j ] = 1;
> SellPrice[ j ] = stopProfitLevelAdjusted[ j ];
>
> i = j;
>
> j = BarCount;
>
> // stop profit exceeded at open
> } else if (Open[ j ] > stopProfitLevelAdjusted[ j ]) {
>
> Sell[ j ] = 1;
> SellPrice[ j ] = Open[ j ];
>
> i = j;
>
> j = BarCount;
>
>
> } else if (j == BarCount - 1) {
>
> i = BarCount;
>
> }
>
> }
>
> }
>
> }
>
>
> } // end procedure
>
>
>
>
> SetChartOptions(0, chartShowDates);
> SetBarsRequired(10000,10000);
>
> Cond1 = Ref(H,-1) > Ref(H,-2) && Ref(H,-2) > Ref(H,-3);
> Cond2 = O < Ref(H,-1);
>
> BuyPrice = Ref(H,-1) - 0.001;
> Buy=Cond1 && Cond2 && L <= BuyPrice && H >= BuyPrice;
>
> // set profit level at 2%
> stopProfitLevel = BuyPrice + BuyPrice * (2 / 100);
>
> // set stop level at 5%
> stopLossLevel = BuyPrice - BuyPrice * (5 / 100);
>
> sell_proc
(Buy,BuyPrice,Open,High,Low,Close,stopProfitLevel,stopLossLevel);
> Buy = BuyAdjusted;
>
> // remove zeros
> stopProfitLevelAdjusted = IIf(stopProfitLevelAdjusted == 0, Null,
stopProfitLevelAdjusted);
> stopLossLevelAdjusted = IIf(stopLossLevelAdjusted == 0, Null,
stopLossLevelAdjusted);
>
> Plot(C,"C",1,64);
> Plot(stopProfitLevelAdjusted,"",colorBrightGreen,1);
> Plot(stopLossLevelAdjusted,"",colorRed,1);
> PlotShapes(IIf(Buy,shapeUpArrow,0),colorWhite, layer = 0,
yposition = BuyPrice, offset = 0 );
> PlotShapes(IIf(Sell,shapeDownArrow,0),colorYellow, layer = 0,
yposition = SellPrice, offset = 0 );
>
> Title=Name()+ ", O: "+WriteVal(O)+ ", H: "+WriteVal(H)+ ",
L: "+WriteVal(L)+ ", C: "+WriteVal(C);
>
> Filter = 1;
> AddColumn(Buy,"Buy");
> AddColumn(Sell,"Sell");
------------------------ Yahoo! Groups Sponsor --------------------~-->
What would our lives be like without music, dance, and theater?
Donate or volunteer in the arts today at Network for Good!
http://us.click.yahoo.com/Tcy2bD/SOnJAA/cosFAA/GHeqlB/TM
--------------------------------------------------------------------~->
Please note that this group is for discussion between users only.
To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com
For other support material please check also:
http://www.amibroker.com/support.html
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/amibroker/
<*> To unsubscribe from this group, send an email to:
amibroker-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|