I am trying to add a loop in an trading EA someone code for me. The EA uses an external indicator which supplies the BUY and SELL signals the EA uses to open/reverse trades. I have managed to add a few cool things to the original version by reading the manuals and internet searches. But, I can't figure out how to properly write the loop and how to insert it in the code.
Current code for a BUY signal from the external indicator:
This works when the condition was met before the current bar, but sometimes it is met in a future bar (when the external indicator doesn't send signal). Instead, I would like for the EA to wait until the condition is met.
StochConfirmation can be manually set to "true" or "false"STO1 = iStochastic(NULL,0,KPeriod,3,3,MODE_SMA,0,MODE_MAIN,1);STO2 = iStochastic(NULL,0,KPeriod,3,3,MODE_SMA,0,MODE_MAIN,2);
Help would be greatly appreciated
Hi, you can paste your code inside form at SRC
will be look better :)
extern bool StochConfirmation=false;
extern int KPeriod=14;
double STO1 = iStochastic(NULL,0,KPeriod,3,3,MODE_SMA,0,MODE_MAIN,1);
double STO2 = iStochastic(NULL,0,KPeriod,3,3,MODE_SMA,0,MODE_MAIN,2);
// To BUY and Reversing a Sell
if(PopUp)Alert("(SC EA) - BUY order was placed - "+Symbol());
if(Email)SendMail("New Order "+Symbol(),"a Buy Order has been placed and closed any Sell order");
if(PushNotification)SendNotification("Buy Order is Placed "+Symbol());
Hi Yohana Parmi and whroeder1,
Here is the section of the code that is activated by the BUY signal from the external indicator. The EA works fine but want to add a loop because the condition is not always met in previous candles but will be in the future (usually, the following candle).
** The condition is ignored when StochConfirmation=false (which I want).
Now: If StochConfirmation=true and STO1<STO2, the EA continues and opens the trade.Instead: I would like the condition be: if StochConfirmation=true WAIT for STO1<STO2.
Hope this clarify things for you.
My problem is that my "external indicator" doesn't send a signal at every bar. So, if STO1<STO2 is not true during the bar the "external indicator" sends a signal, the trade is not made.
Often, STO1<STO2 is "true" the following bar and I miss the trade. I am hoping a loop can fix this. I have tried to figure this out on my own but can't manage to make it to work.
Any guidance or help would be great.
You indicator shouldn't "signal at every bar," if it did, it would be broken.
Stop hoping and start thinking. A loop will not fix anything. There are no "following bars;" there are only the current bar and previous bars.
You look for a signal on bar one, do or do not, and then return. When you get a new tick and it's a new bar, you look for a signal on bar one.
The return, wait for a tick, process the tick is your loop.
OK. I did write something that checks for a signal on the previous bars.
It works but I was looking at the different Loop Operators (for, while, do while) for use instead of (STO1<STO2))||!StochConfirmation).