im struggling with EA to take trades on a specific signal

 

im trying to build my first EA. and the first step was to try to make the EA take a buy och sell position on a specific indicator.

what i was expecting was to see a trade placement on the bar after the signal (which i have marked with red in the screenshot). but it seems that its placing orders a bit random, any ideas on why?

Files:
backtest.JPG  315 kb
code.JPG  173 kb
 
Ddog: im trying to build my first EA. and the first step was to try to make the EA take a buy och sell position on a specific indicator. what i was expecting was to see a trade placement on the bar after the signal (which i have marked with red in the screenshot). but it seems that its placing orders a bit random, any ideas on why?

If you require help with MQL4, then please post in the relevant section at the end of the forum — MQL4 and MetaTrader 4. A moderator will move it for you  as soon as it is spotted by them.

When requesting help with code, then please supply actual code for testing, and not a screenshot of code. Either do it via a file attachment on your post or by inserting the sample code via the "</>" icon "Code (Alt+S)". It is best to supply code that can be compiled and tested.

When debugging your code in the tester or live, then print out key variables and states to the log file in order to detect problems with the logic in your code. Also show those results in your post when requesting guidance.

 
Ddog:

im trying to build my first EA. and the first step was to try to make the EA take a buy och sell position on a specific indicator.

what i was expecting was to see a trade placement on the bar after the signal (which i have marked with red in the screenshot). but it seems that its placing orders a bit random, any ideas on why?

I think is because of the indicator buffers that you choose ... your trade filters => if buffer 0 >=0,1 you buy, and when buffer 1 >=0,1 you sell... your indicator is printing green/red dots, but maybe is not  printing  only when this buffers are >=0,1.

Maybe have other conditions for printing the dots.

Put only indicator in the tester and observe the values of all buffers when a dot is printed. 

Reason: