Auftrag beendet
Spezifikation
Simple EA needs to be coded in mql4: only 1 position open at the same time, works on all charts & time frames, no position sizing or anything. Based on 1 indicator: if both lengths are up, go long, vice versa for short, if 1 of the 2 lengths is no longer the same sign, close, or use ATR-based trailing stop: whichever hits first, so you have 3 external variables: Length1, Length2 and ATRmultiple.
Different lengths are used so you get 2 criteria for entry:
If there is no open position: at the close of the bar:
Entry long: if IndicatorLength1[i] > IndicatorLength1[i+1] && IndicatorLength2[i] > IndicatorLength2[i+1] // so both are going up
Exit Long: if both of them are no longer going up: so if IndicatorLength1[i] < IndicatorLength1[i+1] || IndicatorLength2[i] < IndicatorLength2[i+1]
Entry short: if IndicatorLength1[i] < IndicatorLength1[i+1] && IndicatorLength2[i] < IndicatorLength2[i+1] // so both are going down
Exit short: if both of them are no longer going down: so if IndicatorLength1[i] > IndicatorLength1[i+1] || IndicatorLength2[i] > IndicatorLength2[i+1]
*********************
If there is an open position: at the close of the bar: reverse it only if both have the same sign that is opposite to the previous direction, else you close the open position:
so if you are long, if 1 of the 2 is no longer going up: close it, if at the close of the bar, both of them are going down, close long and open short position.
If you are short, if 1 of the 2 is no longer going down: cover the short position, if at the close of the bar, both of them are going up, cover the short and open a long position.
*********************
to protect profitable positions I want a trailing stop that is a multiple of the ATR: Average True Range, basic indicator. Standard setting could be a 1.5*ATR(10). So this 1.5 should be changeable. The trailing stop needs to be updated every tick. Off course a trailing stop starts out as a classic stop loss: at the opening of the position, the stop is there, so if the position only goes against me, the EA will exit the trade at the entry level +/- 1.5*ATR(10).
*********************
I prefer not to share the indicator, so please work with code that would enable me to replace wit iCustom: you can use a simple moving average as example code:
for(int i=0; i<limit; i++)
{
ExtMapBuffer0[i]=iMA(0,0,Length1,0,0,0,i);
}