Simple Moving Average EA help needed

 

I am programming an EA where an order to buy is given when the 14SMA > 50SMA.

Now the problem is that it does it every time that that occurs, which could even be right before it crosses back.

I only want it to happen when it crosses, or better, just after it crossed and when the market is bullish.

How can I do that?


Thank you in advance!

 

ILP


See the code below for an example of checking the market for main trend




//============================ INFO FROM OTHER PERIODS/INSTRUMENTS =======================================
double EMA_D5_1 = iMA(NULL,PERIOD_D1,5,0,MODE_EMA,PRICE_CLOSE,1);
double EMA_D5_0 = iMA(NULL,PERIOD_D1,5,0,MODE_EMA,PRICE_CLOSE,0);
double EMA_D20_0 = iMA(NULL,PERIOD_D1,20,0,MODE_EMA,PRICE_CLOSE,0);
double EMA_D130_0 = iMA(NULL,PERIOD_MN1,6,0,MODE_EMA,PRICE_CLOSE,0);

//============================ INFO FROM OTHER PERIODS/INSTRUMENTS =======================================


// ==========================================================================
// Lot Sizing START

BuyLots=Lots;
SellLots=Lots;

if ((EMA_D5_0 > EMA_D20_0) && (EMA_D5_0 > EMA_D5_1) && (EMA_D20_0 > EMA_D130_0))
{
BuyLots=RiskBoost*Lots;
SellLots=Lots;
}

if ((EMA_D5_0 < EMA_D20_0) && (EMA_D5_0 < EMA_D5_1) && (EMA_D20_0 < EMA_D130_0))
{
BuyLots=Lots;
SellLots=RiskBoost*Lots;
}



// Lot Sizing END
// ==========================================================================



But.....


Using SMA only as entry/exit signals is unwise as they lag too much - EMA may be better but even there you can be missing divergence that is occurring on RSI, MACD, Stochastics or CCI.

The divergence of an oscillator from price action can be a strong pointer to a false MA signal.


Your best bet with a simple strategy is to wait for D1, H4, H1 &...M5? EMA crosses to line up?


FWIW

-BB-

 

Using SMA only as entry/exit signals is unwise as they lag too much - EMA may be better but even there you can be missing divergence that is occurring on RSI, MACD, Stochastics or CCI.

The divergence of an oscillator from price action can be a strong pointer to a false MA signal.


Your best bet with a simple strategy is to wait for D1, H4, H1 &...M5? EMA crosses to line up?


FWIW

-BB-

Thank you Barrowboy for your reply.


Okay, so basically what you are saying is:


If "current MA > previous MA" then we have an uptrend.

I think I can give a buy signal when: current MA > previous MA and 14SMA=50SMA


I want to use it as an entry signal. I have found that for an exit you lose to many pips. Also when the market is trading sideways it is not profitable. However on the H4 chart with short stops (20pips) it is very profitable. You will lose trades, but the winning trades are big because you ride all the good waves.


As an exit strategy I want the MACD, ( 7MACD =21MACD ) where 7MACD is on a downtrend.

Not the standard one, but I found a good set of numbers that make for a good exit. For my Moving averages and MACD numbers I tend to use Fibonacci numbers, they work the best.

Now, since I don't have the patience/discipline to manually trade this, I want to use an EA. I always close the trade on a reasonable win, but find that I could have made a lot more if I would have left it.


For a short entry we do exactly the reverse.

If there are more ideas out there, I like to hear them please !

If I finish this and it works, I will make it available for everyone to download for free.


Thanks!


Tip: When trading on EA with windows, make sure you have "automatic updates" off. My computer rebooted after an auto update and I missed the USD/JPY run for a lot of pips.
 

ILP


> My computer rebooted after an auto update and I missed the USD/JPY run for a lot of pips


Good point, thats a killer - think we've all suffered that one :(


See the ideas on this thread to get back up & working in the least time


'Command line options for terminal.exe'


Good luck

-BB-

 

Okay, you are not going to believe this, but I have a profitable EA. I made 34% over the last week on demo trading and that could have been more but I increased the lot size as I went.

However, there are 2 things I want to improve. Biggest profit was $640,- Biggest loss $240,-

1. to avoid false entries I want to add an RSI indicator, which is no problem.

2. Is a bit more complicated as it involves a variable stoploss.


I want to enter an order and put a stoploss just passed (2 pips) the 23.6% fibonacci retracement level.


For instance, today I missed a rally of 100 pips after a stoploss of 20pips was hit by just 1 pip. So if I had stoploss set at 25, I would have gained 100 pips instead I had a loss, but if I had put the stoploss at the first level of resistance there would not have been a problem.


Can someone please help me with this?


Thank you in advance.


Ilovepippin

 

ILP



Very well done for the progress :)

Always keep a <last good copy> of an EA thats working - i.e. dont work on the current 'master' version.

This means you can always step back if it goes pear-shaped & <stops working> when you <only changed one little thing> :(


Back to the questions - you cant go chasing the results of one trade or one day & say <thats what I need to change> - because this will be <wrong> some other day.

You have to take a view based on months of results...



As for the Fib - thats not difficult, its only a percentage of a high from a low - the very hard part is deciding which hgh & which low to measure from...

In general I use trailing stops instaed of precalculated levels

The trailing stop steps are initially calculated from back-testing results (single broker data) and then refined in live trading (over several months).

Having re-read your post though, I have just realised that many of the trailing stops increments do look very like a fib series minus 2/3 pips?!!!


PS

RSI can be great for some pairs/time-frames but dont forget CCI?



PPS

I see you are demo trading - is the demo account off MetaTrader or from a broker

Broker data is more representative but still not as... rough & tumble as a live trading feed!


FWIW

-BB-

 
BarrowBoy:

ILP



Very well done for the progress :)

Always keep a <last good copy> of an EA thats working - i.e. dont work on the current 'master' version.

This means you can always step back if it goes pear-shaped & <stops working> when you <only changed one little thing> :(


Back to the questions - you cant go chasing the results of one trade or one day & say <thats what I need to change> - because this will be <wrong> some other day.

You have to take a view based on months of results...



As for the Fib - thats not difficult, its only a percentage of a high from a low - the very hard part is deciding which hgh & which low to measure from...

In general I use trailing stops instaed of precalculated levels

The trailing stop steps are initially calculated from back-testing results (single broker data) and then refined in live trading (over several months).

Having re-read your post though, I have just realised that many of the trailing stops increments do look very like a fib series minus 2/3 pips?!!!


PS

RSI can be great for some pairs/time-frames but dont forget CCI?



PPS

I see you are demo trading - is the demo account off MetaTrader or from a broker

Broker data is more representative but still not as... rough & tumble as a live trading feed!


FWIW

-BB-


Hi Barrowboy, thank you for the reply.

I have found a way to incorporate the Fibo levels. I am also adding some money management.

For instance, I don't want more than 12% drawdown. The max lot size has to be set by that figure. Maybe I can even make it a variable.

The stoploss should be just above or below the 23.6% fibo depending on the direction of trade.


I stepped away from the RSI and am using the SAR now. The SAR has to be in the same direction as the MA to open a trade.

I will check the CCI.


Thank for the memo on the master copy, that indeed already happened and I had to reprogram, undelete didn't even work :-(.


I am using a broker to demotrade and I am using straighthold, from liteforex. I found that they at busy times have a lot of "busy" errors and that's what I need to keep it as close to live trading as possible. If the EA is profitable in those environments I have a better chance in live environments.


Thanks,

Ilovepippin.

Reason: