[Coding Issues] WindowFind() alternative for testing

 

Hello all,

I'm trying to make an EA which is based on the Freedom Indicator, which on his turn is based on CCI's on multiple timeframes; So in order to go long for instance M15,M30 and H1 should all show an uptrend. This is the first time I used a custom indicator instead of one from the library, and I'm struggling with it a bit. Since you can't use WindowFind() on the MT4 Strategy Tester, I was looking for an alternative, but since I'm not very experienced with this I'm asking you're help, thanks in advance! 

 for (ii=0; ii<4; ii++)
      {  
         string txt = "??";
         double gp;
         switch (ii)
         {
            case 0: txt = tf2txt(Period_1);  gp = 1 + shift;         break;
            case 1: txt = tf2txt(Period_2);  gp = 1 + Gap + shift;   break;
            case 2: txt = tf2txt(Period_3);  gp = 1 + Gap*2 + shift; break;
            case 3: txt = tf2txt(Period_4);  gp = 1 + Gap*3 + shift; break;
         }
         string name = "FF_"+win+"_"+ii+"_"+txt;
         ObjectCreate(name, OBJ_TEXT, WindowFind(shortname), iTime(NULL,0,0)+dif*3, gp);
         ObjectSetText(name, txt,8,"Arial", Black);
      }

 

The complete code is also added. I've pretty much copypasted the indicator in my template, so that's why you'll probably notice two different styles of writing.

Files:
freedomv104.mq4  15 kb
 
Feel like an idiot for not finding that, thanks for it!
 

I really can't figure it out. And i did search a lot. Mainly because of the fact MT4 should have several limitations, i.e.:

- Can't use WindowFind() function while testing

- SetIndexBuffer don't appear to work within an EA?

 

The solution you pointed to:

if(IsTesting() && !IsVisualMode() ) {}

// note: no indy object create while backtesting w/o VisualMode, if visual testing make sure indy on visual tester template

else
{
// [ ObjectCreate CODE.... ]

}

 

 Is not working to for me unfortunately, since I still need to use the WindowFind() Function.

Again after a lot of hours I've only seperated them, since it's more overviewable this way and hope you've got any other thoughts.

 Any help would be greatly appreciated 

 Edit: I could also rewrite it, and make it like this, if that's more easier? Thoughts?

 

double A,B,C;
////////////////////////
int init()
    {
// Load indicator values for first loop
     A=iCCI(TF1Parameters);
     B=iCCI(TF2Parameters);
     C=iCCI(TF3Parameters);

    return(0);
    }

////////////////////////
double CCITimeFrame1()
    {
     if(IsNewBarTF1()) 
        A=iCCI(TF1Parameters);
    
    return(A);
    }

double CCITimeFrame2()
    {
     if(IsNewBarTF2())
        B=iCCI(TF2Parameters);
     return(B);
    }

double CCITimeFrame3()
    {
     if(IsNewBarTF3())
        C=iCCI(TF3Parameters);
     return(C);
    }

 A disadvantage would be that I can't see my indicator but I could always ad it manually in case I want to see it, plus it's going to run on a server anyhow. Thoughts?

 Freedom102 --> EA

 Freedom --> Indicator  

Files:
freedom.mq4  7 kb
 
Maarten91:

I really can't figure it out. And i did search a lot. Mainly because of the fact MT4 should have several limitations, i.e.:

- Can't use WindowFind() function while testing

- SetIndexBuffer don't appear to work within an EA?

 

The solution you pointed to:

 

 Is not working to for me unfortunately, since I still need to use the WindowFind() Function.

You don't if you are calling your Indicator from your EA using iCustom . . . all you care about is the buffer values not what Objects are on screen . . .  so if the WindowFind() returns -1 don't draw thee Objects.
 

But i am calling it per iCustom now(right?), but doesn't appear to work (EA + Ind. were attached to previous post), or I'm misunderstanding you! 

Is the alternative I stated ok? Since I only know the basics at this moment. Well probably a bit more, but you can point it that way. And because of that I'm opted (for myself) to go with the flow with the least resistance/that's the most easy one for me. But offcourse I want to learn it, so if you've got some extra additions or what I misinterpreted just tell! Thanks for the replies!  

 
Maarten91:

But i am calling it per iCustom now(right?), but doesn't appear to work (EA + Ind. were attached to previous post), or I'm misunderstanding you! 

Is the alternative I stated ok? Since I only know the basics at this moment. Well probably a bit more, but you can point it that way. And because of that I'm opted (for myself) to go with the flow with the least resistance/that's the most easy one for me. But offcourse I want to learn it, so if you've got some extra additions or what I misinterpreted just tell! Thanks for the replies!  

"doesn't appear to work" means what exactly ?  did you mean to get all 8 of the buffers for the currently forming bar ?  isn't it going to re-paint ?
 
What I mean with that, is that I keep getting the 'unknown subwindow number -1 for ObjectCreate function'-error every time a new bar is generated.
 
Maarten91:
What I mean with that, is that I keep getting the 'unknown subwindow number -1 for ObjectCreate function'-error every time a new bar is generated.

RaptorUK:
You don't if you are calling your Indicator from your EA using iCustom . . . all you care about is the buffer values not what Objects are on screen . . .  so if the WindowFind() returns -1 don't draw thee Objects.

Check the value from WindowFind()  if it is -1  don't attempt to create the Objects then you won't get the error from ObjectCreate()
 
  1. Since you can't use WindowFind() on the MT4 Strategy Tester
    Since when?
  2. SetIndexBuffer don't appear to work within an EA?
    Of course not, there are NO indicator buffers in an EA
  3. But i am calling it per iCustom now
    Yes you are. You are getting the indicators buffers. BUT the indicator is not attached to the chart - it has no window. Do what RaptorUK suggests. Don't draw things in the indicator's window when it doesn't exist. There's no need to draw anything anyway - EA's have no eyes.
Reason: