Download MetaTrader 5

3 Bar stop EA need help

To add comments, please log in or register
toti1981
319
toti1981  

Hi guys i am trying to code EA, which is suppose to help me only with the SL.

1 Trade and initial SL triggered manually

2. EA triggered:

EA should do following:

For long trade:

1. EA is triggered after 5 bars. Counting starts at Entry Bar.

2. Before ThreeBarStop is started we check If the 5th bar is having higher high than the Entry Bar High. If yes, then start the Three Bar Stop.

3. After a bar makes new higher high (it is marked as our 1st bar), we check back by looking ONLY at the lows at the prev bars. We set the SL 5 pips below 3th bar that has lower low than 2th and the 1st (counting backwards)

4. Reverse for Short


I wrote some code in non mql language, but i cannot start because cannot figure out the how to do the bar count of the first 5 bars...

Can someone help me?

Thanks A Lot

void ThreeBarTrail(int ticket,int tmfrm,int bars_n, int indent){

if (OrderType()==OP_BUY){
   if(5 Bars completed after Entry (+Entry Bar))
   {
      currentHighestHigh = currentBar[High]
      while (currentHighestHigh >= currentBar[High]
      {
         getNextBar();
      }
      counter = 1;
      while(counter <= 3)
      {
         while(PrevBar[Low] => currentBar[Low])
         {
            getPrevBar();
         }
         currentBar=PrevBar;
         counter++;
      }
      setSL(currentBar, iIndent);
   }
} 
Ubzen
5394
Ubzen  
iBarShift() along with the OrderOpenTime() is probably what you're looking for.
toti1981:I wrote some code in non mql language, but i cannot start because cannot figure out the how to do the bar count of the first 5 bars...
Tjipke de Vries
6370
Tjipke de Vries  
toti1981:

Hi guys i am trying to code EA, which is suppose to help me only with the SL.

1 Trade and initial SL triggered manually

2. EA triggered:

EA should do following:

For long trade:

1. EA is triggered after 5 bars. Counting starts at Entry Bar.

2. Before EA is started we check If the 5th bar is having higher high than the Entry Bar High. If yes, then start the Three Bar Stop.

3. After a bar makes new higher high (it is marked as our 1st bar), we check back by looking ONLY at the lows at the prev bars. We set the SL 5 pips below 3th bar that has lower low than 2th and the 1st (counting backwards)

4. Reverse for Short


I wrote some code in non mql language, but i cannot start because cannot figure out the how to do the bar count of the first 5 bars...

Can someone help me?

Thanks A Lot

if(5 Bars completed after Entry (+Entry Bar))

make use of OrderOpenTime() and look if it is < Time[...]

whroeder1
15576
whroeder1  
... OrderSelectLoop ...
datetime WhenOrderOpen = OrderOpenTime();
int      iBarOrderOpen = iBarShift(NULL,0, WhenOrderOpen);
To add comments, please log in or register