Useful AFL to share and help request

Dear all experts,

I have no coding knowledge, trying to learn and understand as much as I could currently.

I had been having this AFL and find it to be useful. It only have Buy condition but not Sell.

Can anyone assist to input how to script a sell condition in the similar concept of the original script.

Thank you for reading and any help is much appreciated.

Rectangle Breakout system

- A powerful function in Amibroker not developed fully,
  modified to perform Buy exploration
- This script check for:
            -9 Day, 1 month, 2 month, 50day rectangle
            -2 times Vokl MA of 20 days
Author : wiselytoh V1.0


minAvgVolume = 0;

function rectBaseBreakout() 

 global vav20d;
  hhv9d = HHV(H, 9);
  llv9d = LLV(L, 9);

  hhv1m = HHV(H, 20);
  llv1m = LLV(L, 20);

  hhv2m = HHV(H, 40);
  llv2m = LLV(L, 40);

  hhv50d = HHV(H, 50);
  llv50d = LLV(L, 50);

  vhhv60d = HHV(V, 60);

  cav50d = MA(C, 50);
  vav20d = MA(V, 20);

  C1 = H > Ref(hhv9d, -1);
  C2 = L > Ref(llv9d, -1);
  C3 = C > Ref(hhv50d, -1);
  C4 = C > cav50d;
  C5 = V > (vav20d * 2);
  C6 = vav20d > minAvgVolume;
  C7 = cav50d > 0;
  C8 = (llv1m < (llv2m * 1.05)) OR (llv1m <= (llv2m + 1));
  C9 = (hhv1m > (hhv2m * 0.95)) OR (hhv1m >= (hhv2m - 1));

  return( C1 AND C2 AND C3 AND C4 AND C5 AND C6 AND C7 AND C8 AND C9 );

Buy = rectBaseBreakout();
//Sell = 0;

Filter = Buy;

AddTextColumn( FullName(), "Full name", 1, colorDefault, colorDefault, 200);
AddColumn(C, "Close", 1.3,colorDefault,colorDefault,50);
AddColumn(V/1000, "Vol (K)", 8.0, colorDefault,colorDefault,60);
AddColumn(V/vav20d,"xVol", 5.1, colorDefault, colorDefault,50);
type or paste code here

You would need to reverse all that you want "reversed"

I would copy this to an empty script and then take it from there, step by step. Most things are easy. For example:

C1 = H > Ref(hhv9d, -1);

Will become:

S1 = L < Ref(llv9d, -1);

Just take it step by step like that. Change the return to something like:

return( S1 /* AND C2 AND C3 AND C4 AND C5 AND C6 AND C7 AND C8 AND C9*/ );

Now your sell condition (that is why I call it S1) the return will only take rule 1 into account. Then add the next rule:

return( S1 AND S2 /* AND C3 AND C4 AND C5 AND C6 AND C7 AND C8 AND C9*/ );

Every time check your results...

Probably I am missing some steps here and there but that would be the way.

Great Thanks Henri!

I find this very useful. Credit to Wisely Toh. Hope more experts can look into to improve on it and share.

Perhaps a Trailing Stop as a Sell signal.
Or a break down through a moving average.
Or a move back into the box?
Many, many options available to you.

Thank you Chris!

Hope you try it out for yourself as well. Seem like quite a decent script for mid to long term trade.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.