Fibonacci EA - Newbie

 

Hi,

I am VERY new to MQL4 coding and have just been mucking around really, looking at some of the articles and the book on here to see what I can learn.

What I am trying to create is an expert advisor that opens trades based on fibonacci levels. I strategy is this:

In an downtrending market,

where the price retraces to enter the 'trade zone' (between the 38.2% and 61.8% fib levels) the EA waits starts looking for a trade,

Once this has happened I want the EA to open a sell trade when the price drops back down and a canlde closes below the 75% fib level

The stoploss should be set above the 0% say 20 pips (although ideally this pip level would be adjustable)

The takeprofit set at about 50 pips (although also adjustable)

In an uptrending market it should open a buy order but with the same entry criteria

I have tried, and I am in no way under the belief that what I have done is even close to correct but the attempt is attached.

I also have not included anything in this attempt with regard to determining and up or down trend. i made a parameter 'higher_to_lower' so that this could just be changed from true to false depending on whether the trader thinks the market is trending up or down.

I think that I may be close to getting the EA to calculate the fib levels but beyond this i was really just copying from an example in the MQL4 book with regard to opening and closing, modifying what i thought needed to be changed to fit and leaving the rest.

Like I said this is a first, and presumably horrible attempt and I dont necessarily expect anyone to help out but I thought it wouldnt hurt to ask. any advice at all would be greatly appreciated.

Thanks in advance

-Andrew

Files:
fibs_2.mq4  11 kb
 
abaillie wrote >>

Hi,

I am VERY new to MQL4 coding and have just been mucking around really, looking at some of the articles and the book on here to see what I can learn.

What I am trying to create is an expert advisor that opens trades based on fibonacci levels. I strategy is this:

In an downtrending market,

where the price retraces to enter the 'trade zone' (between the 38.2% and 61.8% fib levels) the EA waits starts looking for a trade,

Once this has happened I want the EA to open a sell trade when the price drops back down and a canlde closes below the 75% fib level

The stoploss should be set above the 0% say 20 pips (although ideally this pip level would be adjustable)

The takeprofit set at about 50 pips (although also adjustable)

In an uptrending market it should open a buy order but with the same entry criteria

I have tried, and I am in no way under the belief that what I have done is even close to correct but the attempt is attached.

I also have not included anything in this attempt with regard to determining and up or down trend. i made a parameter 'higher_to_lower' so that this could just be changed from true to false depending on whether the trader thinks the market is trending up or down.

I think that I may be close to getting the EA to calculate the fib levels but beyond this i was really just copying from an example in the MQL4 book with regard to opening and closing, modifying what i thought needed to be changed to fit and leaving the rest.

Like I said this is a first, and presumably horrible attempt and I dont necessarily expect anyone to help out but I thought it wouldnt hurt to ask. any advice at all would be greatly appreciated.

Thanks in advance

-Andrew

I have managed to make an indicator that does what i want it to do but need help making an EA makes trades based on the information in it.

What this does is draws fib levels at 25, 38.2, 62.8, 75 and 161.8.

It determines the 0 adn 100% levels based on whether the market is trending up or down. I plan to use this on the 5min charts so the trend is determined based on two MAs with periods 30 and 10 on the 1 Hour chart. If the 30 MA is aboe the 10 MA then the market is trending down and vice versa. I figure this is a good way to get an overall trend to apply to the 5 min chart.

What i want is an EA that opens a trade in the direction of the market when the price retraces to between the 61.8 and 38.2 levels and then turns back in the direction of the market so that the EA opens a trade when a candle closes above(or below) the 75% level.

Can anyone help me with this? or guide me in the right direction?

Also, is it possible to make determine the high/low so that they are at least 40pips apart? from what i can see it is only possible to calculate them based on a number of bars back but this does not always give an accurate representation whereas a high/low based on price difference is a much better guide.

Thanks

Files:
 
abaillie:

I have managed to make an indicator that does what i want it to do but need help making an EA makes trades based on the information in it.

What this does is draws fib levels at 25, 38.2, 62.8, 75 and 161.8.

It determines the 0 adn 100% levels based on whether the market is trending up or down. I plan to use this on the 5min charts so the trend is determined based on two MAs with periods 30 and 10 on the 1 Hour chart. If the 30 MA is aboe the 10 MA then the market is trending down and vice versa. I figure this is a good way to get an overall trend to apply to the 5 min chart.

What i want is an EA that opens a trade in the direction of the market when the price retraces to between the 61.8 and 38.2 levels and then turns back in the direction of the market so that the EA opens a trade when a candle closes above(or below) the 75% level.

Can anyone help me with this? or guide me in the right direction?

Also, is it possible to make determine the high/low so that they are at least 40pips apart? from what i can see it is only possible to calculate them based on a number of bars back but this does not always give an accurate representation whereas a high/low based on price difference is a much better guide.

Thanks

abaillie,

Thanks for the work you have done on this so far. I am wondering if you have made any improvements to it in the last couple of years?

Thanks,

prose

 
abaillie:

I have managed to make an indicator that does what i want it to do but need help making an EA makes trades based on the information in it.

What this does is draws fib levels at 25, 38.2, 62.8, 75 and 161.8.

It determines the 0 adn 100% levels based on whether the market is trending up or down. I plan to use this on the 5min charts so the trend is determined based on two MAs with periods 30 and 10 on the 1 Hour chart. If the 30 MA is aboe the 10 MA then the market is trending down and vice versa. I figure this is a good way to get an overall trend to apply to the 5 min chart.

What i want is an EA that opens a trade in the direction of the market when the price retraces to between the 61.8 and 38.2 levels and then turns back in the direction of the market so that the EA opens a trade when a candle closes above(or below) the 75% level.

Can anyone help me with this? or guide me in the right direction?

Also, is it possible to make determine the high/low so that they are at least 40pips apart? from what i can see it is only possible to calculate them based on a number of bars back but this does not always give an accurate representation whereas a high/low based on price difference is a much better guide.

Thanks

Hi Abaillie,

Here are the iCustom statements needed for using the "BailsiFibs" indicator (.mq4) . I did not test these statements or test your indicator, but they should work fine. It also looks like you are using 2 Fib indicators, one a .mq4 file and the other a compiled .ex file with a different name?

This example below uses the .mq4 file.

The key to iCustom statements is to include ALL parameters (or remove all the externs in the indicator so you don't have any parameters to list). The same principle works for the .ex buffers as well (except you can't remove the externs in the compiled .ex file).

fib_1 = iCustom(Null,0,"BailsiFibs",StartBar, BarsBack, MA_1_Calc_Period, MA_2_Calc_Period, Percent1, Percent2, Percent3, Percent4, Extension1,0,0);
fib_2 = iCustom(Null,0,"BailsiFibs",StartBar, BarsBack, MA_1_Calc_Period, MA_2_Calc_Period, Percent1, Percent2, Percent3, Percent4, Extension1,1,0);
fib_3 = iCustom(Null,0,"BailsiFibs",StartBar, BarsBack, MA_1_Calc_Period, MA_2_Calc_Period, Percent1, Percent2, Percent3, Percent4, Extension1,2,0);
fib_4 = iCustom(Null,0,"BailsiFibs",StartBar, BarsBack, MA_1_Calc_Period, MA_2_Calc_Period, Percent1, Percent2, Percent3, Percent4, Extension1,3,0);
fib_5 = iCustom(Null,0,"BailsiFibs",StartBar, BarsBack, MA_1_Calc_Period, MA_2_Calc_Period, Percent1, Percent2, Percent3, Percent4, Extension1,4,0);
fib_6 = iCustom(Null,0,"BailsiFibs",StartBar, BarsBack, MA_1_Calc_Period, MA_2_Calc_Period, Percent1, Percent2, Percent3, Percent4, Extension1,5,0);
fib_7 = iCustom(Null,0,"BailsiFibs",StartBar, BarsBack, MA_1_Calc_Period, MA_2_Calc_Period, Percent1, Percent2, Percent3, Percent4, Extension1,6,0);

You also need to add these parameter names and values to your EA externs...or you can hardcode them into your iCustom statements.

fib_1 = iCustom(Null,0,"BailsiFibs",0, 50, 10, 30, 0.25, 0.382, 0.618, 0.75, 1.618, 0, 0); Do the same for each buffer.

Yes you can make it trade on the conditions you stated, however that sounds like two different conditions for two different trades?
1) Retrace between 2 levels
2) Closes above or below the 75% level.

Now that you have the buffer values from your iCustom statements, you can now refine your Buy Sell conditions more exactly.

Hope this helps,
Robert
 

I am not sure about "BailsFib" but the key to any fib ea is making sure the lines are always in the correct place. There are good free fib indicators like Autotrend fib which uses "zigzag" to find the highs and lows which can be cpu intensive if using multiple indicators. A proprietary choice is "Fib and Potatoes" which has better accuracy and less cpu usage. But free is free. With any indicator you could use a small script to catch the FIB_PRICE1 and FIB_PRICE2 to create an EA using price collision detection.

double price1=ObjectGet("FibNAme, OBJPROP_PRICE1),

price2=ObjectGet("FibName", OBJPROP_PRICE2;

//then get the levels wtih a loop

if(Bid=FibPrice&&OtherCondition()==true){ OrderSend(Symbol(),OP_BUY,lots,Ask,Slippage,Ask-sl*Point,0,comment,magic,0,Green);}


Or something similar to it. I hope this help[s someone I am working on a similar piece ATM.