EA building 101 question Need Help please!

 

Hi there -

I have a simple problem and figured this was the bast place to turn to for some helpful advice. I have a very simple ea I put together from the following website:

Expert Advisor Builder for MetaTrader 4

I'm not a programmer, and thought this was the best place to put my ideas to work (instead of posting my brain online here ). The ea works, no doubt about that, and has been giving me some good entries.

My problem comes when it opens a trade, and the buy or sell signal is continued on the next bar, it closes the current buy and starts a new one, creating multiple trades (usually losses) over and over again in a short time span. How do I allow it to only trade once, until the close buy signal is generated?

To my willing experts out there, thank you in advance!

S.

 
TRADE ONLY ONCE ON BAR

Up at the top where you declare your variables put

static bool ITradedOnThisBar;

then where you send your order put

if(Your Critera && ITradedOnThisBar!=Bars)

{

ticket=OrderSend(Symbol(),OP_BUY,... );

ITradedOnThisBar = Bars;

}

Doing This will keep you from opening a trade on the same bar that you already opened a trade on, but more importantly you want to keep it from closing on the same bar so I would also add this code where you close your trade, for example:

if(Your Criteria && ITradedOnThisBar != Bars)

{

OrderClose(OrderTicket(),... ); // close position

}

This is probably the most simple way to do what you are trying to do.

This works if you can find the places to add these statements.

 

Another possibility that is causing your problem is the close of buy and sell statement setting are set and activating very close to your opening buy and sell entry statement setting....Such as buy open at RSI > 60 and Closing the RSI positions < 50. If the RSI is ranging up and down because of price volatility you will be entering and exiting quite frequently. Check how the program statements work by studying the enter and exit points on the graph by expanding the bars and see how they correspond to your in and out logic of your program.

 

Thank you!

Thank you Dave! It seems the close buy logic was holding the issue, but I'm certain your other respose will serve me well down the line. I didnt rationalize too well how the code wouldn't do as I wished it to right off the bat. I'm pretty impressed with this little website otherwise; its allowed me to put my mental garbage to good use . After I fixed this problem my results shot up to an 85% win rate; not bad for a first attempt. Keep you posted and I appreciate, very much, the reply.

S.

Reason: