TheHedgeLearner++ - page 2

 

Can you guys post the latest working EA so I don't screw something up in the code You guys think this one works best? What TF and Currencies?

Thanks

 
matrixebiz:
Can you guys post the latest working EA so I don't screw something up in the code You guys think this one works best? What TF and Currencies? Thanks

I was thinking the same, though it's The Learner that has the ball. The TF is hourly; the currencies I don't know: from start I felt this EA to be hampering my temperament so I've never used it for real. Not uninteresting as coding exercise though.

 

Yup, I'm still learning and thus "the learner", hehe. Here's the latest attached.

Files:
 

Learning by Doing

the learner:
Yup, I'm still learning and thus "the learner", hehe. Here's the latest attached.

OK, Guy,....

I think we are all still learning by doing with testing your EA. It looks the EA promising profitable because it use the breakout method. If you don't mind of my stupidity in programming , would you share the logic behind the coding of the EA and the best setting you use. Perharps I can share my exprience in the break out trading of the certain pair.

BTW thank you for your effort with sharing this EA....

 

Hello Kusha,

Sorry for not replying after so long. I was away for the holidays.

This system is actually plucked out from a thread in Forex Factory. It is based on the premise of calculating the 24 hour range for the past 5 to 10 "24 Hour" periods starting from a particular time (e.g 7am) to obtain the largest and smallest range . Then obtain the Range by Range = (largest 24 hour range + smallest 24 hour range)/2. The Entry, Stoploss and Takeprofit level is then based on a percentage of Range. For example, price at 7 am is 1.8500 and the calculated range is 100 pips. Long entry would be at 1.8525 (assuming 25% of range). Stoploss would be 1.8475 (assuming 25% of range). Take Profit at 1.8575 (assuming 75% of range). The Take profit level follows the lowest low value since 7 am. It is more like a trailing take profit. For exmaple, if the price now is 1.8480, the TP will be 1.8555. If the price then increase to 1.8490, the TP remains at 1.8555. Only a new low will change its level. The Stoploss remains the same. Vice versa for short trades. All open trades will close at 6am next day and 7 pm on Fridays.

Now... there is a trailing stoploss which i have added in earlier on. But the results does not match up with my manual backtesting. Need your expertise once again Ralph! All right, for Kusha, i shall explain how the trailing stop works (there's some changes to the previous one though).

Basically, the trailing stop only starts when the profit earned so far hits 60% of the maximum take profit. Continuing with the example above, the max profit that can be earned for the day is 1.8575 (Initial TP)- 1.8525(the long entry price) = 0.0050 = 50 pips. So the trailing stop only kicks in when the price hits 1.8555 (60% of 0.0050 + 1.8525 ). The trailing stop loss level will be 80% of 60% of 0.0050 which is 0.0024.

Below attached is the latest EA so far with all the above conditions in it. The only one not working is the trailing stop. Please help me Ralph!!. hehe

Oh.. And I wish everyone reading this post a Happy New Year!!

Files:
 

happy new year

I just got back from the perfect, relaxing summer holiday, and am ready to revise the advice I've given... firstly as comments here, and then I'll add in the "corrected" software in a while.

a) re "sample_price": yes, it was not computed correctly, because it used "sample_time" rather than "last_sample". "sample_time" is the time stamp for today's sampling hour, which may be in the future, whereas "last_sample" is the time stamp of either today's or yesterday's sampling hour, to be the most recent such hour.

b) re "SB" and "Openp": there is a potential time frame confusion in using PERIOD_M5 for "SB" and then referring to "Open[SB]" for "Openp". I would suggest an explicit use of PERIOD_H1 is better.

c) re "Max*ProfitSoFar": these should probably use actual trade attributes rather than offset from the sampling hour price.

d) re "*BufferStop": these are not initialised correctly. The intention is to not apply them unless the profit threshold is reached. As is, they get initialised to 0, which ends up requiring positive positions from start, and that will cause them to close immediately (since there is the initial spread DD). Though, I think the condition is inverted as well; it should be inverted and be true if the trade should remain open.

I'll try to spend some quality time with the code and drop an update eventually.

 

Ok; I obviously had misunderstood about the trailing stop in my comment above. The attached code should be a working implementation of the idea that: if price moves to 60% of target (since sample hour), up or down, then the SL should be at 80% of the extreme (peak or trough). You may diff this version against yours, and you'll discover a couple of fixes as well; especially to dealing well with the "beginning of time" the EA experiences at backtesting.

Please ask or tell me if my edits seem confusing or wrong.

Files:
 

Oh... Now i know why the trailing stop didn't work.

I realised that the conditions to remain open has been changed from price to pips. That's something new to me... Nice work!

I did some changes to the codes (attached below is the modified EA for your reference):

1) the trailing take profit is not in place, therefore i added in take = TP * Point to take = LLV - sample_price + ( TP - OP ) * Point; so as to let the take profit level follow the LLV for a long entry and vice versa for short entry.

2) I'm still puzzled as to why its better to use PERIOD_H1 instead of M5 for the calculations of HHV, LLV, SB and sample_price. The reason for using M5 or even M1 is so that the trailing take profit would be more responsive rather than having it move only after every hour since it is calculated using HHV and LLV.

3) The stop loss is suppose to be 25% of sample_range below the sample_price so i changed the stop loss level from stop = - SL * Point to stop = - ( SL + OP ) * Point.

I'm also facing some difficulties with certain new conditions that i'm thinking of adding in:

1) I'm thinking, if it is still possible to enter the trade at the Close price instead of the Ask and Bid price? For the entry part, i tried changing the price = Ask and price = Bid in the opening conditions to price = Close[0] for both but the results showed that trades are entered at minutes other then multiples of 5 (using the 5 minute chart for backtesting). Another anormaly was that the prices that the trades entered were not the actual Close[0] prices....

2) Is it possible to exit at Close[0] price instead of Ask price and Bid price?

3) Stop and reverse: Now... this might be a little confusing but i will try my best to explain it. Currently, the system does not allow 2 trades in a day. I would like to limit it to 2 instead of 1 but i couldn't get it to work. I don't think it is that simple as to change this:

for ( i = OrdersHistoryTotal() - 1; i >=0; i-- ) [/php]

to this:

[php] for ( i = OrdersHistoryTotal() - 1; i >=1; i-- )

right? hehe

After being able to trade only 2 times a day, the next thing would be on how to reverse the trade after the first one hits the "stop = - ( SL + OP ) * Point" (not the trailing stop, only the static stop). And the entering conditions for the reverse trade is the same as the previous trade with the only difference being a Short instead of Long (assuming the previous is a Long)

In other words, if the range for the day is 100 pips, (assuming Long trade) entry level would be 25 pips above sample_price, TP level at 75 pips above sample_price, SL level at 25 pips below sample_price. When the pips earned hits negative 25 pips, the trade closes and reverses with these conditions: TP at 75 pips below sample_price, SL at 25 pips above sample_price, with all the trailing take profit and trailing stop in place. And after this trade closes, there won't be a 3rd trade for the day.

For this, i really have no idea how to do it... couldn't come up with any idea...

Files:
 
the learner:

2) I'm still puzzled as to why its better to use PERIOD_H1 instead of M5 for the calculations of HHV, LLV, SB and sample_price. The reason for using M5 or even M1 is so that the trailing take profit would be more responsive rather than having it move only after every hour since it is calculated using HHV and LLV.

Yes, I think you are right about the responsiveness, but to make it work you must then also have M5 (or M1) chart opened, so that MT4 keeps loading up that time frame as well. Using H1 is only "better" in not needing the additional chart opened.

the learner:

1) I'm thinking, if it is still possible to enter the trade at the Close price instead of the Ask and Bid price? For the entry part, i tried changing the price = Ask and price = Bid in the opening conditions to price = Close[0] for both but the results showed that trades are entered at minutes other then multiples of 5 (using the 5 minute chart for backtesting). Another anormaly was that the prices that the trades entered were not the actual Close[0] prices....

Ehh? So you want pending trades rather than immediate trades? The Ask/Bid prices are what the market accepts at that point in time, and if you are not happy with those you have to wait until the new Ask/Bid prices change to what you are happy with. I don't understand the objective here.

the learner:

2) Is it possible to exit at Close[0] price instead of Ask price and Bid price?

same deal as above

the learner:

3) Stop and reverse: ...

right? hehe

Nope :-) The right place though... instead of it returning, it should increment a counter, and then following the loop, there should be a check of the counter.

the learner:

After being able to trade only 2 times a day, the next thing would be on how to reverse the trade after the first one hits the "stop = - ( SL + OP ) * Point" (not the trailing stop, only the static stop). And the entering conditions for the reverse trade is the same as the previous trade with the only difference being a Short instead of Long (assuming the previous is a Long)

In other words, if the range for the day is 100 pips, (assuming Long trade) entry level would be 25 pips above sample_price, TP level at 75 pips above sample_price, SL level at 25 pips below sample_price. When the pips earned hits negative 25 pips, the trade closes and reverses with these conditions: TP at 75 pips below sample_price, SL at 25 pips above sample_price, with all the trailing take profit and trailing stop in place. And after this trade closes, there won't be a 3rd trade for the day.

For this, i really have no idea how to do it... couldn't come up with any idea...

mmmm... maybe next week... the heat wave here stops me from thinking ...

 

Oh... sorry for the confusion.. I will try my best to clear things up.

Quote:

Originally Posted by the learner

2) I'm still puzzled as to why its better to use PERIOD_H1 instead of M5 for the calculations of HHV, LLV, SB and sample_price. The reason for using M5 or even M1 is so that the trailing take profit would be more responsive rather than having it move only after every hour since it is calculated using HHV and LLV.

Yes, I think you are right about the responsiveness, but to make it work you must then also have M5 (or M1) chart opened, so that MT4 keeps loading up that time frame as well. Using H1 is only "better" in not needing the additional chart opened.

I'm actually using a M5 chart for this system all along and not a H1 chart... hehe. So with the use of M5 chart, other than changing the H1 to M5 for the sample_time calculations, as far as i know there is nothing else to change in the system to make it fit into a M5 chart right?

Quote:

Originally Posted by the learner

1) I'm thinking, if it is still possible to enter the trade at the Close price instead of the Ask and Bid price? For the entry part, i tried changing the price = Ask and price = Bid in the opening conditions to price = Close[0] for both but the results showed that trades are entered at minutes other then multiples of 5 (using the 5 minute chart for backtesting). Another anormaly was that the prices that the trades entered were not the actual Close[0] prices....

Ehh? So you want pending trades rather than immediate trades? The Ask/Bid prices are what the market accepts at that point in time, and if you are not happy with those you have to wait until the new Ask/Bid prices change to what you are happy with. I don't understand the objective here.

Well, not pending trade exactly.. It is more like open a long trade only when the close of the current bar is above 25% of range + sample_price and vice versa for short trades. The rational behind this is to prevent the the Ask or Bid price to just touch the 25% of range + sample_price and reverse immediately while a long trade has been opened. Sort of like a filter to sieve out false signals. Same for the exit at close price condition.

Quote:

Originally Posted by the learner

3) Stop and reverse: ...

right? hehe

Nope :-) The right place though... instead of it returning, it should increment a counter, and then following the loop, there should be a check of the counter.

Like this?

for ( i = OrdersHistoryTotal(); i >=0; i-- )

To clear things up on the stop and reverse condition just in case there is a misunderstanding... There is only maximum 2 trades a day. If and only if the first trade is being stopped out by the static stop loss, the system will stop and reverse the trade. If the stop and reverse gets stopped out by either the static or trailing stop, or took a profit, no more trades for the day.

It is getting hot here too... (X_x)