Expert Advisor places trade immediately after adding to chart.

 

Hey,

I was wondering if anyone has this same problem as the title.

After adding an expert advisor to my mt4 chart it immediately places a trade. (conditions not met)…..Then after this (random) trade it works perfectly.

Anyone else has this?

Thanks again


 
apinkdog:

After adding an expert advisor to my mt4 chart it immediately places a trade. (conditions not met)…..Then after this (random) trade it works perfectly.

Post the code if you would like people to help.

 
Keith Watford:

Post the code if you would like people to help.

Thanks for the suggestion.

Just wondered if anyone else had come across this as well (without posting code)

 
apinkdog:

Thanks for the suggestion.

Just wondered if anyone else had come across this as well (without posting code)

how we should analyze your problem without code?

 
amando:

how we should analyze your problem without code?

For example: it might be a common problem that other people had come across and knew how to fix.

 
apinkdog:

For example: it might be a common problem that other people had come across and knew how to fix.

after 10000 of ea's?

 

There are many ways to prevent it — depends on how it's coded. We can't see your broken code — we can only guess.

One way is not to not look at a signal (e.g. price above MA.) Act on a change of signal.
          MQL4 (in Strategy Tester) - double testing of entry conditions - Strategy Tester - Expert Advisors and Automated Trading - MQL5 programming forum #1

If it only triggers on a new bar, initialize on the first tick.

 
apinkdog:

Hey,

I was wondering if anyone has this same problem as the title.

After adding an expert advisor to my mt4 chart it immediately places a trade. (conditions not met)…..Then after this (random) trade it works perfectly.

Anyone else has this?

Thanks again


Possibly your OnTick() is being called before your conditions have been set up? You could try delaying the OnTick() through a counter or boolean until your program is ready to trade....

 
apinkdog:

Hey,

I was wondering if anyone has this same problem as the title.

After adding an expert advisor to my mt4 chart it immediately places a trade. (conditions not met)…..Then after this (random) trade it works perfectly.

Anyone else has this?

Thanks again


I have seen that problem a couple of times. It wouldn't be happening if you used arrays to define your exact entry points. Your trading conditions were met in the past before the period that you are testing from. Therefore, a trade will be opened on chart drop. Then in the future you control trading by declaring that the trading function should not run when a position is present. Thus your observations.

 
If the EA is set to place a trade under certain conditions, and those conditions are present at the time when you place it on the chart, then that could explain why this is happening. But there could be something wrong with the EA. There appears to be some generous people here who want to help you. If you are not willing to post your code, then the best solution is to hire someone to fix your EA for you (if it needs fixing), so that it meets your expectations. 
 
andrew:

Possibly your OnTick() is being called before your conditions have been set up? You could try delaying the OnTick() through a counter or boolean until your program is ready to trade....

Nelson Wanyama:

I have seen that problem a couple of times. It wouldn't be happening if you used arrays to define your exact entry points. Your trading conditions were met in the past before the period that you are testing from. Therefore, a trade will be opened on chart drop. Then in the future you control trading by declaring that the trading function should not run when a position is present. Thus your observations.

cvdestyfx:
If the EA is set to place a trade under certain conditions, and those conditions are present at the time when you place it on the chart, then that could explain why this is happening. But there could be something wrong with the EA. There appears to be some generous people here who want to help you. If you are not willing to post your code, then the best solution is to hire someone to fix your EA for you (if it needs fixing), so that it meets your expectations. 

really appreciate all the help from everyone despite no code.

Fixed it by taking out parts of code and running the strategy tester each time.....

For some reason having two OP_BUY order sends inside one conditional, it would cause the problem as described above. When one was taken out it solved the problem.

I know there is logic as to why but it hurts my head to try to understand my messy code. 

Thanks again everyone.


Reason: