EMA CROSS upgrade...coders guru please help

 

After reading codersguru's lessons me and the expert advisor wizzard got this far with creating code. I'm just trying to learn to make EA's. I would prefer someone who knows what they are doing to do this but I do want to learn too so I'm trying to make a start at it at least.

This is basically to define the things I'd like to see added to the EMA CROSS already created by coder's guru. Man I would love to see HIM take on this upgrade instead of leaving it to a novice like me.

I like the EMA CROSS system perhaps because I've spent alot of time studying moving average dyanamics. It's something I can get my brain around. What you will notice is that I like to give the user the option to engage certain functions or not in a strategy. This allows for many variations in testing different combinations which forms the basis for comparing and re-evaluating results. I find such compare and evaluation reveals what works well together. I believe in giving users the choice.

I get to explain a couple of the parameters here and where I found the ideas...

I've watched a few different systems operate now. I've gotten ideas from them I'd like to see all incorporated into the EMA cross.

The basket profit idea I got from watching the divergence trader EA which opens multiple orders and pools the equity from them to reach a target and then closes all the orders in the pool together. It occurred to me that this might be an effective method to clean up positions which get 'left behind' in the present EMA CROSS- EA. These positions which go unprofitable need to be cleaned up. I don't know if it will work but it's an idea. I hate to see the EMA CROSS method give back so much after it's made such good gains. It's all about damage control before the damage gets big. clean up the small messes as they happen. that's the idea with this function. (optional of course)

I'm wanting other functions which aren't in the present versions of the EMA cross, (or anywhere else I know of) I'd like to see the ability to execute on a custom bar period. I have no idea how to pull this off but I like the concept since I could do that in my spreadsheet and found several advantages to doing it. Why can't it be done in the metatrader? I think just because no one I know of has DONE it yet. I'm told it can be done buy building the candles from one minute data. There is a custom candle indicator already but I don't know if it engages EA's to execute on that custom candle data or not...well I'd like to see this done with the EMA CROSS method because my spreadsheet told me how advantageous it is to do that with moving average cross strategies. Trust me it matters.

I'd like to see the ability to scale stop losses and trailing stop losses. If we can scale into and out of positions then we should be able to scale down stop loss and trailing stop losses to close positions based on conditions we like. It needs fleshing out but the general idea is to make some conditions to get the most out of closing strategies thru creative stop loss use.

I'd like to see the ability to scale lot sizes because presently the EMA Cross places two orders at the same time one buy and one sell. This seems like hedging at 100% and that doesn't seem like having much confidence in the signal cross to me. Again if the lots were scaled so the opposing direction were half the size of the signal direction then that would minimize losses right there making less drawdown to recover in the first place.

I put a close all hotkey option in this so that with two keyboard keys the user could manually close all orders. That could be for damage control AND for discretionary profit taking. It just keeps the discretionary trader able to take immediate action which could be good for some highly intuitive types of people or whatever.

The specified trading hours is not new but I've not seen the ability to go in and out more than once so I made three sessions for engagement during hot trading hours.

I also made a spot for a MACD and a Stochastic to join this EA if desired. I've seen the three work well together in the CAT50fx system which I've seen work in other places too. It's optional if this can be created like I envision it.

The reversal option already exists in the present version of the EMA CROSS. I just made a place for that here even though I don't fully know how it's done.

In fact I don't know how alot of this is done or how much is doable. All I know is what I'd like to see done. I assume that coder's guru doesn't have the same limitations that I do when it comes to what is 'doable'. I can tell you I know I don't have the understanding to do all this right now. But I don't think that should stop me from envisioning or communicating what I can envision. Envisioning is something I CAN do. So this is just doing what I can. I know it's not much. I hope I'll get some help with this (from real programmers) doing what I'm not ready to tackle myself. I'll keep learning but all assistance is appreciated. This is just trying to communicate what I'm envisioning at this point so someone else who codes can see what I'm thinking. As I learn more I'll communicate what I learn how to communicate. I'm expressing more than I did when I first came here. I didn't even know how to start to make an EA. Now I have all these ambitious ideas (ambitious for me anyway).

If I had to prioritize all this I would say the most important is the function to scale lots because I see that as reducing losses which the current version really needs from my testing of it.

Second importance would be the trading session hours that lets the user put the EA on standby during certain times of the day.

