Ea opening plenty of trades instead of one per conditions

 

Hi,

I've coded all my indicators and everything is working only when im backtesting my strategy the ea opens more than one trade because the conditions remain valid

Could someone help me out that it would open only trade per valid conditions?


Here my code for opening trades

Files:
 
Fujin: I've coded all my indicators and everything is working only when im backtesting my strategy the ea opens more than one trade because the conditions remain valid. Could someone help me out that it would open only trade per valid conditions?

If you expect proper help and guidance then you are going to have to provide real working code to be analysed. Providing a screenshot of something resembling a bad copy/paste snippet is just not going to get you anything.

If you don't want to open multiple trades, then you will have to keep track of when positions are placed, and maybe even only detect signals when a new bar is formed.

 
Fernando Carreiro #:

If you expect proper help and guidance then you are going to have to provide real working code to be analysed. Providing a screenshot of something resembling a bad copy/paste snippet is just not going to get you anything.

If you don't want to open multiple trades, then you will have to keep track of when positions are placed, and maybe even only detect signals when a new bar is formed.

 I attached my code file at the top!
 
Fujin #I attached my code file at the top!

Your code logic is too simplistic and very inefficient.

  1. You are creating Indicator handles on every tick. Don't do that! Create the handle in the OnInit event and then use them when needed in the OnTick.
  2. Instead of checking current Indicator values, consider only checking them once the bar has closed. The current values are always in flux due to the current close price still evolving. So keep track of when a bar is closed. Search the forum for how to only carry out the evaluation on a new bar detection.
  3. Keep track of an open trade, either by tracking it, or by keep a state variable that lets you know not to place any more orders until the signal has reversed. You can do this in a similar way to how to detect a new bar.