Auto Fib

 

Hello all,

My question relates to the attached indicator. It draws Fibonacci retracements from zigzags. I want to include it as part of my EA under an iCustom, however unfortunately the Fibonacci retracements don't show in the data window so I can't draw off the values. Does anyone know how this could be amended to include such information?

Thanks!

Files:
 

BUMP!!

Anyone?!

 

Use ObjectGetValuesByShift Instead Of Buffers

crsnape@btinternet.com:
Hello all,

My question relates to the attached indicator. It draws Fibonacci retracements from zigzags. I want to include it as part of my EA under an iCustom, however unfortunately the Fibonacci retracements don't show in the data window so I can't draw off the values. Does anyone know how this could be amended to include such information?

Thanks!

Use ObjectGetValuesByShift Instead Of Buffers

Hi Crsnape...

There is a way to get the values of the Fibo Lines without using Buffers...

Use - ObjectGetValuesByShift

You just have to know the names of the Fibo Lines to get their values.

Place your cursor on the lines to get the name of the Fibo Lines...then use them directly in your EA.

Search for ObjectGetValuesByShift to find some examples.

I haven't tried it with Fibo Lines...but it should work for you.

BTW - some Fibo indicators don't label their lines.

In your case...the Fibo Lines for Zigzagy Auto Fibo are named right in the indicator settings so you have them right there.

Hope this helps,

Robert

 

I see.

The name of the 38.2 fibonacci line (which is the one I want to use) is "FIBO382 line". So is this correct:

int TrendChartShift = iBarShift(NULL, TrendChart, Time[0]);

Fib_38.2 = ObjectGetValueByShift(FIBO382 line, TrendChartShift + 1)

Thing is, this is a custom indicator, so I need to put iCustom somewhere right? But iCustom returns its value. A value that I don't need as the data I require is instead being drawn through ObjectGetValueByShift. But I need to load the Custom Indicator right? Whats the best way to go about this? Something like this maybe?

Fib_38.2 = iCustom(NULL, TrendChart, "ZigZagy Auto Fibo", 12, 5, 3, 0, TrendChartShift + 1)

Fib_38.2 = ObjectGetValueByShift(FIBO382 line, TrendChartShift + 1)

 

Use ObjectGetValueByShift

crsnape@btinternet.com:
I see.

The name of the 38.2 fibonacci line (which is the one I want to use) is "FIBO382 line". So is this correct:

int TrendChartShift = iBarShift(NULL, TrendChart, Time[0]);

Fib_38.2 = ObjectGetValueByShift(FIBO382 line, TrendChartShift + 1)

Thing is, this is a custom indicator, so I need to put iCustom somewhere right? But iCustom returns its value. A value that I don't need as the data I require is instead being drawn through ObjectGetValueByShift. But I need to load the Custom Indicator right? Whats the best way to go about this? Something like this maybe?

Fib_38.2 = iCustom(NULL, TrendChart, "ZigZagy Auto Fibo", 12, 5, 3, 0, TrendChartShift + 1)

Fib_38.2 = ObjectGetValueByShift(FIBO382 line, TrendChartShift + 1)

Good work so far. You are very close.

Your 1st example is correct to get the Fibo line value.

Your 2nd example with iCustom will get the value for buffer 1 (ZigzagBuffer)...not your FIbo line.

The indicator does need to be on the chart to get the Fibo line values.

The indicator either needs to be manually placed on the chart when running the EA...or...you can use iCustom that calls the indicator...but only to get the Fibo lines on the chart...not for getting any iCustom values (use a different name for the iCustom value...not the Fibo name).

Once the Fibo lines are on the chart...

Then use the ObjectGetValueByShift to get the PRICE line value of the Fibo lines.

Also...in the specific case of Fibo lines (or any horizontal lines)...the PRICE does not change with the shift...so no need to add +1 or the iBarShift statements...just 0 shift is fine.

That PRICE value only changes when the Fibo lines change.

Next step is to start adding Print or Comments to start checking your Fibo lines price values...and then use them in your EA strategy.

Hope this helps you.

Robert

 

Thanks for your help so far. So this is the code I've come up with:

iCustom(NULL, TrendChart, "ZigZagy Auto Fibo", 12, 5, 3, 0, TrendChartShift + 1);

int TrendChartShift = iBarShift(NULL, TrendChart, Time[0]);

Fib_38.2 = ObjectGetValueByShift(FIBO382 line, TrendChartShift);

I didn't realise you could call the indicator iCustom without assigning it to a variable. Does this look ok?So I'm now at the next stage of my code. I've been trying to do it this weekend but am struggling. What I want to do is have my EA look for long (or short) positions if price has broken the 38.2 fib level. I already have the buying criteria in place, I just want yo refine it to it only enters when price has retraced far enough. How would I do this? I've done this so far:

static bool FibTriggeredUpTrend = false;

static bool FibTriggeredDownTrend = false;

if (UpTrend == true && DownTrend == false && SignalUpTrend == true && SignalDownTrend == false

{

if (Ask

 

Auto Fib - Use ObjectGetValueByShift

Hi crsnape,

Regarding the iCustom variable...Neither did I...

I was surprised that the iCustom compiled OK without a variable....but...I suggest it's better to be safe to assign a variable just in case.

The main key is to call the iCustom indicator to display it's Fibo lines on the chart when testing and running on Demo or Live.

Your Buy/Sell code does not show how it relates to your Fibo382 line...so I don't know how they work together to answer your question...?

For retracement (or crossing distance)...just add the pips distance to your Buy/Sell code...(plus or minus depending on if it's retracement or crossing...and whether it's for a Buy or Sell)...

Example: if Price > Fibo + cross distance (or retreat distance)...then Buy or Sell..

Hope this helps you,

Robert

 

Sorry my original post seems to have been cut short. This is what is should have read (with some minor changes):

Thanks for your help so far. So this is the code I've come up with:

iCustom(Symbol(), TrendChart, "ZigZagy Auto Fibo", 12, 5, 3, Red, 4, 0, Aqua, 0, LightGray, Yellow, Red, White, White, Red, White, Aqua, 0, TrendChartShift + 1);

double Fib_38.2 = ObjectGetValueByShift("FIBO382 line", TrendChartShift);

I didn't realise you could call the indicator iCustom without assigning it to a variable. Does this look ok?

So I'm now at the next stage of my code. I've been trying to do it this weekend but am struggling. What I want to do is have my EA look for long (or short) positions if price has broken the 38.2 fib level. I already have the buying criteria in place, I just want to refine it so it only enters when price has retraced far enough to break the 38.2 fib.

static bool FibTriggeredUpTrend = false;

static bool FibTriggeredDownTrend = false;

if (UpTrend == true && DownTrend == false && SignalUpTrend == true && SignalDownTrend == false)

{

if (Ask <= Fib_38.2)

{

FibTriggeredUpTrend = true; FibTriggeredDownTrend = false;

}

}

if (UpTrend == false && DownTrend == true && SignalUpTrend == false && SignalDownTrend == true)

{

if (Bid >= Fib_38.2)

{

FibTriggeredUpTrend = false; FibTriggeredDownTrend = true;

}

}

For Buying:

if (OrdersTotal() < 1)

{

if (FibTriggeredUpTrend == true && FibTriggeredDownTrend == false && ...)

Ticket = OrderSend(...

The thing is, I still want it to search for long positions if it breaks the 38.2 fib with a shadow and closes above it. Because in my strategy this is a valid signal.

Any ideas how I would do this?

 

Just a small comment...

I'm not sure why you would want to use "ObjectGetValuesByShift" at all, since it seems to me that ObjectGet(lineName,OBJPROP_PRICE1) is the same thing. (The line is horizontal, right?)

It was also mentioned that not all fib indicators draw separate trendline objects at the key levels of interest. I'd just like to point out that if you know the price of the high and low of a swing, then, for example..

pr1 = ObjectGet(fiboName,OBJPROP_PRICE1);

pr2 = ObjectGet(fiboName,OBJPROP_PRICE2);

price382 = pr1 + 0.382 * (pr2 - pr1);

You really don't need for there to be a specific line object drawn at the 0.382 fib level.

Just sayin'

 

Hello all!

I havent had much success with your responses so let me try and explain it better!

I want my EA to only enter long (or short) positions until it has retraced a certain distance- 38.2% or more. To do this I need my EA to recognise when it has entered this 38.2% retracement zone. I can use the the custom indicator 'ZigZagy Auto Fibo' (attached) to help with this - what this indicator does is automatically draw the important fibonacci retracements based on the zig zag indicator. I use this code to call this indicator and attach it to my chart:

iCustom(Symbol(), TrendChart, "ZigZagy Auto Fibo", 12, 5, 3, Red, 4, 0, Aqua, 0, LightGray, Yellow, Red, White, White, Red, White, Aqua, 0, TrendChartShift + 1);

I then use these lines of code to draw off the price level at the 38.2% fibonacci retracement level:

int TrendChartShift = iBarShift(NULL, TrendChart, Time[0]);

double Fib_38.2 = ObjectGetValueByShift("FIBO382 line", TrendChartShift);

So now when my EA checks whether to enter a long position, for instance, it uses this:

if (this && that && this && that && Ask < Fib_38.2) // Long entry criteria. All must be true.

Ticket = OrderSend(...

This is fine, however there is a problem. If price retraces and breaks the 38.2% fibonacci retracement with a long wick and the same candle, whether 5M, or 15M or 1H etc closes back above the 38.2% then the EA won't enter a trade even though its a valid signal. It is a valid single because price has retraced of a sufficient distance to break the 38.2% fibonacci retracement. However because it closed back above it it will no longer apply.

How would I code this to overcome this problem?

I have tried for several weeks now to no avail so would very much appreciate your help!!

Thanks in advance.

Chris.

 

Anyone...?

Reason: