EA meets order opening conditions, but doesn't trade

 

Hey everyone,

I recently got an answer to a problem I was having while trying to make an EA based on ZigZag breakouts. Looks like I got the ZigZag code working (don't worry, I realize that ZigZag repaints...), but now the EA isn't trading. I looked in the log, and the values are being displayed correctly, so I figure it must be a problem with my order conditions. Here are my variables:

double  LastBarHigh     = iHigh(NULL, 0, 1);  
double  LastBarLow      = iLow(NULL, 0, 1);  

      double SwingValue[3]={0,0,0};
      int Found = 0;
      int k = 0;
      while(Found < 3){
         if(iCustom(NULL, 0, "ZigZag", Depth, 5, 3, 0, k) != 0){
            SwingValue[Found] = iCustom(NULL , 0, "ZigZag", Depth, 5, 3, 0, k);
            Found++;
         }
         k++;
      }

...and my trading signals:

bool BuySignal, SellSignal;

if (LastBarHigh < SwingValue[2] && Ask > SwingValue[2]) SIGNAL_BUY = true;
if (LastBarLow > SwingValue[2] && Bid < SwingValue[2]) SIGNAL_SELL = true;

...and the code to place actual trades is the generic one from the expert advisor builder tool.

The full logic of the EA is only slightly more complicated, and can be found in the attachment. Does anyone know why this might not be trading? Again, I'm getting the correct ZigZag values, but no trades are placed and no errors are shown.

Thanks again for all your help, forum-goers... someday, I hope to be able to answer others' questions and not just post my own!

-Alex

 

i would really like to help but i dont understand what you are trying to accomplish, (when you want to buy and when to sell) can u explain the thing with words & not with code (the best would be whit a chart attach)

BTW (according to your code) it seems to me that the array in not necessary at all

 

one more thing, i think that your conditions can't ever be together "LastBarHigh < SwingValue[0] && Ask > SwingValue[0]"

& the same thing "LastBarLow > SwingValue[0] && Bid < SwingValue[0]" can't be

 
Yeah man, I really wanna help too. But those Builder Codes make my eyes water. I recommend you built your own code from scratch. Adopt a clean cut programming bracket { } style. And lastly, my little trick, use allot of user define functions. I made a .mqh file and dumped all my simple functions in there. Trust me it's easier than it sounds and makes life easier for un-natural programmers like us 8)
 

Wow, I guess I've never even thought about changing the builder code... I'll work on that today :) Also, I'll always try to post labeled charts with every question I have; I really appreciate everyone's help and I want to make it as easy as possible for you all, so I can actually make some progress as a coder.

For now, what I'm trying to do is get the last two ZigZag values, use those to form a breakout range, and trade the breakout of that range (but only when intraday volatility is high).

That's basically what I want to do. Anyway, like I said I'll get to work on building a from-scratch code for this. And I'll learn to make functions and stuff :)

qjol, thanks for the input on the order conditions and array usage... what would you recommend doing instead?

-Alex

 
double SwingValue[2]={0,0};
while(Found <= 2){
         if(iCustom(NULL, 0, "ZigZag", Depth, 5, 3, 0, k) != 0){
            SwingValue[Found] = i
Found could be 0, 1, or 2 therefor the size of SwingValue must be 3. Your exceeding the array bounds.
 

Thanks for responding WHRoeder, and my original post reflects your suggestion - I changed the array settings. Unfortunately, still no trades are being opened. Here's another screenshot, during visual mode of the strategy tester, exactly when a short trade should have been taken. The log corresponds with the chart: the ZigZag breakout range is being accurately displayed with the code -- so it must be a problem with the order conditions, right?

I apologize for being obscure in my original post; I hope this is as clear as possible. All I'm looking for is a set of buy and sell conditions that would do the job I'm trying to do. Thanks again for your contributions.


 

because LastBarLow not > SwingValue[2]

 
qjol, the bottom yellow dotted line in the image is the value of SwingValue[2]. The current bar is the one cutting through that line... and it looks to me like the previous bar's low is above it. Am I missing something?
 
the code in the fille you have attached is different, inside the code you use SwingValue[0] in your breakoutcalculations
 
Hey zzuegg, that was the first version... I've corrected that mistake, and updated the EA since then. The text of the first post is what I'm using, not the old attached file. Thanks for pointing that out!
Reason: