Help with an EA

 

I put together an EA that seems to work quite well, when it works right. There is a glitch that I can't figure out. I use moving averages as a filter and sometimes it places a trade when it shouldn't according the the MAs. I think the problem is with the process the platform goes through when reading the code and not updating the values often enough.

I know that is vague and posting the file would make matters easier. I am not ready to give it out publicly, but am looking for somebody that may be willing to help me figure it out. PM me if you are interested.

 

is your strategy looking to the last closed bar

or is the ea reading the current tick iMA?

 

It does check the last price so it should recalculate every tick. This is what I have for the iMA.

double RSI = iRSI(NULL, RSI_TF, RSI_PERIOD, PRICE_CLOSE, 0);

double MA5S = iMA(Symbol(),PERIOD_M5,MASlow,0,MODE_SMA, PRICE_CLOSE, 0);

double MA5F = iMA(Symbol(),PERIOD_M5,MAFast,0,MODE_SMA, PRICE_CLOSE, 0);

double MA1 = iMA(Symbol(),PERIOD_H4,MAPeriod,0, MODE_SMA, PRICE_CLOSE, 0);

 

so your ea is taking trade when it should not? or not yet?

sometimes current tick iMA crossed on a few tick and then back-off

could this be the cause of your ea's problems.

 

It places a trade when it should not, but only after several hours. For example, last night on the EURUSD it went short when it should have been looking for buys. The MAs crossed over and instead of changing the direction for sell to buy, it continued looking for shorts.

 
icepeak:
It places a trade when it should not, but only after several hours. For example, last night on the EURUSD it went short when it should have been looking for buys. The MAs crossed over and instead of changing the direction for sell to buy, it continued looking for shorts.

This could have something to do with how you're detecting the MA crossovers. For example, if you buy when the fast MA crosses up over the slow MA and sell when the fast MA crosses back down over the slow MA, and you don't filter it any more than that, you're going to get into trouble, especially if you're judging the result based on the most recent bar (shift = 0).

When the two MAs are really close together and then start crossing, they might cross both up and down repeatedly, giving you false trading signals, possibly in both directions in a short period of time.

You've got to program some kind of threshold to cross before you accept a cross up or a cross down so it doesn't whipsaw.

 

icepeak, will you post a little more of your trade logic - at least just the part where conditions for long and sell are

then we'll see where the error could be

 

Here it is

I'll attach the file. I think that will help out more and I really want to get this working right. It sometimes places trades several bars passed the cross.

I put it on a 5 min chart. The parameters are good for the EURUSD, USDCHF, and USDJPY. I set tighter parameters for the GBPUSD and USDCAD. It enters long if the 4 hr 100 sma is below the current price and the 100 sma on the 5 is above the 200 sma. The RSI must be less than 30. Reverse all that and the RSI must be greater than 70 to go short.

It exits the trade when the RSI hits 63 for a buy and 37 for a sell. It does add to the position if it is negative 30 pips and locks in profit at +40.

I am not a programmer so I just cut and pasted code from a few different EAs and made some adjustments so the code may be a little messy and I didn't add many comments because I didn't intend on giving it out. This particular file is set up for a mini account because I am trading live with it.

Files:
 
icepeak:
It places a trade when it should not, but only after several hours. For example, last night on the EURUSD it went short when it should have been looking for buys. The MAs crossed over and instead of changing the direction for sell to buy, it continued looking for shorts.

can you check your lastnight's trade if it went short because it is adding a short position due to negative 30 pip

 

Last nights trade

It wasn't. There were 12 candlesticks between closing positions of an earlier trade and placing a new trade on the eurusd and 14 between on the usdcad.

 

Here is the EURUSD last night. The blue line is the 100 sma and the red is the 200 sma. You can see it closed trades when the RSI hit 37 then went short again when the RSI reached 70 even though the blue line was above the red.

Reason: