imjeffd:
ok so the first ObjectCreate puts it in window 0 (main) and the second ObjectCreate puts it in the 2 i dont know why???
You need to reference the window / sub window index.
General Example:
int window_index=WindowFind("my indicator short name"); if(window_index<0){window_index=0;}
That will tell you the window index that you need to reference.
Index 0 is the main chart window.
If you have an indicator sub window, then it would be index 1, etc etc etc.
yah did i not index them to the same window 0 becouse the first m5 shows up in the main window and m15 in window 2 even though the code is the some
here is all the code
//+------------------------------------------------------------------+ //| rsibot.mq4 | //| | //| | //+------------------------------------------------------------------+ // int lastsec = TimeSeconds(TimeCurrent()); //#property copyright //#property link //#property description #property strict #property indicator_separate_window #property indicator_minimum 0 #property indicator_maximum 100 #property indicator_buffers 1 #property indicator_color1 DodgerBlue #property indicator_level1 30.0 #property indicator_level2 70.0 #property indicator_levelcolor clrSilver #property indicator_levelstyle STYLE_DOT //--- input parameters input int InpRSIPeriod=14; // RSI Period //--- buffers double ExtRSIBuffer[]; double ExtPosBuffer[]; double ExtNegBuffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit(void) { string short_name; //--- 2 additional buffers are used for counting. IndicatorBuffers(3); SetIndexBuffer(1,ExtPosBuffer); SetIndexBuffer(2,ExtNegBuffer); //--- indicator line SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(0,ExtRSIBuffer); //--- name for DataWindow and indicator subwindow label short_name="RSI("+string(InpRSIPeriod)+")"; IndicatorShortName(short_name); SetIndexLabel(0,short_name); //--- check for input if(InpRSIPeriod<2) { Print("Incorrect value for input variable InpRSIPeriod = ",InpRSIPeriod); return(INIT_FAILED); } //--- SetIndexDrawBegin(0,InpRSIPeriod); //--- initialization done return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Relative Strength Index | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { int i,pos; double diff; //--- if(Bars<=InpRSIPeriod || InpRSIPeriod<2) return(0); //--- counting from 0 to rates_total ArraySetAsSeries(ExtRSIBuffer,false); ArraySetAsSeries(ExtPosBuffer,false); ArraySetAsSeries(ExtNegBuffer,false); ArraySetAsSeries(close,false); //--- preliminary calculations pos=prev_calculated-1; if(pos<=InpRSIPeriod) { //--- first RSIPeriod values of the indicator are not calculated ExtRSIBuffer[0]=0.0; ExtPosBuffer[0]=0.0; ExtNegBuffer[0]=0.0; double sump=0.0; double sumn=0.0; for(i=1; i<=InpRSIPeriod; i++) { ExtRSIBuffer[i]=0.0; ExtPosBuffer[i]=0.0; ExtNegBuffer[i]=0.0; diff=close[i]-close[i-1]; if(diff>0) sump+=diff; else sumn-=diff; } //--- calculate first visible value ExtPosBuffer[InpRSIPeriod]=sump/InpRSIPeriod; ExtNegBuffer[InpRSIPeriod]=sumn/InpRSIPeriod; if(ExtNegBuffer[InpRSIPeriod]!=0.0) ExtRSIBuffer[InpRSIPeriod]=100.0-(100.0/(1.0+ExtPosBuffer[InpRSIPeriod]/ExtNegBuffer[InpRSIPeriod])); else { if(ExtPosBuffer[InpRSIPeriod]!=0.0) ExtRSIBuffer[InpRSIPeriod]=100.0; else ExtRSIBuffer[InpRSIPeriod]=50.0; } //--- prepare the position value for main calculation pos=InpRSIPeriod+1; } //--- the main loop of calculations for(i=pos; i<rates_total && !IsStopped(); i++) { diff=close[i]-close[i-1]; ExtPosBuffer[i]=(ExtPosBuffer[i-1]*(InpRSIPeriod-1)+(diff>0.0?diff:0.0))/InpRSIPeriod; ExtNegBuffer[i]=(ExtNegBuffer[i-1]*(InpRSIPeriod-1)+(diff<0.0?-diff:0.0))/InpRSIPeriod; if(ExtNegBuffer[i]!=0.0) ExtRSIBuffer[i]=100.0-100.0/(1+ExtPosBuffer[i]/ExtNegBuffer[i]); else { if(ExtPosBuffer[i]!=0.0) ExtRSIBuffer[i]=100.0; else ExtRSIBuffer[i]=50.0; } } ObjectCreate("m5",OBJ_LABEL,0,0,0); ObjectSetText("m5","M5 "+iRSI(NULL,5,14,PRICE_CLOSE,0)); ObjectSet("m5",OBJPROP_CORNER,0); ObjectSet("m5",OBJPROP_XDISTANCE,20); ObjectSet("m5",OBJPROP_YDISTANCE,50); ObjectCreate("m15",OBJ_LABEL,0,0,0); ObjectSetText("m15","M15 "+iRSI(NULL,15,14,PRICE_CLOSE,0)); ObjectSet("m15",OBJPROP_CORNER,0); ObjectSet("m15",OBJPROP_XDISTANCE,10); ObjectSet("m15",OBJPROP_YDISTANCE,20); if(lastsec>45){ lastsec = TimeSeconds(TimeCurrent()); } if(((ExtRSIBuffer[(rates_total-1)] >= 70) || (ExtRSIBuffer[(rates_total-1)] <= 30)) && (lastsec <= (TimeSeconds(TimeCurrent())-10))){ PlaySound("alert2.wav"); Print(ExtRSIBuffer[(rates_total-1)]+" alert"+iRSI(NULL,0,14,PRICE_CLOSE,0) ); lastsec = TimeSeconds(TimeCurrent()); } if(ExtRSIBuffer[(rates_total-1)] >= 71){ Print("sell"); } if(ExtRSIBuffer[(rates_total-1)] <= 29){ Print("buy"); } //--- return(rates_total); } //+------------------------------------------------------------------+
fixed it i guess that object name was used somewhere
ObjectCreate("m_5",OBJ_LABEL,2,0,0); ObjectSetText("m_5","M5 "+iRSI(NULL,5,14,PRICE_CLOSE,0),9,NULL,White); ObjectSet("m_5",OBJPROP_CORNER,0); ObjectSet("m_5",OBJPROP_XDISTANCE,10); ObjectSet("m_5",OBJPROP_YDISTANCE,50); ObjectCreate("m_15",OBJ_LABEL,2,0,0); ObjectSetText("m_15","M15 "+iRSI(NULL,15,14,PRICE_CLOSE,0),9,NULL,White); ObjectSet("m_15",OBJPROP_CORNER,0); ObjectSet("m_15",OBJPROP_XDISTANCE,10); ObjectSet("m_15",OBJPROP_YDISTANCE,35); ObjectCreate("m_60",OBJ_LABEL,2,0,0); ObjectSetText("m_60","M60 "+iRSI(NULL,60,14,PRICE_CLOSE,0),9,NULL,White); ObjectSet("m_60",OBJPROP_CORNER,0); ObjectSet("m_60",OBJPROP_XDISTANCE,10); ObjectSet("m_60",OBJPROP_YDISTANCE,20);
ObjectCreate("m_60",OBJ_LABEL,2,0,0);Don't hard code constants. If you add or remove an indicator your code breaks. Find the sub-window like @Jack Thomas said.
whroeder1:
Don't hard code constants. If you add or remove an indicator your code breaks. Find the sub-window like @Jack Thomas said.
thanks!! i will do that i just did that for testing
Don't hard code constants. If you add or remove an indicator your code breaks. Find the sub-window like @Jack Thomas said.

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
ok so the first ObjectCreate puts it in window 0 (main) and the second ObjectCreate puts it in the 2 i dont know why???