-
int nextValidWAEDirection = 0,//0 = Either; 1 = Long; 2 = Short; lookingForTrade= 0;//0 = Not looking, 1 = Long, 2 = Short ⋮ int test = qqeState() == 1 ||qqeState() == 3 ? 2 : 1; enumeration Direction{eEither, eLong, eShort};
Don't use ints when you mean enumerations.It also makes your code self-documenting.
enumeration Status{eIdle, eBuy, eSell}; Direction nextValidWAEDirection = either; Statis lookingForTrade= eEither; ⋮ int test = qqeState(); Print(test); nextValidWAEDirection = test == 1 || test == 3 ? eShort : eLong;
-
№ 1: Don't cut-and-paste code. call the function once, use twice.
-
№ 1: What does one (1) and three (3) mean? A different enumeration?
-
if(!IsNewCandle()) return;
I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
Running EA once at the start of each bar - MQL4 programming forum (2011) -
isPrimaryTriggered();
That looks like it returns a boolean, but you don't check the value.
-
bool isPrimaryTriggered(){ int mHandle = iCustom(_Symbol,_Period,"Waddah Attar Explosion",
Perhaps you should read the manual, especially the examples.
How To Ask Questions The Smart Way. (2004)
How To Interpret Answers.
RTFM and STFW: How To Tell You've Seriously Screwed Up.They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick/OnCalculate (after the indicator has updated its buffers), you use the handle, shift and count to get the data.
Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 (2020)
How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 (2020)
How to call indicators in MQL5 - MQL5 Articles (2010) -
void PlaceOrder( int nCurBias, double dbLots, int nStopLoss, int nSlippage, int nmaxSpread, int nmagicNumber ) { if( OrdersTotal() == 0 )
Magic number only allows an EA to identify its trades from all others. Using OrdersTotal/OrdersHistoryTotal (MT4) or PositionsTotal (MT5), directly and/or no Magic number/symbol filtering on your OrderSelect / Position select loop means your is incompatible with every EA (including itself on other charts and manual trading.) -
int nTicket = OrderSend( _Symbol, bBuy ? OP_BUY : OP_SELL, dbLots, dbPrice, nSlippage, dbStopLossPrice, dbTakeProfitPrice, "Primary Order", nmagicNumber, 0, bBuy ? clrBlue : clrMagenta );
The above is MT4 call, but you posted in the MT5 general section and posted MT5 code.
Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 programming forum (2013)
PositionClose is not working - MQL5 programming forum (2020)
MagicNumber: "Magic" Identifier of the Order - MQL4 Articles (2006)
Orders, Positions and Deals in MetaTrader 5 - MQL5 Articles 2011
You need one Magic Number for each symbol/timeframe/strategy. Trade current timeframe, one strategy, and filter by symbol requires one MN.
-
I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
Running EA once at the start of each bar - MQL4 programming forum (2011)
Ok, I'm surprised that was all to be honest. But thank you for the input, I'm working on putting it into practice and doing some follow up research.
As for the new bar function. I have the same issue with the one in your link as I do with the one I was using before. It's very common for things to go off on init even if they aren't in the init function. I've searched and searched for an explanation but can't find one anywhere.
//+------------------------------------------------------------------+ //| Variables | //+------------------------------------------------------------------+ static datetime lastBarOpenAt; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { bool isNewBar = lastBarOpenAt != iTime(_Symbol, PERIOD_CURRENT, 0); if (isNewBar){ lastBarOpenAt = iTime(_Symbol, PERIOD_CURRENT, 0); Alert("New bar"); } }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello all,
I have been working on learning how to code an EA from scratch. I started in MQL4 and then moved it over to MQL5. I've made some mistakes and reworked it several times. And I'm posting for a critique of my coding style and ability.
DISCLAIMER:
NO I am not looking for anyone to code or debug for me!I'm looking for input on things I need to root out of my habits in order to code better and need less help in the future.
Since I'm looking for a general coding critique, I shouldn't need to post "things I have tried" but I will anyway just to make sure I attempt to satisfy everyones posting standards.
- I have started trying to cut down on nested statements and to make better use of if statement shorthand. I still need to rework some of them.
- I coded this one with the idea of trying to make each of the functions as self contained as possible so that I could test them and not have to worry about breaking one functions by working on another.
-I have read the documentation page for any function I have had issues with, and I have watched dozens of videos and read articles.
If you don't like my post for whatever reason, please feel free to pass it by. No one is holding a gun to your head to reply to this.
Not all functions are in use yet. But, before I get too far into this project, I want to make sure I'm not ingraining any horrible practices into my coding. I would rather learn to do things right and move on from there.
That being said, please try to be kind. I'm new to this and am indeed putting a lot of effort into learning.