Need coding help in amibroker afl

Hi,

I'm trying to code following strategy but unable to code for "short" because it includes buy condition as well. I have coded Buy,Sell & Cover but not able to code "Short". Please help.

As in short, it is including 2 timeranges :

  1. between 091500 to 094500
  2. between 133000 to 143000

afl is not reading it correctly. I think I'm missing something.


Buy = (If timerange is between 091500 to 094500) and price > X

Sell = Profit target of 2 % or Stop loss of 1%

Short = {Buy condition} and {(If timerange is between 133000 to 143000) and price < Y}

Cover = Profit target of 2 % or Stop loss of 1%
 
Hi,

I'm trying to code following strategy but unable to code for "short" because it includes buy condition as well. I have coded Buy,Sell & Cover but not able to code "Short". Please help.

As in short, it is including 2 timeranges :

  1. between 091500 to 094500
  2. between 133000 to 143000

afl is not reading it correctly. I think I'm missing something.


Buy = (If timerange is between 091500 to 094500) and price > X

Sell = Profit target of 2 % or Stop loss of 1%

Short = {Buy condition} and {(If timerange is between 133000 to 143000) and price < Y}

Cover = Profit target of 2 % or Stop loss of 1%
I would have thought your short condition code would have been;
Short = {Sell condition} and {(If timerange is between 133000 to 143000) and price < Y}
You are selling on a short, not buying.
 
Thanks for your reply mickey !!
It is not sell, it is buy..and that is the catch.

Short = {Buy condition} and {(If timerange is between 133000 to 143000) and price < Y}

What I'm trying to do is to create a trend following indicator.

Stock will be bought if price is above certain level-say X for last 5 candles between 091500 to 094500.

There is another level say Y which is below X.

I want to put another condition for shorting same stock which was trading above X for last 5 candles between 091500 to 094500 but came below Y between 133000 to 143000 intraday.

As it is a short condition, it will also force my earlier long position to sell first and then go short.

I hope I'm able to explain now...please let me know in case of any queries.

Below is snapshot what I have created :

Timerange = TimeNum() > 091500 AND TimeNum() < 094500 ;
Timerange1 = TimeNum() > 133000 AND TimeNum() < 143000 ;
Timeout = TimeNum() > 151500;
Range = LLV(L,5) ;
Range2 = HHV(H,5) ;

X = one of the resistance level
Y = one of the support level

Trend = Timerange AND Ref(Range,-1) > X ;
Trend2 = Trend and (Timerange1 and Ref(Range2,-1) < Y) ;


Buy = Trend ;
Sell = Timeout OR Trend2;
Short = Trend2 ;
Cover = Timeout ;

Buy = ExRem(Buy,Sell) ;
Short = ExRem(short,Cover) ;
Sell = ExRem(Sell,Buy) ;
Cover = ExRem(Cover,Short) ;
 
Back
Top