Universal MA Cross EA - page 64

 

Hello could some one please add a breakeven code to this Ea.

Price moves x pips move stop to break even Plus x pips. I've tried but keep getting multiple errors.https://www.mql5.com/en/forum

Thanks in advance for any help.

 

is this what you are looking for?

Mjack59_59@yahoo.com:
Hello could some one please add a breakeven code to this Ea.

Price moves x pips move stop to break even Plus x pips. I've tried but keep getting multiple errors.https://www.mql5.com/en/forum

Thanks in advance for any help.

not exactly what you want, i'm guessing, since i'm not clear what you mean... but start with this and let me know...

sn

 

it's didn,t work for 5 digit broker boss ?

firedave:
I try to make an EA for any Moving Average Cross strategy, try to make it universal. So please let me know should you have any suggestion to add to this EA.

Common Setting :

-----------------

StopLoss (default 100)

Set your Stop Loss. Use 0 (zero) if you don't like to use Stop Loss ( not recommended ).

TakeProfit (default 200)

Set your Take Profit. Use 0 (zero) if you like to use open target.

Trailing Stop Setting :

----------------------

ver.6 TrailingStopType (default 1)

Set trailing stop type. 1:will start trailing if profit in pips is greater / same with TrailingStop. 2:will start trailing as soon as trade in profit. (will add other type of trailing stop if suggested, latest suggestion is SafeZone trailing stop post #99 https://www.mql5.com/en/forum/general )

TrailingStop (default 40)

Set the Trailing Stop. Use 0 (zero) if you don't use trailing stop feature.

Moving Average Setting :

------------------------

FastMAPeriod (default 10)

Fast Moving Average Period.

FastMAType (default EMA / 1)

Fast Moving Average Type 0:SMA 1:EMA 2:SMMA 3:LWMA

FastMAPrice (default Close / 0)

Fast Moving Average Applied Price 0:Close 1:Open 2:High 3:Low 4:Median 5:Typical 6:Weighted

ver.7.2 FastMAshift (default 0)

Fast Moving Average Shift

SlowMAPeriod (default 80)

Slow Moving Average Period.

SlowMAType (default EMA / 1)

Slow Moving Average Type 0:SMA 1:EMA 2:SMMA 3:LWMA

SlowMAPrice (default Close / 0)

Slow Moving Average Applied Price 0:Close 1:Open 2:High 3:Low 4:Median 5:Typical 6:Weighted

ver.7.2 FastMAshift (default 0)

Slow Moving Average Shift

Minimum Cross Distance :

------------------------

ver.2 MinCrossDistance (default 0)

Set the pip distance between FastMA and SlowMA to be consider as a valid cross. Use 0 (zero) to disable this filter.

ver.7 MaxLookUp (default 1)

Set number of bar after the cross to keep checking on the entry condition in regards with the minimum distance between FastMA and SlowMA. Need MinCrosDistance > 0 to enable this feature. Use 0 (zero) to disable this feature.

Exit Setting :

-------------

StopAndReverse (default true)

If set to TRUE, will exit any trade and reverse position when signal change.

PureSAR (default false)

If set to TRUE, will use no Stop Loss - Take Profit - and Trailing Stop. This is always in play setting.

ver.7.2 ExitOnCross (default false)

If set to TRUE, will exit any trade if there is an opposite cross without consider any additional filter. So exit purely base on moving average cross.

Third MA Setting :

------------------

ver.5 UseThirdMA (default false)

If set to TRUE (and UseCounterTrend = FALSE), will only trade according to ThirdMA direction, above for BUY and below for SELL.

ver.5 UseCounterTrend (default false)

If set to TRUE will keep trade even if counter ThirdMA direction, but with different StopLoss and TakeProfit. Need UseThirdMA = TRUE to enable this feature.

ver.7 OnlyCounterTrend (default false)

If set to TRUE will set the EA only to trade counter trend trade, mean BUY if cross below ThirdMA and SELL if cross above ThirdMA. Need UseCounterTrend = TRUE to enable this feature.

ver.5 ThirdMAPeriod (defaul 100)

Third Moving Average Period.

ver.5 ThirdMAType (default EMA / 1)

Third Moving Average Type 0:SMA 1:EMA 2:SMMA 3:LWMA

ver.5 ThirdMAPrice (default Close / 0)

Third Moving Average Applied Price 0:Close 1:Open 2:High 3:Low 4:Median 5:Typical 6:Weighted

ver.7.2 ThridMAshift (default 0)

Third Moving Average Shift

ver.5 CTStopLoss (default 0)

Set your Stop Loss for CounterTrend trade. Use 0 (zero) if you don't like to use Stop Loss ( not recommended ).

ver.5 CTTakeProfit (default 0)

Set your Take Profit for CounterTrend trade. Use 0 (zero) if you like to use open target.

Pivot Filter Setting :

-------------------

ver.8.0 Use.Pivot.Filter (default false)

Set to true if you like to filter the trade, only BUY if the cross of Slow and Fast MA occur between S1 and S2 and only SELL if the cross of Slow and Fast MA occur between R1 and R2.

Order Setting :

--------------

ReverseCondition (default false)

Set TRUE to reverse the entry condition.

ver.3 ConfirmedOnEntry (default true)

If set to TRUE, will enter/exit trade on the next bar after the cross confirmed. If set to FALSE, will enter/exit trade as soon as there is a cross.

ver.4 OneEntryPerBar (default true)

If set to TRUE, will only trade once on one bar. If set to FALSE, will trade more than once on one bar if the entry condition is still valid, although still one trade at a time.

NumberOfTries (default 5)

Number of try if the order rejected by the system.

Slippage (default 5)

Slippage setting.

MagicNumber (default 1234)

Use to generate Magic Number. Change this number ONLY if you like to run the EA on same pair and same time frame but with different setting.

Multiple Open Trade Setting :

-----------------------------

ver.5 MaxOpenTrade (default 2)

Number of maximum open trade at one time. This setting is use when StopAndReverse / PureSAR = FALSE so the EA won't close the open order when there is an opposite signal, but rather it will open a new trade. Set the number of open trade allowed. If StopAndReverse / PureSAR = TRUE this setting will always = 1, mean one trade at a time.

ver.6 MinPriceDistance (default 5)

If multiple open trade enable (by set MaxOpenOrder>1 and OneEntryPerBar=FALSE) this number will determine the minimum distance between each trade on same direction.

Time Filter Setting :

-------------------

UseHourTrade (default false)

If set to TRUE, the EA only active on certain time.

StartHour (default 10)

Time when the EA start active (use with UseHourTrade = TRUE).

EndHour (default 11)

Time when the EA stop active (use with UseHourTrade = TRUE).

Lot and Money Management Setting :

------------------------------------

Lots (default 1)

Number of lot per trade.

MM (default false)

If set to TRUE, will use build in money management.

AccountIsMicro (default false)

If using Micro Account set this to TRUE.

Risk (default 10)

Use with MM = TRUE to set the risk per trade.

Cross Alert Setting :

--------------------

ver.5 EnableAlert (default true)

Will sound an alert when there is a moving average cross, cross UP or cross DOWN.

ver.5 SoundFilename (default "alert.wav")

The filename for the alert.

BackTest Setting :

------------------

PrintControl (default true)

Print some comment on backtesting.

Show_Settings (default true)

Show setting on the chart.

Let me know if you still got problem with the setting. Thank you to codersguru and pengie for several partial code. Hope this help

Journal :

-----------

version.6 :

- fixed ConfirmedOnEntry bug.

- add immediate trailing stop.

- add MinPriceDistance for multiple open trade.

version.7 :

- add MaxLookUp feature to keep checking on the entry after certain bar from the cross regarding the MinCrossDistance.

- add OnlyCounterTrend feature if using ThirdMA filter.

version.7.1 :

- fixed MinCrossDistance bug.

version.7.2 :

- fixed MinCrossDistance bug for ConfirmedOnEntry = FALSE.

- add MA shift parameter.

- add ExitOnCross feature.

version.7.3 :

- fixed on screen display COMMENT.

version.8.0 :

- added Pivot Filter.

version.8.1 :

- revised some code because Build 206 bugs.
 

invalid stoploss / takeprofit

Hi Serpentsnoir,

I have test this version on 5 digits, with

StopLoss=30

TakeProfit=40

and the error generated as shown here;

2011.04.27 22:47:44 universalMACrossEA[5 Dig]-V4 EURGBP,M5: sn Debug on sell: Bid,Slippage,aStopLoss,aTakeProfit 0.88554/30.00000/0.88466/0.89066

2011.04.27 22:47:44 universalMACrossEA[5 Dig]-V4 EURGBP,M5: sn Debug on sell: ticket,err,count -1/130/5

Could you teach me how to solve the 130 is invalid stops (TP, SL)?

Cheers

Takingpip

 

invalid stop loss, error 130

StopLoss and TakeProfit levels cannot be too close to the market. The minimal distance of stop levels in points can be obtained using the MarketInfo() function with MODE_STOPLEVEL parameter. In the case of erroneous or unnormalized stop levels, the error 130 (ERR_INVALID_STOPS) will be generated.

The above is from the Metaquotes documentation.

Error 130 occurs when you set the stop loss too close to the Bid/Ask price. It generally means that you should increase the stop loss to correct the problem or possibly, you should not be modifying the order to set a stop loss but instead should be closing it as it is very near to the current stop loss on the order.

Note that MarketInfo with Mode_Stoplevel may return a zero, at least it does with my broker FXCM so you may have to set manually.

 

invalid stop loss, error 130

Thanks for the explaination Tzuman.

For example even i have set the

SL = 200

TP = 150

it is still generating error 130 and my broker only need a minimum of 10pip for stoploss or take profit.

I am new to MT programming, still learning. Could you explain where to insert the MODE_STOPLEVEL monitoring parameter into the code ?

Cheers

 
serpentsnoir:
not exactly what you want, i'm guessing, since i'm not clear what you mean... but start with this and let me know... sn

Hello, I've downloaded your version with BE feature but when compiling I got this error: "'UseBreakEven' - comparison expression expected

Please, can you check it up?

Thank you

 
FxCba:
Hello, I've downloaded your version with BE feature but when compiling I got this error: "'UseBreakEven' - comparison expression expected

Please, can you check it up?

Thank you

I prefer to use integers for flags rather than boolean. It does not affect the operation of the EA. Just change the type to boolean if you want the error to go away.

sn

 
serpentsnoir:
I prefer to use integers for flags rather than boolean. It does not affect the operation of the EA. Just change the type to boolean if you want the error to go away. sn

Do you mean to add a line like this?: " bool UseBreakEven = false;"

(sorry for the question but I don't understand Metatrader code)

I made it that way and got no error.

 

Daily profit limit add on to EA.

Hi everybody,

I would like to know if someone could add the feature bellow, to the UMA cross EA attached.

extern string DayProfitHelp = "--Enter either DayProfitLimit in USD or DayProfitLimitPct in percent of last day balance. Set both 0 to disable.";

extern double DayProfitLimit = 0.0;

extern double DayProfitLimitPct = 0.0;

extern int DayProfitResetHour = 0;

extern bool DayProfitGlobal = FALSE;

I found this function very handy on another EA, and basically what it does is to stop the EA opening orders if a "x%" has been hit before the Stop time.

Also the trailing features is not working properly on the UMAcrossEA. If someone could help I appreciate.

Thks very much

===============================

extern int SL_pips = 290;

extern int MA_distance_pips = 20;

extern int MA_period = 16;

extern int TP_pips = 20;

extern int TradeVolume = 1;

extern string HourTradeHelp = "--Set if EA will work only on a specific period of the day. ForceClose will close all open orders.";

extern bool UseHourTrade = FALSE;

extern int StartHourTrade = 21;

extern int EndHourTrade = 3;

extern bool ForceClose = FALSE;

extern string MinToKeepTradeHelp = "--Will close the order once its life time is grater than MinutesToKeepTrade. Set 0 to disable.";

extern int MinutesToKeepTrade = 0;

extern string DayProfitHelp = "--Enter either DayProfitLimit in USD or DayProfitLimitPct in percent of last day balance. Set both 0 to disable.";

extern double DayProfitLimit = 0.0;

extern double DayProfitLimitPct = 0.0;

extern int DayProfitResetHour = 0;

extern bool DayProfitGlobal = FALSE;

extern int ModifyIntervalMin = 1;

extern int MagicNumber = 2265;

extern bool Hedge=false;

int g_ord_total_172;

int g_ticket_176;

int g_ticket_180;

int g_minute_184;

bool g_bool_188;

bool gi_192;

bool gi_196;

bool gi_200;

bool gi_204;

double g_price_208;

double gd_216;

double g_price_224;

double gd_232;

double gd_240;

double gd_248;

double gd_256;

double gd_264;

double gd_272;

double gd_280;

double g_ima_288;

double gd_296;

double gd_304;

double gd_312;

double g_lots_320;

void init() {

gd_240 = MarketInfo(Symbol(), MODE_STOPLEVEL);

gd_256 = gd_240 * Point;

gd_248 = (gd_240 + 1.0) * Point;

gd_216 = SL_pips * Point;

gd_232 = MA_distance_pips * Point;

gd_280 = TP_pips * Point;

g_minute_184 = Minute();

}

int start() {

double ld_8;

double ld_16;

if (AccountBalance() - gd_304 != 0.0) ld_8 = 100.0 * (gd_304 / (AccountBalance() - gd_304));

else ld_8 = 0;

if (AccountBalance() - gd_304 != 0.0) ld_16 = 100.0 * ((AccountBalance() - gd_304 + gd_312) / (AccountBalance() - gd_304)) - 100.0;

else ld_16 = 0;

gd_296 = Ask - Bid;

gd_304 = GetDailyProfit();

g_lots_320 = Lots();

if (DayProfitLimitPct > 0.0) gd_312 = (AccountBalance() - gd_304) * (DayProfitLimitPct / 100.0);

else gd_312 = DayProfitLimit;

g_bool_188 = !(UseHourTrade && !IsTradeTime(StartHourTrade, EndHourTrade));

if (g_bool_188 && GlobalVariableGet("gISEAStop") == 1.0) g_bool_188 = FALSE;

string ls_0 = "Symbol: " + Symbol()

+ "\nSpread: " + DoubleToStr(MarketInfo(Symbol(), MODE_SPREAD) / 10.0, 1) + " pips"

+ "\nDaily P/L: $" + DoubleToStr(gd_304, 2) + " (" + DoubleToStr(ld_8, 2) + "%)"

+ "\nLimit P/L: $" + DoubleToStr(gd_312, 2) + " (" + DoubleToStr(ld_16, 2) + "%)"

+ "\nCurrent P/L: $" + DoubleToStr(AccountProfit(), 2)

+ "\nStop Level: " + DoubleToStr(gd_240 / 10.0, 1) + " pips"

+ "\nVolume: " + DoubleToStr(g_lots_320, 1) + " ($" + DoubleToStr(g_lots_320 * MarketInfo(Symbol(), MODE_LOTSIZE), 2) + ")";

if (gd_312 > 0.0 && gd_304 + AccountProfit() >= gd_312) {

Comment(ls_0

+ "\n\nReached daily profit... See you tomorrow... Good night :-)");

RemoveAllOrders(1);

return (0);

}

g_ord_total_172 = OrdersTotal();

gi_192 = FALSE;

gi_196 = FALSE;

gi_200 = FALSE;

gi_204 = FALSE;

for (int l_ord_total_24 = g_ord_total_172; l_ord_total_24 >= 0; l_ord_total_24--) {

if (OrderSelect(l_ord_total_24, SELECT_BY_POS) == TRUE && OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {

if (OrderType() == OP_BUY) {

gi_200 = TRUE;

Close_B(OrderTicket(), OrderLots());

}

if (OrderType() == OP_SELL) {

gi_204 = TRUE;

Close_S(OrderTicket(), OrderLots());

}

if (OrderType() == OP_BUYLIMIT) {

gd_264 = NormalizeDouble(OrderOpenPrice(), Digits);

g_ticket_176 = OrderTicket();

gi_192 = TRUE;

}

if (OrderType() == OP_SELLLIMIT) {

gd_272 = NormalizeDouble(OrderOpenPrice(), Digits);

g_ticket_180 = OrderTicket();

gi_196 = TRUE;

}

}

}

if (g_bool_188) {

g_ima_288 = iMA(NULL, 0, MA_period, 0, MODE_LWMA, PRICE_TYPICAL, 0);

Modify_order();

Open_order();

} else {

Files:
Reason: