Hi all,

i am investigating my version of Ehlers algo from his "Rocketscience"-Book. When i start the optimization, is comes to a certain solution, but when i start a second opt-run it comes to a totally different solution and so on..... it seems totally random without changing anything. What the hack is wromg here?

function trade_Ehlers()
{
TimeFrame = 2;

vars Price = series(price());
vars Smoothed = series(LowPass(Price,optimize(100,50,200,25)));
vars Trendline = series(HTTrendline(Price));
vars Trendmode = series(HTTrendMode(Price));
var Phase = DominantPhase(Price,10);
vars LeadSine = series(sin(Phase+PI/4));
vars Sine = series(sin(Phase));
MaxLong = MaxShort = 1;

if(abs(Smoothed[0] - Trendline[0]) > (optimize(0.5,0.25,1.5,0.25) * ATR(30))) {
Trendmode[0] = 1;}

Stop = optimize(30,3,21,3) * ATR(30);

if(Trendmode == 1) {
if(crossOver(Smoothed, Trendline)){
enterLong();}
else if(crossUnder(Smoothed, Trendline)){
enterShort();}}
else if(Trendmode[0] == 1 && Trendmode[1] == 0) {
if(Smoothed > Trendline){
enterLong();}
else if(Smoothed < Trendline){
enterShort();}}
else if(Trendmode == 0){
if(crossOver(LeadSine, Sine)){
enterLong();}
else if(crossUnder(LeadSine, Sine)){
enterShort();}}
}