When you post code please use the CODE button (Alt-S)!
Sure . I will do it from the next time. Thanks
Do you have any suggestion on my given problem. ?
When slow Ma crosses fast Ma then Buy trade will close.
Closing Trade Criteria for Sell Trade:
When Fast Ma crosses Slow Ma then Sell trade closes."
This is mutual. How do you want to differentiate between what is crossing which?
and Slow MA crosses Fast MA for opening sell Trade."
So basically you open and close a sell and a buy on the same signal. How do you differentiate?
When slow Ma crosses fast Ma then Buy trade will close.
Closing Trade Criteria for Sell Trade:
When Fast Ma crosses Slow Ma then Sell trade closes."
This is mutual. How do you want to differentiate between what is crossing which?
and Slow MA crosses Fast MA for opening sell Trade."
So basically you open and close a sell and a buy on the same signal. How do you differentiate?
Just now i have updated my source code . Please have look into it.
fast_ma: 10ema
Slow_ma: 20ema
When,
10ema > 20ema : Open Buy Trade
10ema < 20ema: Open sell Trade
when,
20ema > 10ema: Closing Buy Trade
10ema > 20ema: Closing Sell Trade
You already have an enumeration.
Don't use strings, don't use ints.enum yes_no { yes=0, //yes no=1, //no }; ⋮ extern yes_no losses=1; //Close losses ⋮ if(CountDeals()<max_deals && EnumToString(losses)=="no") CheckForOpen();
Use the enumeration. enum yes_no{ yes, no }; ⋮ extern yes_no losses=no; //Close losses ⋮ if(CountDeals()<max_deals && losses==no) CheckForOpen();
-
int ticket=-1; ⋮ if(OrderSelect(ticket,SELECT_BY_TICKET)==false) return;
EAs must be coded to recover. If the power fails, OS crashes, terminal or chart is accidentally closed, on the next tick, any static/global ticket variables will have been lost. You will have an open order but don't know it, so the EA will never try to close it, trail SL, etc. How are you going to recover?
Use a OrderSelect / Position select loop on the first tick, or persistent storage (GV+flush or files) of ticket numbers required.
-
You should be able to read your code out loud and have it make sense. You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled where as Long_Entry sounds like a trigger price or a ticket number and “if long entry” is an incomplete sentence.
Don't you mean && here? The EAs order and on the current chart? if(OrderMagicNumber()==magic || OrderSymbol()==Symbol()) h++;
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I need your help regarding closing the current running trade. Then open a new trade after closing the previous.
here in this EA 1 trade got open then again next trade is opening without closing the previous one. It keeps moving lke that.
Here is the Code of my EA.
2 moving Average.
Fast Ma crosses Slow Ma for opening Buy Trade
and Slow MA crosses Fast MA for opening sell Trade.
Closing Trade Criteria for Buy Trade :
When slow Ma crosses fast Ma then Buy trade will close.
Closing Trade Criteria for Sell Trade:
When Fast Ma crosses Slow Ma then Sell trade closes.