EA Multi Stage criteria for opening trade

 

Hi 

Im having some difficulty with coding a multi stage acceptance to open a trade and I hoping someone can help

there are 4 indicators that need to return true values to open a code. Im trying to expand this to add a 5th and 6th indicator combination to reduce drawdown.

what im tring to achive is: 

If the first set of criteria are true, loop for X bars until either the second group of criteria is true or abandon the trade

Here is what i have so far

Part of OnBar()

   int entrySignal = GetEntrySignal();

   if (posType == OP_FLAT && entrySignal != OP_FLAT)
     {
      OpenPosition(entrySignal);
      UpdatePosition();
     }

then the entrySignal

   bool canOpenLongPt1  = ind0long && ind1long && ind2long && ind3long;
   bool canOpenShortPt1 = ind0short && ind1short && ind2short && ind3short;

   if (canOpenLongPt1==true)
   {
      bool canOpenLongPt2 = ind4long && ind5long;
      return(canOpenLongPt2);
   }
   
   if (canOpenShortPt1==true)
   {
      bool canOpenShortPt2 = ind4short && ind5short;
      return(canOpenShortPt2);
   }
//   bool canOpenLong  = ind0long && ind1long && ind2long && ind3long && ind4long;
   bool canOpenLong  = canOpenLongPt2;
//   bool canOpenShort = ind0short && ind1short && ind2short && ind3short && ind4short;
   bool canOpenShort  = canOpenShortPt2;
   
   return canOpenLong  && !canOpenShort ? OP_BUY
        : canOpenShort && !canOpenLong  ? OP_SELL
        : OP_FLAT;

im sure there needs to be a counter add but does it go to the onbar()

Thanks in advance

 
mbaker71:

Hi 

Im having some difficulty with coding a multi stage acceptance to open a trade and I hoping someone can help

there are 4 indicators that need to return true values to open a code. Im trying to expand this to add a 5th and 6th indicator combination to reduce drawdown.

what im tring to achive is: 

If the first set of criteria are true, loop for X bars until either the second group of criteria is true or abandon the trade

Here is what i have so far

Part of OnBar()

then the entrySignal

im sure there needs to be a counter add but does it go to the onbar()

Thanks in advance

Its not entirely clear what you want, but I guess it is something like this pseudo code:

//   If the first set of criteria are true, loop for X bars until either the second group of criteria is true or abandon the trade
   if(first_set_of_criteria == true)
        {
	X = 0;
         do
           {
            if(second_group_of_criteria == true)
              {
               //whatever you want to do
                return(true);
              }
	    X = (bar_has_changed)? X++ : X;
           } // end - do
         while(X < bar_limit);
        return(false); //abandon trade
        } //end if

 
R4tna C #:

Its not entirely clear what you want, but I guess it is something like this pseudo code:

Hi R4tna C,

Thanks for that. I think that is what im after. I will have a go with that. Much appreciated

 
mbaker71 #:

Hi R4tna C,

Thanks for that. I think that is what im after. I will have a go with that. Much appreciated

Sure - this will of course evaluate the 2nd set of criteria with every loop iteration

You could add some logic to delay it by a fixed number or seconds, or do it once per bar using PeriodSeconds()

good luck
Reason: