On two different EAs I can go long and short but if I try to get one ea to do both it instantly closes the position upon entering it. Any ideas?
Hey Guys,
I am struggling with getting my ea to trade both directions without immediately closing them.
Any suggestions? I am relatively new to coding.
Fix the compiler warnings for lines 78 and 119, and you'll see improvement.
Hey,
Are you using different magic numbers?
Hey,
Are you using different magic numbers?
I am not, I need different magic numbers within the same ea?
Fix the compiler warnings for lines 78 and 119, and you'll see improvement.
I'll give that a shot, thank you
Hey Guys,
I am struggling with getting my ea to trade both directions without immediately closing them.
Any suggestions? I am relatively new to coding.
Won't solve your immediate problem, but you might need to look at the structure of your coding.
A quick look told me you have just the standard functions: OnInit, OnTick, OnDeinit..I'm no expert, but if you separate out some of the code actions into functions, it makes it a lot easier to read and debug.
Take this segment, in OnTick(), which I'm guessing is to identify a sell order?
if(Bid < ThirtyMinuteEMA) { if(ThirtyMinuteCCI>-100) if(CurrentMACDSignal<PreviousMACDSignal) if((TimeCurrent()>= StrToTime(StartTrading)) && (TimeCurrent() <= StrToTime(StopTrading))) if(AccountBalance() > StopTradingBalance) if(Bid < FiveMinute200PeriodEMA) if((FirstClose>CurrentSlow) && (SecondClose<CurrentSlow)) if(OrdersTotal()==0) // etc
That code is a prime candidate to put into a separate function like this, away from OnTick()
void OnTick(){ // other code if(IsSellOrder()) ticket=OrderSend(..); } bool IsSellOrder(){ if(!cond0)return false; if(!cond1)return false; return true; }
For me, this makes it easier to read, and debug.
- www.mql5.com
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hey Guys,
I am struggling with getting my ea to trade both directions without immediately closing them.
Any suggestions? I am relatively new to coding.