I'm currently setting up a buy order when a certain condition is true. The problem I'm running into is the stoploss is triggering and then trying to re-purchase the buy order right away.
So, the end result is multiple trades per day that is just eroding the capital.
How can I put something in my code that basically says... "When s/l triggered, don't buy anything else today"?
static bool isBuyCondition=false;
bool wasBuyCondition = isBuyCondition;
isBuyCondition = ...;
if(!wasBuyCondition && isBuyCondition) // Now open.
So let's go with a more specific situation:
if close is > than MA(5) --> BUY
if close is <= SL --> SELL
The problem is arising that on the same day the price will drop below the SL and then pop back up and re-purchase. I know one solution is to not set the SL so close, but I also want to add in "Don't BUY if it was closed today".
Can you show me a more specific example using these parameters?
When you open a trade for the day, set a variable containing the dateTime value for the daily candle.
https://docs.mql4.com/series/itimeiTime() will tell you information you need.Then just check that before you open a new order.