3 Bar TrailingStop

 
With 3 Bar TrailingStop, I need ideas to code this:

1. Buy Trailing Stop - Set 1 pip below lowest bar in previous 3 bars excluding Inner Bars. Inner Bar is when one bar's high and low are within previous bar high and low. If this happens, exclude this bar and go back 1 more bar.

Wackena
 
Yes I need this too.

I do not know the solution but will look into it some more,
and hopefully we can find out how solve it.
 
Off the top of my head...not sure of the inside thingy

bool IsInsidePrev(int index)
{
//You might want to adjust this def.
if (Low[index - 1] < Low[index] && High[index - 1] > High[index])
{
return (true);
}
return (false);
}

//Start at index bars back
double GetStop(int index)
{
int counted = 0;
double lowest = 0;
while(counted < 3)
{
if (!IsInsidePrev(index))
{
counted++;
if (lowest == 0 || Low[index] < lowest) lowest = Low[index];
}
index++;
}
return (lowest - Point);
}
 

Thanks Craig for the code. I also put this code together and it seems to work well.

Wackena

      int c, n, p;
      c=-1; n=0; p=0;
      while(n<6)
      {
         if(High[c]<High[c-1] && Low[c]>Low[c-1]) n-=1;
         if(High[c]<High[-c] )
         n+=1;
         c--;
         p+=1;
         if(n==3) break;
      }
      ShortTS=High[Highest(NULL,0,MODE_HIGH,p,1)];
      
      c=-1; p=0;
      while(n<6)
      {
         if(High[c]<High[c-1] && Low[c]>Low[c-1]) n-=1;
         if(Low[c]>Low[-c])
         n+=1;
         c--;
         p+=1;
         if(n==3) break;
      }
      LongTS=Low[Lowest(NULL,0,MODE_LOW,p,1)];



 

Works well on daily charts. This is miners Stopplosssystem. Stopp adjusted only if there is a new high or low, otherwise unchanged.


T. Bopp

 
Thank you very much for such a usefull info. it's exactlly what I was searching for. better actually because I didn't think of the inside bar thing.
I managed to put the code to work, but I can't figure out where do you change the number of bars it looks for the highest and lowest. in this code it's set on 3, right? how do I change it? I tried some things but the more I try it out the less sense it seems to make. it seems to have to do with the
while(n<6)
and/or

        if(n==3) 

can you help me out here, the problem is that I don't really understand the code itself. I knew nothing about programing until a few days ago when I started exploring mql4.
 
I've refined the code as follows:

int c, n, p;
c=0; p=0;
for(n=0;n<=6;n++)
{
if(High[c+1]<High[c+2] && Low[c+1]>Low[c+2]) {n--;} 
c++;
p++;
if(n==3) break;
}
double ShortTS=NormalizeDouble(High[iHighest(Symbol(),0,MODE_HIGH,p,1)],Digits);
      
double LongTS=NormalizeDouble(Low[iLowest(Symbol(),0,MODE_LOW,p,1)],Digits);
I use 6 cycles (n<=6) to allow for multiple descarded inner bars (n--). When it finds 3 good bars (n==3), it breaks out of scan cycle. Then the High{iHighest] and Low[iLowest] of the 3 good bars is found scanning back (p) number of bars (which includes both good and inner bars).

Wackena