MAMA initial SL

 

Hi

MT5 comes with an EA named MAMA, this EA has only trailing SL and no initial SL, and if a fixed SL of say 100pips is manually or using another script added, then the EA start changing it even though it's supposed to start trailing once it goes into profit region.

How may I change the code to add two regions:

1. in this region the trade has not entered the trailing SL of the EA, so SL= initial fixed SL

2. in this region the trade has entered the trailing SL of the EA, so SL= trailing SL


The EA currently only works once it enters region 2, and as I said in region if an SL is set then the EA changes it.

Files:
 
Armin :


1. in this region the trade has not entered the trailing SL of the EA, so SL= initial fixed SL

2. in this region the trade has entered the trailing SL of the EA, so SL= trailing SL


Can not understand anything.

I recommend that you start writing Expert Advisors on your own or use the CodeBase search.

 
Vladimir Karputov #:

Can not understand anything.

I recommend that you start writing Expert Advisors on your own or use the CodeBase search.

Well the problem is that moving average trailing stop that's supplied with MT5 tries to set a trailing stop if there's already a SL (i.e Sl==0), but I don't want it to start trailing before entering the profit.

   double base  =(pos_sl==0) ? position.PriceOpen() : pos_sl;

I changed it successfully so now I have

   double base  =(pos_sl==initialstopLossPrice) ? position.PriceOpen() : pos_sl;

it's working fortunately but I need to find a long term solution for this as every time I change the method of initial SL, I have to change the way initial SL is bein calculated and passed to TrailingMA.mqh.

Also I have different EAs using the same trailing library so it makes some problems as I should go to the original TrailingMA.mqh every time.

one way is to use extern variables and different cases defined by the EA, but I'm worried it might affect the EA running speed and RAM requirements.

on a side note/question, how much does using "for" loops affect the speed?

 
Armin #:

Well the problem is that moving average trailing stop that's supplied with MT5 tries to set a trailing stop if there's already a SL (i.e Sl==0), but I don't want it to start trailing before entering the profit.

I changed it successfully so now I have

it's working fortunately but I need to find a long term solution for this as every time I change the method of initial SL, I have to change the way initial SL is bein calculated and passed to TrailingMA.mqh.

Also I have different EAs using the same trailing library so it makes some problems as I should go to the original TrailingMA.mqh every time.

one way is to use extern variables and different cases defined by the EA, but I'm worried it might affect the EA running speed and RAM requirements.

on a side note/question, how much does using "for" loops affect the speed?

Forum on trading, automated trading systems and testing trading strategies

MAMA initial SL

Vladimir Karputov, 2021.09.23 17:49

***

I recommend that you start writing Expert Advisors on your own or use the CodeBase search.