Values of ibands vs bands on chart different !!

Post Reply
lwtrade
Trader
Posts: 27
Joined: Wed Jan 11, 2017 9:23 am

Values of ibands vs bands on chart different !!

Post by lwtrade »

Hey everyone, I just need a more expert eye over this please...

I am printing a dot on the chart to illustrate the offset issue...
2017-07-01 10_38_47-Greenshot.png
You can see where the arrow is highlighting... the first number in the object name is correct, but then the actual price it uses is different!!!! Grrrr!!!

Any thoughts?


In troubleshooting I tried:
This is not just a printing to chart issue as the values ARE actually different (see circled values in image)
Tried about 4 different bands indicators which all produce the same lines, obviously)
Tried iCustom with Bands indi which also produced different values to chart indi's
These value differences range in value. ie not just 100 different for each bar
Values are not returning for the wrong bar... it is value to bar accurate

Here is the code I am using for iBands:

Code: Select all

iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_UPPER,i);
The print to chart function:

Code: Select all

void DrawDot(int barr, double price)   {  
   string objName = objPrefix + barr + " " + price;
   ObjectCreate(objName, OBJ_TEXT, 0, Time[barr], price);
   ObjectSetText(objName, CharToStr(159), 24, "Wingdings", Red); 
}


the entire indi:

Code: Select all

#property indicator_chart_window 
string objPrefix = "printBB_";
int init()
  {
   for (int i=1;i<100;i++){
      DrawDot(i,iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_UPPER,i));
   }
   return(0);
  }
  
int deinit(){
   deleteObjects();
   return(0);
   }

int start() {
   if (IsNewBar()) DrawDot(1,iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_UPPER,1));;
}

void DrawDot(int barr, double price)   {  
   string objName = objPrefix + barr + " " + price;
   ObjectCreate(objName, OBJ_TEXT, 0, Time[barr], price);
   ObjectSetText(objName, CharToStr(159), 24, "Wingdings", Red); 
}
      
bool IsNewBar()   {
   static datetime lastbar;
   datetime curbar = Time[0];
   if(lastbar!=curbar){
      lastbar=curbar;
      return (true);
      }
   else{
      return(false);
      }
}

void deleteObjects(){
   for(int i=ObjectsTotal();i >= 0;i--){
      if(StringSubstr(ObjectName(i),0,StringLen(objPrefix))==objPrefix) 
         ObjectDelete(ObjectName(i));    
   }  
}
You do not have the required permissions to view the files attached to this post.
User avatar
renexxxx
Trader
Posts: 860
Joined: Sat Dec 31, 2011 3:48 am

Values of ibands vs bands on chart different !!

Post by renexxxx »

You have to set the anchor point of your dot objects in the center, like so:

Code: Select all

        void DrawDot(int barr, double price)   {  
           string objName = objPrefix + barr + " " + price;
           ObjectCreate(objName, OBJ_TEXT, 0, Time[barr], price);
           ObjectSetText(objName, CharToStr(159), 24, "Wingdings", Red);
           ObjectSetInteger( ChartID(), objName, OBJPROP_ANCHOR, ANCHOR_CENTER );
        }
Cheers ...
lwtrade
Trader
Posts: 27
Joined: Wed Jan 11, 2017 9:23 am

Values of ibands vs bands on chart different !!

Post by lwtrade »

Oh Renexxxx,

That fixed it!!!! I had this issue last year as well!

Thanks a million times! :clap: :clap: :clap: :clap:
Post Reply

Return to “Coders Hangout”