I've been trying to write an EA, and to help get more precise about getting to a peak in the price before placing a sell order (in a strong uptrend), I've been trying to use a while loop - only when I do so, it seems that the tester goes into an infinite loop - it just doesn't perform the script though there are no errors when compiling.
Below is the loop, if anyone can point out why it's not working or give any suggestions to tweak or modify it, I'd appreciate it.
Below is the loop, if anyone can point out why it's not working or give any suggestions to tweak or modify it, I'd appreciate it.
BuyPriceMax = Bid-(TrailingBuy*Point);
while(Bid>=BuyPriceMax) {
if(Bid>BuyPriceMax+(TrailingBuy*Point)) {
BuyPriceMax = Bid-(TrailingBuy*Point);
Sleep(10000); // SLEEP 10 SECONDS
RefreshRates();
}
}
- Set a "trailing price" (BuyPriceMax) that Bid can be compared with
- While the Bid price is >= BuyPriceMax, keep checking the Bid Price for any increase.
- If price increased, increase BuyPriceMax to the Bid price minus "TrailingBuy" - a variable I use to allow price to dip slightly as it rises higher without exercising the order (similar to what you might set a trailing stop to)
- Once price drops below BuyPriceMax, the loop should stop executing and the order will be placed at the Bid price.
If anyone can help me figure out why Bid always seems to be >= BuyPriceMax, I'd appreciate it. It seems that with the refresh command, once Bid drops far enough, it should end the loop so that my order can be placed.
Thanks!