How to get price from Fibo (OBJ_FIBO)

 

I am not being lazy here, I have done several searches on this. I have posted another thread Fibo Mania trying to resolve this issue.

I need to get the prices on the fibo lines. Now there have only been a handful of people working with code or putting code on this forum that covers fibo. So the resources are limited. I then searched the internet abroad and sitll the same, very little details on it.

I am currently using QuickFibo, a variation that I modified, see thread.

All I want to do is to know the prices of each of the lines including the extensions. So here is some code that I have found that is doing different things around what I am looking for:

Setting price and fibo levels in description:

   int    obj_total = ObjectsTotal();
   string name,text;
   int i, j;
   for(i = 0; i < obj_total; i++)
     {
       name = ObjectName(i);
       if(ObjectType(name) == OBJ_FIBO)
         {
           for(j = 0; j < 32; j++)
             {
               if(GetLastError() != 0) 
                 break;
               switch (TextStyle)
               {
                 case 2 :
                   // Style 2 example is:  61.8  234.67
                   ObjectSetFiboDescription(name, j, DoubleToStr(ObjectGet(name,
                                        OBJPROP_FIRSTLEVEL+j)*100,1) + "  %$");
                   break;
                 case 0 :
                   // Style 0 example is:  61.8
                   ObjectSetFiboDescription(name, j, DoubleToStr(ObjectGet(name,
                                        OBJPROP_FIRSTLEVEL+j)*100,1));
                   break;
                 default:
                   // default, or style 1.  Example:  (61.8) - 234.67
                   ObjectSetFiboDescription(name, j, "(" + DoubleToStr(ObjectGet(name,
                                        OBJPROP_FIRSTLEVEL+j)*100,1) + ")" + " - %$");
               }
             }
         } else if(ObjectType(name) == OBJ_EXPANSION)
         {
           for(j = 0; j < 32; j++)
             {
               if(GetLastError() != 0) 
                 break;
               switch (TextStyle)
               {
                 case 2 :
                   // Style 2 example is:  FE 61.8  234.67
                   ObjectSetFiboDescription(name, j, "FE " + DoubleToStr(ObjectGet(name,
                                        OBJPROP_FIRSTLEVEL+j)*100,1) + "  %$");
                   break;
                 case 0 :
                   // Style 0 example is:  FE 61.8
                   ObjectSetFiboDescription(name, j, "FE " + DoubleToStr(ObjectGet(name,
                                        OBJPROP_FIRSTLEVEL+j)*100,1));
                   break;
                 default:
                   // default, or style 1.  Example:  FE (61.8) - 234.67
                   ObjectSetFiboDescription(name, j, "FE (" + DoubleToStr(ObjectGet(name,
                                        OBJPROP_FIRSTLEVEL+j)*100,1) + ")" + " - %$");
               }
             }
         }

The only documentation for getting the Fibo description:

#include <stdlib.mqh>
  ...
  string text;
  for(int i=0;i<32;i++)
    {
     text=ObjectGetFiboDescription(MyObjectName,i);
     //---- checking whether the objects has less than 32 levels
     if(GetLastError()!=ERR_NO_ERROR) break;
     Print(MyObjectName,"level: ",i," description: ",text);
    }

Now it is very frustrating to find that these other code snippets seem to be handling the description of the lines, but when I attempt to use any of this code I get a 4201 error about an object. I used the same object name as QuickFib used, so why isn't it working. Here is what I am currently attempting:

      ObjectCreate(objOuterId, OBJ_FIBO, 0, Time[shiftLowest], Low[shiftLowest], Time[shiftHighest], High[shiftHighest]);   
      ObjectSet(objOuterId, OBJPROP_COLOR, ColorDowntrend);
      ObjectSet(objOuterId, OBJPROP_LEVELCOLOR, ColorDowntrend);
      ObjectSet(objOuterId, OBJPROP_LEVELSTYLE, STYLE_DOT);      
      
      ObjectGet(objOuterId, ObjectFind(objOuterId));
      for(j = 0; j < 32; j++)
      {
         ObjectSetFiboDescription(objOuterId, j, "(" + DoubleToStr(ObjectGet(objOuterId,
            OBJPROP_FIRSTLEVEL+j)*100,1) + ")" + " - %$");
            err = GetLastError();
         if(err != 0)
         {
            Print(err, " set: ", ErrorDescription(err));
            break;
         }
      }

      
      for(int i=0;i<32;i++)
      {
         text=ObjectGetFiboDescription(objOuterId,i);
         //---- checking whether the objects has less than 32 levels
         err = GetLastError();
         if(err !=0)
         {
            Print(err, " get: ", ErrorDescription(err));
            break;
         }
         Print(objOuterId,"level: ",i," description: ",text);
      }

What really bothers me is that there is no existing code snippet of actually accessing the data of a fibo. I have a hard time believing that MT4 would create an object and not have a method for accessing the data related to the object.

 

why getting the values from the object? calculate the values inside your code. Nicer, faster, better ;)


//z

 
zzuegg:

why getting the values from the object? calculate the values inside your code. Nicer, faster, better ;)



Yep, thats what I do :)

-BB-

 
zzuegg:

why getting the values from the object? calculate the values inside your code. Nicer, faster, better ;)

//z


Why getting values from the object?!?!? LOL! Are you serious?

What if you are developing an EA that allows dropping a fibo object on a chart and you want to be able to add/change/delete levels via the chart without having to re-load the EA? How do you programmatically get the %s used without having to read the description and do string manipulation (if fib object has been modified to display things other than just the %)?

 
dlewisfl:


Why getting values from the object?!?!? LOL! Are you serious?

Why are you replying to an 18 moth old post ? do you need some help ?

The fact is you cannot get the pries of all the lines in a Fib, you can get the prices for the anchor lines and you can get the other lines level values . . . but if you want prices of lines other than the anchors you have to calculate them.

 
RaptorUK:

Why are you replying to an 18 moth old post ? do you need some help ?

The fact is you cannot get the pries of all the lines in a Fib, you can get the prices for the anchor lines and you can get the other lines level values . . . but if you want prices of lines other than the anchors you have to calculate them.


When you say you can get the other line's level values, do you mean the percentages? Or just the level # (0 - 31) and the description?
 
dlewisfl:

When you say you can get the other line's level values, do you mean the percentages? Or just the level # (0 - 31) and the description?
I mean the %ages . . . and from the %ages and the 2 anchor price values you can calculate the other levels prices. The anchors are always at 0 and 1 (100%).
 
RaptorUK:
I mean the %ages . . . and from the %ages and the 2 anchor price values you can calculate the other levels prices. The anchors are always at 0 and 1 (100%).

Still trying to see how that's "nicer, faster, better", as original responder claims, versus just reading the prices from the object, which would require zero calculations in your code. Of course, since you can't read the prices from the object, you're forced into re-calculating what's already been calculated for you. Seems a more appropriate response would have simply stated, as you did, that you can't get the price from the object and must code it. ObjectGet with OBJPROP_FIBOLEVELS, OBJPROP_FIRSTLEVELx and the two TIME/PRICE properties to get the 0/100 level.

 
Perhaps there was an element of misunderstanding between question asker and question answerer.
 

You can't but calculate it :

double getFiboLevel( double up, double dw, double lev, int direction ){

   double ling = up - dw;
   double pLev = ( ling / 100 ) * lev;
   
   return ( direction < 0 ) ? NormalizeDouble( up - pLev, Digits ) : NormalizeDouble( dw + pLev, Digits ) ;

}
Comment( DoubleToString( getFiboLevel( LastZZhigh, LastZZlow, 23.6, 1 ) ) );
 

ANY SOLUTION

Reason: