Hi there,
This is my first post to this forum.
I created an EA based on the following system http://forums.babypips.com/free-forex-trading-systems/507-45-pips-per-day-system-eur-usd.html.
Entry is crossover of macd over signal followed by SAR and ADX confirmations, or flip of SAR followed by macd and ADX confirmations.
Exit is to TP at 30 pips or be stopped out at SAR. Will upgrade to incorporating BE functionality if I can get this piece up and running.
Not sure why the Tester doesn't show the trades.
I created a tester.tpl template with settings as below:
The outcome was no trades placed.
The journal appears as below:
The code (MQL4) is as below and I the file is attached.
If anyone could point me in the right direction, that'd be lovely.
Thank you.
<CODE DELETED>
Please read some other posts before posting . . .
Please edit your post . . . please use the SRC button to post code: How to use the SRC button.
Read this and implement it: What are Function return values ? How do I use them ?
You have a globally declared variable called OrderDirection, you also have this variable declared locally in some Functions, which one should your Functions use ? why not make things clearer and use a different variable name ?
Thanks for both src button info and variable name suggestion.
I think I've only decalared and initialised that variable once in the global area and later reassigned values to it, although at times, reassigned it the same value it already had.
Thanks again.
Thanks for both src button info and variable name suggestion.
I think I've only decalared and initialised that variable once in the global area and later reassigned values to it, although at times, reassigned it the same value it already had.
Thanks again.
Please edit your first post.
You have declared the variable in the function declaration . .
double CalcStopLoss( int OrderDirection )
In an attempt to simplify this, I've excluded all of the time related funtions and only focusing on opening and closing orders with a simple MACD crossover of signal now. The function that calculates the MACD line and signal line is as below. It differs from the values of the IBFX Traditional MACD indicator and I'm not sure why. Can you please confirm that my code and logic is accurately applied? Am quite the noob at all this and although I thought I had it mostly figured out, am starting to wonder how to make progress with this now. Any assistance much appreciated. Thanks.
void CalcMACDAndSignalValues(){ // populate arrays for the EMA values to to calculate the MACD Line and Signal Line for(int s = 0; s < 10; s++) { FastEMAArray[s] = iMA(NULL, TIMEFRAME, FAST_MACD_EMA, 0, MODE_EMA, PRICE_CLOSE, s+1); SlowEMAArray[s] = iMA(NULL, TIMEFRAME, SLOW_MACD_EMA, 0, MODE_EMA, PRICE_CLOSE, s+1); // MACDlineArray holds values for the MACD Line and is used to calc the Signal Line. // The MACD Line will only use the current and previuos values but the signal will use 9 values. // The MACD Line = the diffence between the 2 EMAs. if(s < 9) { if(FastEMAArray[s] > SlowEMAArray[s]) MACDLineArray[s] = FastEMAArray[s] - SlowEMAArray[s]; if(FastEMAArray[s] < SlowEMAArray[s]) MACDLineArray[s] = SlowEMAArray[s] - FastEMAArray[s]; } } // Determine values of PreviousMACD, CurrentMACD, PreviousSignal, CurrentSignal PreviousMACD = MACDLineArray[2]; CurrentMACD = MACDLineArray[1]; PreviousSignal = iMAOnArray(MACDLineArray, 0, 9, 0, MODE_SMA, 2); CurrentSignal = iMAOnArray(MACDLineArray, 0, 9, 0, MODE_SMA, 1); }
In an attempt to simplify this, I've excluded all of the time related funtions and only focusing on opening and closing orders with a simple MACD crossover of signal now. The function that calculates the MACD line and signal line is as below. It differs from the values of the IBFX Traditional MACD indicator and I'm not sure why. Can you please confirm that my code and logic is accurately applied? Am quite the noob at all this and although I thought I had it mostly figured out, am starting to wonder how to make progress with this now. Any assistance much appreciated. Thanks.
Thanks RaptorUK.
double FastEMAArray[10]; double SlowEMAArray[10]; double MACDLineArray[9];
The related variables in the global area look like this:
// MACD signal related variables. extern int FAST_MACD_EMA = 12; extern int SLOW_MACD_EMA = 26; extern int SIGNAL_PERIOD = 9; double FastEMAArray[10]; double SlowEMAArray[10]; double MACDLineArray[9]; double PreviousFastEMA = 0; double CurrentFastEMA = 0; double PreviousSlowEMA = 0; double CurrentSlowEMA = 0; double PreviousMACD = 0; double CurrentMACD = 0; double PreviousSignal = 0; double CurrentSignal = 0; bool MACDCrossedUp; bool MACDCrossedDown;
Thanks RaptorUK.
The related variables in the global area look like this:
OK, so you are declaring the arrays with an initial size, that is good otherwise you would have to ArrayResize().
Add Print() statements everywhere you need to check that a variable has the correct value so you can debug your code. IMAOnArray() is a bit of a pain, it's not very clearly documented, especially the consequence of using/not using an array set as a series array, you are going to have to suck it and see . . . unless you find the documentation clear than I do. I've never had to use iMAOnArray so it's not something I have ever had to get fully to grips with.
Your Code | if(IsNewCandle()) TradingConditionsChecked = CheckTradingConditions(); <= Only this line is skipped if(TradingConditionsChecked) <= if not a new candle what is this value? // if yes then check if market is open according to relevant session Times. MarketOpen = CheckIfMarketOpen(); // if yes then place trade if(MarketOpen) <= if TradingConditionsChecked is false, what is this value? OrderEntry(OrderDirection); <= How many opens per bar? there is no check |
Code now matches your indenting | if(IsNewCandle()){ TradingConditionsChecked = CheckTradingConditions(); if(TradingConditionsChecked){ // if yes then check if market is open according to relevant session Times. MarketOpen = CheckIfMarketOpen(); if(MarketOpen){ // if yes then place trade OrderEntry(OrderDirection); } // MarketOpen } // TradingConditionsChecked } // IsNewCandle |
Thanks for the tips RaptorUK and WHRoeder.
Yes, the print statements help alot.
Oh yeah, I can totally see how the braces need to go in!
Thanks to you both for your assistance. I'm slowly progressing with coding this little EA and learning heaps in the process.
Happy days.
- 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 there,
This is my first post to this forum.
I created an EA based on the following system http://forums.babypips.com/free-forex-trading-systems/507-45-pips-per-day-system-eur-usd.html.
Entry is crossover of macd over signal followed by SAR and ADX confirmations, or flip of SAR followed by macd and ADX confirmations.
Exit is to TP at 30 pips or be stopped out at SAR. Will upgrade to incorporating BE functionality if I can get this piece up and running.
Not sure why the Tester doesn't show the trades.
I created a tester.tpl template with settings as below:
The outcome was no trades placed.
The journal appears as below: