quite new to Amibroker I do experience some sort of issue while trying to program a manual take profit. I do have a set of rules for Buy and Sell signals which, of course, generate multiple buy and sell signals. Redundant signals should not be removed. Take profit shall only be executed if the Close is above a certain level at the end of the week, therefore I cannot use ApplyStop. Currently I implemented it as follows:
eow = TimeFrameExpand(1, inWeekly, expandPoint);
cnt_array = Null;
bprice_array = Null;
bprice = cnt = 0;
for ( i = 0; i < BarCount-1; i++ ) {
if ( Buy[ i ] == 1 && bprice == 0 ) {
bprice = Open[ i+1 ];
}
if ( bprice > 0 ) {
cnt++;
if (eow[i] AND C[i] >= 1.3*bprice) {
Sell[ i ] = 1;
bprice = cnt = 0;
}
if (C[i] <= 0.85*bprice) {
Sell[ i ] = 1;
bprice = cnt = 0;
}
cnt_array[ i ] = cnt;
bprice_array[i] = bprice;
}
}
Unfortunately this does not take care of handling multiple signals. Somehow the manual take profit is overwritten as soon as a new Buy Signal occurs, although this Buy signal might not be taken from the Backtester. Any hint on this would be welcome!
Hi Tomasz,
either I did not fully understand the descriptions given in the page you were referring to or the explanation of my use case is misleading. Please see the following code for my manual stops:
cnt_array = Null;
bprice_array = Null;
bprice = cnt = 0;
for ( i = 0; i < BarCount-1; i++ ) {
//
if ( Buy[ i ] == 1 && bprice == 0 ) {
bprice = Open[ i+1 ];
}
//
if ( bprice > 0 ) {
cnt++;
if (eow[i] AND C[i] >= 1.3*bprice) {
Sell[ i ] = 1;
bprice = cnt = 0;
}
if (C[i] <= 0.85*bprice) {
Sell[ i ] = 1;
bprice = cnt = 0;
}
cnt_array[ i ] = cnt;
bprice_array[i] = bprice;
}
}
I want to get out of the trade if it's the end of the week and I'm in profit, 30%, or if I do face a draw down of 15%. However, if I run the backtest the frist trade exits after 9 bars, althoush none of the given requirements is met. This indicates to me, that it must've been a Sell signal of an earlier trade. So question, how can I prevent this and only allow Sell signals, which "fit" to my buy signal?
I did some debugging as you suggested. Here's what I've found.
My backtest range start 1st of January 2007. However, the "bprice" which I store and use for comparison for my TP and SL is taken from a trade which is placed on 30th of October, 2006. How can this happen? Is there any command which clears my Buy and Sell signal at the beginning of the loop?