OBJ_FIBO lines

 

Hi.

In my EA I'm trying to find the closest fibonacci line that is below my last close price

However I can't figure out how to get the y-axis (or price) value of the fibonacci lines. The ObjectGet call below is returning something else.

// check FiboUp lines
for (int ix = 0; ix <= 14; ix++)
{
fiboVal = ObjectGet("FiboUp",OBJPROP_FIRSTLEVEL+ix);
if (fiboVal < lastClose && fiboVal > closestFibo)
closestFibo = fiboVal;
}

Any help will be greatly appreciated.

The Fibonacci lines were created in an indicator attached to the chart with following code:

if(ObjectFind("FiboUp") == -1)
ObjectCreate("FiboUp",OBJ_FIBO,0,StartTime,HiPrice+Range,StartTime,HiPrice);
else
{
ObjectSet("FiboUp",OBJPROP_TIME2, StartTime);
ObjectSet("FiboUp",OBJPROP_TIME1, StartTime);
ObjectSet("FiboUp",OBJPROP_PRICE1,HiPrice+Range);
ObjectSet("FiboUp",OBJPROP_PRICE2,HiPrice);
}
ObjectSet("FiboUp",OBJPROP_LEVELCOLOR,UpperFiboColor);
ObjectSet("FiboUp",OBJPROP_FIBOLEVELS,13);
ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+0,0.0); ObjectSetFiboDescription("FiboUp",0,"(100.0%) - %$");
ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+1,0.236); ObjectSetFiboDescription("FiboUp",1,"(123.6%) - %$");
ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+2,0.382); ObjectSetFiboDescription("FiboUp",2,"(138.2%) - %$");
ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+3,0.500); ObjectSetFiboDescription("FiboUp",3,"(150.0%) - %$");
ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+4,0.618); ObjectSetFiboDescription("FiboUp",4,"(161.8%) - %$");
ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+5,0.764); ObjectSetFiboDescription("FiboUp",5,"(176.4%) - %$");
ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+6,1.000); ObjectSetFiboDescription("FiboUp",6,"(200.0%) - %$");
ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+7,1.236); ObjectSetFiboDescription("FiboUp",7,"(223.6%) - %$");
ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+8,1.500); ObjectSetFiboDescription("FiboUp",8,"(250.0%) - %$");
ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+9,1.618); ObjectSetFiboDescription("FiboUp",9,"(261.8%) - %$");
ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+10,2.000); ObjectSetFiboDescription("FiboUp",10,"(300.0%) - %$");
ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+11,2.500); ObjectSetFiboDescription("FiboUp",11,"(350.0%) - %$");
ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+12,3.000); ObjectSetFiboDescription("FiboUp",12,"(400.0%) - %$");
ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+13,3.500); ObjectSetFiboDescription("FiboUp",13,"(450.0%) - %$");
ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+14,4.000); ObjectSetFiboDescription("FiboUp",14,"(500.0%) - %$");
ObjectSet("FiboUp",OBJPROP_RAY,true);
ObjectSet("FiboUp",OBJPROP_BACK,true);

thanks

 
 
milfordT:

Hi.

In my EA I'm trying to find the closest fibonacci line that is below my last close price

However I can't figure out how to get the y-axis (or price) value of the fibonacci lines. The ObjectGet call below is returning something else.

// check FiboUp lines 
for (int ix = 0; ix <= 14; ix++)
{
fiboVal = ObjectGet("FiboUp",OBJPROP_FIRSTLEVEL+ix);
if (fiboVal < lastClose && fiboVal > closestFibo)
closestFibo = fiboVal;
}

That code will get the value for the Fib line, for example 0.382 for a 38.2% line

You use something like this . .

Price1 = ObjectGet(Fib_Name, OBJPROP_PRICE1); 
Price2 = ObjectGet(Fib_Name, OBJPROP_PRICE2);
Time1 = ObjectGet(Fib_Name, OBJPROP_TIME1);  
Time2 = ObjectGet(Fib_Name, OBJPROP_TIME2);

. . . to get the time and price values for the 2 Fib anchors . . . then using that info and the info from the ObjectGet("FiboUp",OBJPROP_FIRSTLEVEL+ix); you can calculate the actual price levels for each of the Fib levels.

The Fib anchor levels have Fib percentage values of 0% and 100% (0 and 1) . .

It's just maths . . .

 

From your code . . . these are the anchor levels.

ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+0,  0.0 ); ObjectSetFiboDescription("FiboUp",0,"(100.0%) - %$"); 


ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+6,  1.000 ); ObjectSetFiboDescription("FiboUp",6,"(200.0%) - %$"); 

So between you anchors you have 100%, so to calculate your price level for your 300% line . . .

ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+10, 2.000 ); ObjectSetFiboDescription("FiboUp",10,"(300.0%) - %$"); 

. . you add the difference between the anchor price values to the value of the 100% anchor.

Rinse and repeat for the other lines . . .

Reason: