Object in Subwindow

 
Hello, I want to create an ObjectCreate- function to show an Object in one of my subwindows. An iCustom function opens me the indicator in a subwindow when I run the EA. Unfortunately when I set the 5.paramter in the ObjectCreate function as 1(index=1; for the first subwindow), the Object won't appear in the subwindow and prints me that the Problem is the index-parameter returns -1, because there is no subwindow available. It also gives me that message if I put the ObjextFind with the name of the indicator into the index-paramter of ObjectCreate. How can I set another index than 0 to the Object-Create Function? Thx for your help!
 

I imagine your problem is that you have put ObjectCreate in the init function. You are not allowed to do that. It has to be in the start function and therefore you need a bool flag to run it once. Post some code if you would like more specific advice.

   if( createObjects ){ // get the indicator text in the correct window; can't do this from init()
      int winIndex = WindowFind(INDICATORNAME);
      if( winIndex == -1 )
          winIndex = 1;
          
      ObjectCreate("AUDJPY_label",  OBJ_LABEL, winIndex, 0, 0);
      ObjectSet("AUDJPY_label", OBJPROP_CORNER, 0);
      ObjectSet("AUDJPY_label", OBJPROP_XDISTANCE, 10);
      ObjectSet("AUDJPY_label", OBJPROP_YDISTANCE, 30);
      
      createObjects = false;  // this function need only be run once
   }
 
dabbler:

I imagine your problem is that you have put ObjectCreate in the init function. You are not allowed to do that. It has to be in the start function and therefore you need a bool flag to run it once. Post some code if you would like more specific advice.



Thanks for your help so far!

I put the ObjectCreate in the start function. I also tried your code but it still gives me that message in the Journal with it: "unknown subwindow number 1 for ObjectCreate function".

Maybe if u see the code u will find the mistake easily, I'm new to the language.

Thx for your help already

int start()
{

double Sto1,Sto2;

Sto1 = iCustom(NULL,15,"Stochastic",5,3,3,0,0);
Sto2 = iCustom(NULL,15,"Stochastic",5,3,3,1,0);

int winIndex = WindowFind("Sto(5,3,3)");
if( winIndex == -1 )
    winIndex = 1;

int isCrossed = Crossed (Sto1,Sto2);
static int j=0;
string name;
string name2;
name2 = j-3;
name = j;

if (isCrossed ==1)
 {
 ObjectCreate(name,OBJ_ARROW,winIndex,Time[0],Sto1);
 ObjectSet(name,OBJPROP_ARROWCODE,242);
 Print(j);
 j++;
 if (j>=3)
   {
   ObjectDelete(name2);
   }
 return(0);
 }
if (isCrossed ==2)
 {
 ObjectCreate(name,OBJ_ARROW,winIndex,Time[0],Sto1);
 ObjectSet(name,OBJPROP_COLOR,Lime);
 Print(j);
 j++;
  if (j>=3)
   {
   ObjectDelete(name2);
   }
 return(0);
 }
return(0);
}


 
tak88js:

Thanks for your help so far!

I put the ObjectCreate in the start function. I also tried your code but it still gives me that message in the Journal with it: "unknown subwindow number 1 for ObjectCreate function".

Maybe if u see the code u will find the mistake easily, I'm new to the language.

Thx for your help already


Well is there a subwindow 1? If there isn't then it won't work! Without more of the code it is not possible to debug it. Try putting Print functions throughout the code to find what it is doing. For example what is the value of winIndex before it is tested for equality with -1?
 
dabbler:
Well is there a subwindow 1? If there isn't then it won't work! Without more of the code it is not possible to debug it. Try putting Print functions throughout the code to find what it is doing. For example what is the value of winIndex before it is tested for equality with -1?


How can I tell the Program to run a subwindow with the index? So far I couldn't find a code for that.

I thought by using the iCustom function, its opening an subwindow starting with the index 1.

This is the whole code, there is nothing else relevant to solve my Problem I thought.

//+------------------------------------------------------------------+
//|                                                          EA1.mq4 |
//|                                                        MQL4-Team |
//|                                        http://www.meta-trader.de |
//+------------------------------------------------------------------+
#property copyright "MQL4-Team"
#property link      "http://www.meta-trader.de"

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
int Crossed (double line1 , double line2)
{
    static int last_direction = 0;
    static int current_dirction = 0;

    if(line1>line2)current_dirction = 1; //up 
    if(line1<line2)current_dirction = 2; //down
  
    if(current_dirction != last_direction) //changed 
    {
       last_direction = current_dirction;
       return (last_direction); 
    }
    else 
    {
       return (0);
    }
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
{

double shortEma, longEma,Sto1,Sto2;

Sto1 = iCustom(NULL,15,"Stochastic",5,3,3,0,0);
Sto2 = iCustom(NULL,15,"Stochastic",5,3,3,1,0);

int winIndex = WindowFind("Sto(5,3,3)");
if( winIndex == -1 )
    winIndex = 1;

int isCrossed = Crossed (Sto1,Sto2);
static int j=0;
string name;
string name2;
name2 = j-10;
name = j;

if (isCrossed ==1)
 {
 ObjectCreate(name,OBJ_ARROW,winIndex,Time[0],Sto1);
 ObjectSet(name,OBJPROP_ARROWCODE,242);
 Print(j);
 j++;
 if (j>=10)
   {
   ObjectDelete(name2);
   }
 return(0);
 }
if (isCrossed ==2)
 {
 ObjectCreate(name,OBJ_ARROW,winIndex,Time[0],Sto1);
 ObjectSet(name,OBJPROP_COLOR,Lime);
 Print(j);
 j++;
  if (j>=10)
   {
   ObjectDelete(name2);
   }
 return(0);
 }
return(0);
}
 

//+------------------------------------------------------------------+
 
tak88js:


How can I tell the Program to run a subwindow with the index? So far I couldn't find a code for that.

I thought by using the iCustom function, its opening an subwindow starting with the index 1.

This is the whole code, there is nothing else relevant to solve my Problem I thought.

Well, in the first place

int winIndex = WindowFind("Sto(5,3,3)");

isn't going to work since the indicator short name is actually "Stoch(5,3,3)" and you have missed off two characters!

Secondly, if you are testing in the strategy tester, since the markets are currently closed, you need to save the Stoch in a template with the same name as the EA or it won't appear during the test and there will be no subwindow to find..

 
dabbler:

Well, in the first place

isn't going to work since the indicator short name is actually "Stoch(5,3,3)" and you have missed off two characters!

Secondly, if you are testing in the strategy tester, since the markets are currently closed, you need to save the Stoch in a template with the same name as the EA or it won't appear during the test and there will be no subwindow to find..


But when I start the Tester in the visual Mode it will show me the sub window which has the name: "Sto(5,3,3)".
 
dabbler:

Well, in the first place

isn't going to work since the indicator short name is actually "Stoch(5,3,3)" and you have missed off two characters!

Secondly, if you are testing in the strategy tester, since the markets are currently closed, you need to save the Stoch in a template with the same name as the EA or it won't appear during the test and there will be no subwindow to find..


Anyways you were right! Thank you so much for your help!
Reason: