Please help code me this thing?

So I am trying here to code supply areas and want to short when the prices retrace to this supply.
I define supply area as follows -

  1. First wait for a long red bar to form (where open - close > 5% * close)
  2. Now if any of next bar comes atleast to the 50% of this bar, then it should short it.

The main thing here is that I want the code to look at supplies and record them in the last 60 candles and then wait for the retest. I am only looking for the fresh retests. I.e. if there is a retest to the long candle, that long canldle should be forgotten by the code. However all the remaining supplies (Within last 60 candles) should remain in memory of the code.

I will attach the screenshot for this. Supply

Here is what I have tried to write.

longcandle = Open - Close > 0.005 * Close ;
Count = 0;
Short = 0;
for (i = 0 ; i < 500 ; i++)
{
	Chosen_candle_high[i]=0;
	Chosen_candle_mid[i]=0;
}
for(i = 0 ; i < BarCount-1 ; i++)
{
	if(longcandle[i])
	{
		Chosen_candle_high[Count] = High;
       //Chosen_candle_high = High[i];


		Chosen_candle_mid[Count]=0.5*(High-Low);
		Count++;
	}
}
for (i = 0 ; i < 500 ; i++)
{
	Chosen_candle_mid_touched[i]=0;
}

for(j = 0 ; j < BarCount-1 ; j++)
{
	for(i=0;i<Count;i++)
	{
			if(Chosen_candle_mid_touched[i]==0)
			{
				if(High>=Chosen_candle_mid[i])
				{
					Chosen_candle_mid_touched=1;
 					Short = 1;
				}
			}
		
	}		
}

Please help me with this. I have been trying to write this code for so long but not able to.
Thanks :slight_smile:

You're struggling because you have not yet grasped how arrays work in AmiBroker. Start by reading this:
https://www.amibroker.com/guide/h_understandafl.html

Based on my understanding of your request, you should not require any looping code, and certainly not loops within loops. Here's a bit of untested code to get you started. It is not meant to be a complete solution, but just a short example showing some of the functions you will likely want to use.

// NOTE: Your code uses 0.005 which is one half percent, not five percent as stated in your description
isLongRedCandle = O-C > 0.05 * C;
midPrice = ValueWhen(longRedCandle, 0.5 * (H-L));
Short = BarsSince(Ref(isLongRedCandle,-1)) < 60 AND H > Ref(midPrice,-1);

You are not right, IMO.

Such things do require looping.
Your code just draws single line. But he rather seems to want to keep (multiple) lines of the past "alive" until broken by price or ending because of a set time limit.

See below picture. Lower pane is applying your code (with fix 0.5 * (H+L) -> + instead of -). And upper pane uses looping code. (The light blue arrows are just some n-bar Cover stop in both panes).

30

BTW, now after re-looking the picture of first post he seems to be looking for re-test from above after crossing from below bars before. But that's just subsidiary thing....


Anyway, code on how to do the core part exists in forum/KB/manual already...

Thanks fxshrat for replying on the post.
I am new to Amibroker and it seems that the thing which I need a lot of coding. Anyway can you please share the excat link (since there is so much stuff on knowledge base) on knowledge base so that I can go through it ?
Thanks once again

Can you code it for me fxshrat ? It would be a great help for me :blush:

Here is an article I stumbled across that describes one way to identify retests of resistance after a breakout has occurred. It is not exactly what you are doing, but his simple logic and clear explanations could give you a good starting point.

Good luck!

1 Like

Thanks for the concern Qedges. Really appreciate it. But the above code only accounts for the recent breakout but I want the code to record last various breakouts and then forget one by one when it retest it.