So, AddToComposite as it name says, does not "create" composite. It ADDS to composite.
It is worth noting that code is executed potentially many times (for example when you press "Verify formula" or "Apply formula" when you run the code in chart, etc) and for every symbol in Analysis.
Besides, your looping code does not make sense. Instead of what you are doing you should just write:
value = 1; // ALL that is needed
Or if you want zero for first bar:
value = IIF( BarIndex() == 0, 0, 1 ); // all that is needed
You can't be "almost sure". Either you are sure or you are not. And because "almost" word, you are not sure. To be sure use debug techniques, especially TRACE see: How do I debug my formula?
Also, "last 1 bar" setting for composites is plain wrong.
Thank you for your philosophical approach. I agree with you on I am not sure and not agree with you that I can't be "almost sure". You are thinking digitally. May be this is a side effect of being a very good coder. To me, there are infinite number of "not sure" situations and some of them are closer, some are more close to being sure. "Almost sure" means a closer one.
Thank you also for your ssuggestion. I will check with TRACE. Please also let me know if you also have a shortcut solution idea for my problem.