the rest of this is of interest because of what might make a flexible EA for strategy testing purposes but those two functions I can see giving immediate reward to the present EA.

I suppose the rest is just to give me something to learn on as I try to learn to make EA's and do coding. It may add something to the outcome and it may just help me learn to program.

the rest of what's there is probably not necessary to do any explaining...it's pretty common

 

//---- input parameters

extern bool UseTakeProfit=true; //Gives user the option to use a take profit goal

extern double TakeProfit=20.0; //Specifies the take profit goal

extern bool UseStopLoss=true; //Gives user the option to use a stop loss

extern double StopLoss=20.0; //Specifies Stop Loss

extern bool UseTrailingStop=true; //Gives user the option to use a trailing stop

extern double TrailingStop=20.0; //Specifies Trailing Stop

extern int ShortMA=2; //Specifies short moving average used with moving average cross

extern int LongMA=5; //Specifies long moving average used with moving average cross

extern bool UseImmediateTrade=false; //Gives user the option to enter trade immediately before next ma cross

extern bool UseReversal=false; //Gives user the option to use a reversal strategy based on a specified reversal condition

extern bool UseConfirmedEntry=true; //Gives user the option to use a number of subsequent bar periods to confirm entry signal

extern int Confirmationbars=1; //Specifies the number of bars to confirm entry signal

extern double Lots=1.0; //Specifies how many lots to trade in orders

extern bool UseMoneyManagement=true; //Gives user the option to use money management risk/order scaling

extern int PercentRisk=10; //Specifies the percentage of risk to assume in money management

extern bool UseCustomTimeframe=false; //Gives user the option to execute orders from signals on custom bar interval periods

extern int CustomTimeframe=10; //Specifies the custom bar interval period

extern bool UseLossRecovery=true; //Gives user the option to use basket loss recovery strategy- this uses additional positiions to pool into a basket which closes when the pool equity returns to break even

extern int Basketsize=5; //Specifies the number of additional positions allowed to open to assist in loss recovery of a losing position

extern bool UseLotScaling=true; //Gives user the option to use lot scaling when opening positions

extern double GoalDirectionScaling=100.0; //Specifies the percentage of the lot value to use for orders in the direction of the signal

extern double HedgedDirectionScaling=50.0; //Specifies the percentage of the lot value to use for orders hedging against the direction fo the signal

extern bool UseManualCloseAll=true; //Gives user the option to use a double hotkey manual close all trades function

extern string CloseAllHotkey1="z"; //Specifies the first hotkey for the close all trades function

extern string CloseAllHotkey2="y"; //Specifies the second hotkey for the close all trades function (used for confirmation)

extern bool UseActiveHour=false; //Gives user the option to engage the market during specified hours and standy idle during specified hours

extern double TradehourStart1=0.0; //Specifies the first session daily hour to start trading

extern double Standby1=14.0; //Specifies the first session daily hour to go on standby

extern double TradehourStart2=16.0; //Specifies the second session daily hour to start trading

extern double Standby2=22.0; //Specifies the second session daily hour to go to standby

extern double TradehourStart3; //Specifies the third session daily hour to start trading

extern double Standby3; //Specifies the third session daily hour to go to standby

extern bool UseStopScaling=false; //Gives use the option to scale stop losses

extern double StopScale1=30.0; //Specifies the pips to reduce the stop loss at the first scaling level

extern double StopScale2=60.0; //Specifies the pips to reduce the stop loss at the second scaling level

extern double TrailScale1=30.0; //Specifies the pips to reduce the trailing stop loss at the first scaling level

extern double TrailScale2=60.0; //Specifies the pips to reduce the trailing stop loss at the second scaling level

extern bool UseMACDfilter=false; //Gives use the option to engage a MACD parameter as an additional condition for order entry

extern int MacdShort=3; //Specifies the short period moving average for the macd filter

extern int MacdLong=11; //Specivies the long period moving average for the macd filter

extern int MacdSignal=2; //Specivies the signal averaging line period for the macd filter

extern bool UseStochFilter=false; //Gives user the option to engage a stochasitc parameter as an additional condition for order entry

extern double Kline=0.0; //Specifies the %K of the stochastic filter

extern double PercentD; //Specifies the %D of the stochastic filter

extern int StochBars; //Specifies the number of bars to use for the stochastic filter

extern bool UseReverse=false; //Gives user the option to use a reversal method based on a reversal condition

extern int ReverseCondition=1; //Specifies if the reversal condition is met or not (1=reverse; 0=do not reverse)

hey wow cool i just learned how to post alot of code and wrap php brackets around it

 

Thanks

Thanks for posting an explanation of the commands! I've been really getting into the system as of late , and I've been wanting to translate some of my trading system ideas into EA's for backtesting. I have been having some difficulty finding tutorials or explanations on the Metatrader language. "Reverse engineering" EA's from the top coders ain't easy. Your trading idea is also interesting. Let's hope one of the forum's best coders can help out on this one!

 
Aaragorn:

//---- input parameters

extern bool UseTakeProfit=true; //Gives user the option to use a take profit goal

extern double TakeProfit=20.0; //Specifies the take profit goal

extern bool UseStopLoss=true; //Gives user the option to use a stop loss

extern double StopLoss=20.0; //Specifies Stop Loss

extern bool UseTrailingStop=true; //Gives user the option to use a trailing stop

extern double TrailingStop=20.0; //Specifies Trailing Stop

extern int ShortMA=2; //Specifies short moving average used with moving average cross

extern int LongMA=5; //Specifies long moving average used with moving average cross

extern bool UseImmediateTrade=false; //Gives user the option to enter trade immediately before next ma cross

extern bool UseReversal=false; //Gives user the option to use a reversal strategy based on a specified reversal condition

extern bool UseConfirmedEntry=true; //Gives user the option to use a number of subsequent bar periods to confirm entry signal

extern int Confirmationbars=1; //Specifies the number of bars to confirm entry signal

extern double Lots=1.0; //Specifies how many lots to trade in orders

extern bool UseMoneyManagement=true; //Gives user the option to use money management risk/order scaling

extern int PercentRisk=10; //Specifies the percentage of risk to assume in money management

extern bool UseCustomTimeframe=false; //Gives user the option to execute orders from signals on custom bar interval periods

extern int CustomTimeframe=10; //Specifies the custom bar interval period

extern bool UseLossRecovery=true; //Gives user the option to use basket loss recovery strategy- this uses additional positiions to pool into a basket which closes when the pool equity returns to break even

extern int Basketsize=5; //Specifies the number of additional positions allowed to open to assist in loss recovery of a losing position

extern bool UseLotScaling=true; //Gives user the option to use lot scaling when opening positions

extern double GoalDirectionScaling=100.0; //Specifies the percentage of the lot value to use for orders in the direction of the signal

extern double HedgedDirectionScaling=50.0; //Specifies the percentage of the lot value to use for orders hedging against the direction fo the signal

extern bool UseManualCloseAll=true; //Gives user the option to use a double hotkey manual close all trades function

extern string CloseAllHotkey1="z"; //Specifies the first hotkey for the close all trades function

extern string CloseAllHotkey2="y"; //Specifies the second hotkey for the close all trades function (used for confirmation)

extern bool UseActiveHour=false; //Gives user the option to engage the market during specified hours and standy idle during specified hours

extern double TradehourStart1=0.0; //Specifies the first session daily hour to start trading

extern double Standby1=14.0; //Specifies the first session daily hour to go on standby

extern double TradehourStart2=16.0; //Specifies the second session daily hour to start trading

extern double Standby2=22.0; //Specifies the second session daily hour to go to standby

extern double TradehourStart3; //Specifies the third session daily hour to start trading

extern double Standby3; //Specifies the third session daily hour to go to standby

extern bool UseStopScaling=false; //Gives use the option to scale stop losses

extern double StopScale1=30.0; //Specifies the pips to reduce the stop loss at the first scaling level

extern double StopScale2=60.0; //Specifies the pips to reduce the stop loss at the second scaling level

extern double TrailScale1=30.0; //Specifies the pips to reduce the trailing stop loss at the first scaling level

extern double TrailScale2=60.0; //Specifies the pips to reduce the trailing stop loss at the second scaling level

extern bool UseMACDfilter=false; //Gives use the option to engage a MACD parameter as an additional condition for order entry

extern int MacdShort=3; //Specifies the short period moving average for the macd filter

extern int MacdLong=11; //Specivies the long period moving average for the macd filter

extern int MacdSignal=2; //Specivies the signal averaging line period for the macd filter

extern bool UseStochFilter=false; //Gives user the option to engage a stochasitc parameter as an additional condition for order entry

extern double Kline=0.0; //Specifies the %K of the stochastic filter

extern double PercentD; //Specifies the %D of the stochastic filter

extern int StochBars; //Specifies the number of bars to use for the stochastic filter

extern bool UseReverse=false; //Gives user the option to use a reversal method based on a reversal condition

extern int ReverseCondition=1; //Specifies if the reversal condition is met or not (1=reverse; 0=do not reverse)
hey wow cool i just learned how to post alot of code and wrap php brackets around it

this is along the lines of what I had in mind to scale the stops...

https://www.mql5.com/en/forum

 
rainey75:
Thanks for posting an explanation of the commands! I've been really getting into the system as of late , and I've been wanting to translate some of my trading system ideas into EA's for backtesting. I have been having some difficulty finding tutorials or explanations on the Metatrader language. "Reverse engineering" EA's from the top coders ain't easy. Your trading idea is also interesting. Let's hope one of the forum's best coders can help out on this one!

Thanks rainey,

First let me put you on to the tutorial I've been looking at.

http://www.lightpatch.com/forex/mt_yahoo/MQL4_Tutorial/

I know the reverse engineering blues. I'm passionate about this system right now. I don't have a better grasp on anything better. I am open minded this is just my best going concern at the moment. But my latest tests on this aren't bad, see attached. I have managed to alter the code to allow me to use a TP of 8. That's about as far as I have learned how to modify it using the tutorials. I change one EMA from 2 to 1 and it made a huge difference in the profit generated. I don't recommend the confirm order option in this it only decreases the successful outcome.

If you look at this chart you see it makes alot then gives half of it back at the end. I believe that if the lots on the hedged positions were scalable that this amount which is given back would be reduced. I'd like codersguru to make this modification or someone else competent. I'd just like to see that much done with it and see where it leads. All the rest of the stuff is extra credit so to speak.

I'll keep learning as best I can but I really wish someone competent to program would take an interest in this soon. I think that would be best. All I can do is all I can do.

 

Strategy Tester

Aaragorn,

I looked at your back testing results and I noticed that your modeling quality is only 29% or so. I don't mean this in a mean way, but those results mean nothing. Even with a modeling quality of 90% the results really don't correlate with live trading too well. Back testing with a modeling quality of 90% just starts to give a trader an idea of what potentional the EA Might have. If you really want to see what an EA can do you have to forward test it at present. It is possible that in the future a better backtester will come out, but for now it's not all that reliable. Just try forward testing an EA and you will see what I mean.

Aplari's data that can be download to get modeling quality to 90% is indicative data and therefore doesn't accurately represent the true market movement but only is an estimate that may or may not give signals in live trading. That is why it is hard to trust the backtester.

That is all I have for now. I'm not trying to burst your bubble or anything, I just want you to be aware.

Thanks

Huhenyo

 

A few updates

Hi Aaragorn,

I've made a few updates, let me know if they are what you want.

In the inputs for the EA you can now tell the EA when to start trading and when to stop trading. There is also the option to specify the % of the lots you want the hedged position to be.

Huhenyo

Files:
 
huhenyo:
Hi Aaragorn,

I've made a few updates, let me know if they are what you want.

In the inputs for the EA you can now tell the EA when to start trading and when to stop trading. There is also the option to specify the % of the lots you want the hedged position to be.

Huhenyo

I understand what you're saying about the modeling quality. I know it's indicative not conclusive but indicative is ok to tell me what to examine in the system.

Would you repost this upgrade in .mq4 format, I'm not sure how to handle it in the format you've used.

Thanks for your kind upgrade, I'll get back as soon as I have some idea of what is working, but i need the right file format to do that.

 

Sorry

Aaragorn,

There you go. Sorry, I accidently gave you the wrong file extention. This should work for you now.

Files:
 

Another I'm working on

Here is the EA I've been working on for awhile now. Try it out and see what you think. I'll post two versions. The 1.1 version only trades with the signal. The 1.2 verions trades with the signal during less volitile times and opposite the signal during the more volitile times with a traling stop only if the movement after the signal is such to warrent it. Have fun. Let me know what you think

Huhenyo

 

thank you Huhenyo,

what TF and Which pairs ,

thx

Reason: