How to stop triggering on a re-print?

To add comments, please log in or register
jthornton
70
jthornton  

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"?

whroeder1
17942
whroeder1  
jthornton: I'm currently setting up a buy order when a certain condition is true.
Don't do that. Open the order when you get a change in condition.
static bool isBuyCondition=false;
bool wasBuyCondition = isBuyCondition;
isBuyCondition = ...;
if(!wasBuyCondition && isBuyCondition) // Now open.
jthornton
70
jthornton  
whroeder1:
Don't do that. Open the order when you get a change in condition.

So let's go with a more specific situation:

if close[0] is > than MA(5) --> BUY

if close[0] 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?

Jack Thomas
1635
Jack Thomas  
jthornton:

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"?

When you open a trade for the day, set a variable containing the dateTime value for the daily candle.

https://docs.mql4.com/series/itime

iTime() will tell you information you need.

Then just check that before you open a new order.


iTime - Timeseries and Indicators Access - MQL4 Reference
iTime - Timeseries and Indicators Access - MQL4 Reference
  • docs.mql4.com
iTime - Timeseries and Indicators Access - MQL4 Reference
jthornton
70
jthornton  
Jack Thomas:

When you open a trade for the day, set a variable containing the dateTime value for the daily candle.

https://docs.mql4.com/series/itime

iTime() will tell you information you need.

Then just check that before you open a new order.


The variable carries the value from bar to bar?
whroeder1
17942
whroeder1  
jthornton: "Don't BUY if it was closed today".
If you want that, code that specifically.
  1. Go through history and find the latest order open time.
  2. Compare it to today's date. See Draw rectangle around range of bars by hours - MQL4 and MetaTrader 4 - MQL4 programming forum
To add comments, please log in or register