- Joined
- 11 December 2011
- Posts
- 10
- Reactions
- 0
It takes an exit the next bar after the buy because the variable "BuyPrice" is a reserved variable which is an array. You assign "Close" to the BuyPrice at the beginning of the formula outside the loop so on every iteration of the loop the variable "PriceatBuy" is assigned the close price of that particular bar. That's why your exits are triggered immediately after your entry.
Captian black, sorry. BuyPrice is an array, but PriceAtBuy no, it is a single number. It is created for to be single number.
I think "PriceAtBuy" only acquires a non-zero value inside the loop, when a buy signal (Buy = = 1) outside the loop. And "PriceAtBuy" retains this value until it is one of the other conditions in the rest of the loop is satisfied. That is the intent of the code. Am I wrong?
As I think that the code works? In the beginning in the code, the bars are being evaluated for buy signal. When a buy signal and reaches the loop, all bars from that which generated the buy signal are evaluated. If some condition is met, an action is generated. If not, move on to the end. I may be wrong about what I believe is the logic of program operation.
Thanks.
Edilson