using EMPTY_VALUE to open trade in supertrend indicator

 

Hi everyone, I've a strategy using a supertrend indicator. This supertrend indicator have 2 buffer which is supertrend up and supertrend down.

// setting up supertrend indicator
double supertrendUp(int shift=0)
  {
   return iCustom(Symbol(),PERIOD_CURRENT,"SuperTrend",12,3,0,shift);
  }
//
double supertrendDown(int shift=0)
  {
   return iCustom(Symbol(),PERIOD_CURRENT,"SuperTrend",12,3,1,shift);
  }

//open condition
if(supertrendUP(shift+1)==EMPTY_VALUE && supertrendUP(shift)!=EMPTY_VALUE) >>>> OPEN BUY POSITION
if(supertrendDOWN(shift+1)==EMPTY_VALUE && supertrendDOWN(shift)!=EMPTY_VALUE >>>> OPEN SELL POSITION

When using code above EA doesn't open any position, I don't know if it's because of the code or because I'm using EMPTY_VALUE for open a trade position. Is using EMPTY_VALUE on this condition is incorrect?

 

As iCustom, we don't know what it is expected to return,  showing more code for advice would help.. 

 
Luandre Ezra:

Hi everyone, I've a strategy using a supertrend indicator. This supertrend indicator have 2 buffer which is supertrend up and supertrend down.

When using code above EA doesn't open any position, I don't know if it's because of the code or because I'm using EMPTY_VALUE for open a trade position. Is using EMPTY_VALUE on this condition is incorrect?

Do not use EMPTY_VALUE in Expert. Because Buffers returning from the indicator returns a value. EMPTY_VALUE value is 2147483647.

It can work if you edit the code like this.


 Print(EMPTY_VALUE);
   if(supertrendUP(shift+1)==2147483647 && supertrendUP(shift)!=2147483647) // >>>> OPEN BUY POSITION
if(supertrendDOWN(shift+1)==2147483647 && supertrendDOWN(shift)!=2147483647 //>>>> OPEN SELL POSITION
 
Carlos Albert Barbero Marcos #:

As iCustom, we don't know what it is expected to return,  showing more code for advice would help.. 

It's a condition to open a position. The indicator consist only 2 buffer which is up and down. I want to open a condition when the indicator changing from supertrend down to supertrend up.

 
Mehmet Bastem #:

Do not use EMPTY_VALUE in Expert. Because Buffers returning from the indicator returns a value. EMPTY_VALUE value is 2147483647.

It can work if you edit the code like this.


I change it to  2147483647 and still the problem still occur. btw between using number and EMPTY_VALUE resulting the same.

 
  1. You absolutely should use the proper symbol (EMPTY_VALUE) rather than that 2147483647 which is wrong for MT5.
  2. Capture and print your variables or use the debugger, and find out why.
 
I tried to debugging it. I don't think the problem is on the EMPTY_VALUE. When I use alert it shows that the condition to open order is match but the EA just not opening any order and yet when I looked into the EA journal there's no error or something. Still trying to find the problem though...
 
  1. Don't double post! You already had this thread open.
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2017)

  2. The indicator you posted in the other thread does not use EMPTY_VALUE. The previous value equals the opposite side. Just use:
    bool isUpTrend = supertrendUP(shift) < supertrendUP(shift+1);

 
The indicator might return only EMPTY_VALUE or no EMPTY_VALUE at all, I would check the indicator not the EA.
Reason: