Slopey Slope

Post Reply
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Re: Slopey Slope

Post by SteveHopwood »

hilavoku wrote:Hi Steve.

Sorry for the long post :oops:

Why is the value of the LtfSlopeVal changing every tick but the PrevLtfSlopeVal not? These are the values vor calculating the direction of the slope...

Because PrevLtfSlopeVal refers to the value at the close of the previous candle. We do not need it updating at every tick as it will be the same with every tick.

:D
Thats right but why do i get every tick a different value of LtfSlopeVal? I don't think its the rigth way. I can have a slope value of the last closed bar. Okay but how can i calculate the slope of the 'current' bar when the bar has not closed yet? In my opinion its not reliable cause the value of the slope can change a lot within the current bar till it is closed.

I modifed the 'ReadIndicatorValues()' function as i think it would be right. Would you be so kind to take look? Don't consider the threshold values there represent the hight of the slope change between the last to values.
I added the values OldBarHtfTime and OldBarLtfTime. More important is the variable 'ShiftSlopeVal'. If its set to a value of 1 it means that we take the second last bar for the 'PrevLtfSlopeVal' and the last closed bar for 'LtfSlopeVal'. so we have a synchronized change of both values every time a Ltf bar closes and not every tick.

Hope you can follow my badly written thoughts.


thx in advance
Guido
Fabulous Guido, thanks. This sort of thing is why I make my code so freely available.

Guys, Guido has picked up on some muddled thinking on my part. SS only trades at the start of a new candle, yet examines the angle now and compares it with that at the close 1 candle ago.

Clearly, it should be comparing the angle at the close of the previous candle with that of two candles ago.

Version 1a in post 1 fixes this. I am tired and have done quite a lot of coding again today, so I do not promise the code is correct yet.

Thanks Guido.

:D
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
hilavoku
Trader
Posts: 170
Joined: Mon May 28, 2012 7:54 pm
Location: Germany

Re: Slopey Slope

Post by hilavoku »

My pleasure to contribute a little bit back to you / the forum.

sleep well
Guido

PS: i see i'am a little bit late with my wishing for a good night :)
Last edited by hilavoku on Thu Aug 16, 2012 4:07 pm, edited 1 time in total.
hilavoku
Trader
Posts: 170
Joined: Mon May 28, 2012 7:54 pm
Location: Germany

Re: Slopey Slope

Post by hilavoku »

Hi Steve,

me again. I looked at your new Slopey Slope EA and specially the function 'ReadIndicatorValues' .

Code: Select all

static datetime OldBarTime;
   if (HtfTimeFrame > 0)
   {
      HtfSlopeVal = GetSlope(Symbol(), HtfTimeFrame, 1);
      HtfSlopeTrend = ranging;
      if (HtfSlopeVal >= 0.4) HtfSlopeTrend = buyonly;
      if (HtfSlopeVal >= HtfBuyLevel) HtfSlopeTrend = buyhold;
      if (HtfSlopeVal <= -0.4) HtfSlopeTrend = sellonly;
      if (HtfSlopeVal <= HtfSellLevel) HtfSlopeTrend = sellhold;
   
      if (OldBarTime != iTime(NULL, HtfTimeFrame, 0) )
      {
         PrevHtfSlopeVal = GetSlope(Symbol(), HtfTimeFrame, 2);
      }//if (OldBarTime != iTime(NULL, HtfTimeFrame, 0)
      
      HtfSlopeAngle = unchanged;
      if (HtfSlopeVal > PrevHtfSlopeVal) HtfSlopeAngle = rising;
      if (HtfSlopeVal < PrevHtfSlopeVal) HtfSlopeAngle = falling;      
   }//IF (HtfTimeFrame > 0)

Did you took a look on my modified version? I don't understand the current one.

You define the static variable OldBarTime within the function. So the value of it is 0.
Then without setting a value to it you compare OldBarTime with the open time of the current higher timeframe candle. This should always give as a result 'true'.

You also calculate the slope of the last closed bar even if there is no new closed bar. So for example in the H4 TF you calculate every tick the same slope value for the last closed bar. Same applies for the lower timeframe.

I did also look at 'Flying Slope' EA . There its nearly the same...
In my opinion we should add an 'OldBarTime' variable for every timeframe we use. (Htf and Ltf).

What do you think? Did i miss the point :oops:


greetz from sunny germany
Guido
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Re: Slopey Slope

Post by SteveHopwood »

hilavoku wrote:Hi Steve,

me again. I looked at your new Slopey Slope EA and specially the function 'ReadIndicatorValues' .

Code: Select all

static datetime OldBarTime;
   if (HtfTimeFrame > 0)
   {
      HtfSlopeVal = GetSlope(Symbol(), HtfTimeFrame, 1);
      HtfSlopeTrend = ranging;
      if (HtfSlopeVal >= 0.4) HtfSlopeTrend = buyonly;
      if (HtfSlopeVal >= HtfBuyLevel) HtfSlopeTrend = buyhold;
      if (HtfSlopeVal <= -0.4) HtfSlopeTrend = sellonly;
      if (HtfSlopeVal <= HtfSellLevel) HtfSlopeTrend = sellhold;
   
      if (OldBarTime != iTime(NULL, HtfTimeFrame, 0) )
      {
         PrevHtfSlopeVal = GetSlope(Symbol(), HtfTimeFrame, 2);
      }//if (OldBarTime != iTime(NULL, HtfTimeFrame, 0)
      
      HtfSlopeAngle = unchanged;
      if (HtfSlopeVal > PrevHtfSlopeVal) HtfSlopeAngle = rising;
      if (HtfSlopeVal < PrevHtfSlopeVal) HtfSlopeAngle = falling;      
   }//IF (HtfTimeFrame > 0)

Did you took a look on my modified version? I don't understand the current one.

You define the static variable OldBarTime within the function. So the value of it is 0.
Then without setting a value to it you compare OldBarTime with the open time of the current higher timeframe candle. This should always give as a result 'true'.

You also calculate the slope of the last closed bar even if there is no new closed bar. So for example in the H4 TF you calculate every tick the same slope value for the last closed bar. Same applies for the lower timeframe.

I did also look at 'Flying Slope' EA . There its nearly the same...
In my opinion we should add an 'OldBarTime' variable for every timeframe we use. (Htf and Ltf).

What do you think? Did i miss the point :oops:


greetz from sunny germany
Guido
I am happy for the ea to take a trade on load up if the conditions are in place. At the end of the function, OldBarTime = iTime(NULL, HtfTimeFrame, 0); prevents a further examination of the indi until the start of a new candle.

Given that the ea can only look for a new trade at the start of a new candle, this is irrelevant and is a throw back to every-tick trading.

:D
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
hilavoku
Trader
Posts: 170
Joined: Mon May 28, 2012 7:54 pm
Location: Germany

Re: Slopey Slope

Post by hilavoku »

Hi Steve,

so i read the MQL4 Manual again :D .
I don't want to bother you and steal you some valuable time but i do think there are errors in the 'ReadIndikatorValues' function.

Perhaps there is someone else who can help me :oops: . Steve has enough work...

Here we go:

I understand the global variable OldBarsTime . Whenever the TradingTimeFrame is reached or there was an error in taking a trade you call 'ReadIndicatorValues' and set OldBarsTime to the acual TradingTimeFrame. I didn't saw this before and it makes sence and works perfect. :)

Now the difficult part i can't get around.

Example:

higher timeframe Htf = D1
lower timeframe Ltf = H1
TradingTimeFrame = H4


So when there is no error every four hours you call 'ReadIndicatorValues'. So far so good...

What does the function at those moments?

For the higher time frame it calculates every four hours the 'HtfSlopeVal' which it should do only once in a day :?: On the other side 'PrevHtfSlopeVal' only gets updated once a day. Which is right. Both values must change at the same time so there must both be in the same 'if' clause. :?:



For the lower time frame you do the same. This time its not the big problem cause the Ltf is 'lower' then the TradingTimeFrame. (When you look after four hours after some trading opportunities, since then the value of the lower time frame variables have changed three times.) But there can be settings where this could not be true (TradingTimeFrame is lower then Ltf) ...

The value of 'PrevLtfSlopeVal' will be set when the 'OldBarTime' is different to iTime(NULL, HtfTimeFrame, 0) . But this does mean that only once in a day the value of the lower time frame will be updated. (At this moment 'OldBarTime' represent 00:00 at some day x. The value won't change until 00:00 on day x+1 . ) So the value 'PrevLtfSlopeVal' is a maximum of 11 hours old even when you call the function every four hours.

So i think again there is a need of a OldBarTime variable for the two time frames...


Hope you won't be upset and that i'am not the fool whose brain is to small to understand :o


sincerely yours
Guido
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Re: Slopey Slope

Post by SteveHopwood »

hilavoku wrote:Hi Steve,

so i read the MQL4 Manual again :D .
I don't want to bother you and steal you some valuable time but i do think there are errors in the 'ReadIndikatorValues' function.

Perhaps there is someone else who can help me :oops: . Steve has enough work...

Here we go:

I understand the global variable OldBarsTime . Whenever the TradingTimeFrame is reached or there was an error in taking a trade you call 'ReadIndicatorValues' and set OldBarsTime to the acual TradingTimeFrame. I didn't saw this before and it makes sence and works perfect. :)

Now the difficult part i can't get around.

Example:

higher timeframe Htf = D1
lower timeframe Ltf = H1
TradingTimeFrame = H4


So when there is no error every four hours you call 'ReadIndicatorValues'. So far so good...

What does the function at those moments?

For the higher time frame it calculates every four hours the 'HtfSlopeVal' which it should do only once in a day :?: On the other side 'PrevHtfSlopeVal' only gets updated once a day. Which is right. Both values must change at the same time so there must both be in the same 'if' clause. :?:



For the lower time frame you do the same. This time its not the big problem cause the Ltf is 'lower' then the TradingTimeFrame. (When you look after four hours after some trading opportunities, since then the value of the lower time frame variables have changed three times.) But there can be settings where this could not be true (TradingTimeFrame is lower then Ltf) ...

The value of 'PrevLtfSlopeVal' will be set when the 'OldBarTime' is different to iTime(NULL, HtfTimeFrame, 0) . But this does mean that only once in a day the value of the lower time frame will be updated. (At this moment 'OldBarTime' represent 00:00 at some day x. The value won't change until 00:00 on day x+1 . ) So the value 'PrevLtfSlopeVal' is a maximum of 11 hours old even when you call the function every four hours.

So i think again there is a need of a OldBarTime variable for the two time frames...


Hope you won't be upset and that i'am not the fool whose brain is to small to understand :o


sincerely yours
Guido
To be honest Guido, I have not the faintest idea what you are talking about.

Not that it really matters. Any form of bar time I use is intended to cut down on pcu use. Here, Slope values are calculated internally, so I could simply leave everything to be calculated at every tick and this would not do any harm. Here is why I try to avoid calling custom indicators. It is a copy of a doc I created a long time ago to illustrate the disadvantage of using them in EA's:

"The biggest problem with custom indis is one that lies at the heart of Empty4. When an EA consults an indicator, the platform loads it into memory, then unloads it again once it has responded to the EA call. This takes time.

Custom indis typically consist of a number of calls to the regular indicators that ship with Empty4, and manipulate the information thus gleaned according to what the coder requires. An indicator such as AllAverages will make a number of calls to standard indicators at each tick; each indi is loaded, used, then unloaded. This takes a long time. Ridiculous, but that is how it works, and is the reason that indis such as AA and VQ slow your machine.

And then, we put the EA on multiple charts.................................
"

My Slope bots do not call custom indies, and so do not subject the cpu to the kind of hammering I describe above. So it does not matter if the occasional bar time call is not quite correct.

Ok, so from a purist/perfectionist point of view, it matters. And, I prefer to have accurate code rather than slightly faulty code. Having said that, if the choice is between me spending a day hunting down a tiny and irrelevant bug, or the same day coding a couple of potentially profitable ea's, I am clear where my priorities lie. It helps that I am neither a perfectionist of a purist. :lol:

'If it ain't bust then don't fix it' is something I learned long ago, from grim and bitter experience of fixing things until they broke. It takes a lot to drag me down that route these days. Equally, if it is bust and you have fixed it, then please post it here in a form that I can simply download, adopt and then upload to post 1 as the next version.

:D
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
hilavoku
Trader
Posts: 170
Joined: Mon May 28, 2012 7:54 pm
Location: Germany

Re: Slopey Slope

Post by hilavoku »

Hi Steve,

i totally agree with the statement : 'never change a running system' . :!:
When you say the cpu load of an integrated indi can be neglected than it's okay. I haven't checked this.

But the changes to be made are not that much and i think you can use those in many other EA's...

The second thing i mentioned was about the calculation of the variable 'PrevLtfSlopeVal' . In the 'start' function i added the following line:

Code: Select all

Print("LtfSlopeVal = ", LtfSlopeVal, "   PrevLtfSlopeVal = ", PrevLtfSlopeVal, "\n");
The output given within a single day when setting Htf = 1440 Ltf = 15 trading time frame = 240 i got the following output in the journal:

  • 2012.08.18 12:46:15 2012.08.13 12:00 Slopey Slope EURUSD,M15: LtfSlopeVal = 0.7072 PrevLtfSlopeVal = -0.3173

    2012.08.18 12:46:15 2012.08.13 08:00 Slopey Slope EURUSD,M15: LtfSlopeVal = 0.1943 PrevLtfSlopeVal = -0.3173

    2012.08.18 12:46:15 2012.08.13 04:00 Slopey Slope EURUSD,M15: LtfSlopeVal = -0.175 PrevLtfSlopeVal = -0.3173

    2012.08.18 12:46:14 2012.08.13 00:00 Slopey Slope EURUSD,M15: LtfSlopeVal = -0.2773 PrevLtfSlopeVal = -0.3173

    2012.08.18 12:46:14 2012.08.13 00:00 Slopey Slope EURUSD,M15: open #1 buy 0.01 EURUSD at 1.22890 sl: 1.21890 tp: 1.24890 ok
    2012.08.18 12:46:14 Slopey Slope inputs: Lot=0.01; RiskPercent=0; TakeProfitPips=200; StopLossPips=100; MagicNumber=0; MaxSpread=12; MaxSlippagePips=5; TradingTimeFrame=240; PipsHiddenFromCriminal=0; HiddenPips=0; HtfTimeFrame=1440; HtfBuyLevel=0; HtfSellLevel=0; LtfTimeFrame=15; LtfBuyLevel=0; LtfSellLevel=0; start_hourm=0; end_hourm=12; start_houre=12; end_houre=24; BreakEvenTargetPips=50; BreakEvenTargetProfit=10; CstTimeFrame=0; CstTrailCandles=1; JumpingStopTargetPips=50; TrailingStopTargetPips=20; DisplayGapSize=30;
    2012.08.18 12:44:51 Slopey Slope: loaded successfully


As you can see the value of 'PrevLtfSlopeVal' doesn't change within those 24 hours. But it should change like 'LtfSlopeVal' does. So this is a faulty calculation and therefore also the angle of the slope.

I did the needed changes and the output now looks like this:

  • 2012.08.18 13:36:18 2012.08.13 20:00 Slopey Slope_repaired EURUSD,M15: LtfSlopeVal = -0.6429 PrevLtfSlopeVal = -0.6464

    2012.08.18 13:36:18 2012.08.13 16:00 Slopey Slope_repaired EURUSD,M15: LtfSlopeVal = 1.6725 PrevLtfSlopeVal = 1.786

    2012.08.18 13:36:18 2012.08.13 13:00 Slopey Slope_repaired EURUSD,M15: modify #1 buy 0.01 EURUSD at 1.22890 sl: 1.22990 tp: 1.24890 ok
    2012.08.18 13:36:18 2012.08.13 12:00 Slopey Slope_repaired EURUSD,M15: LtfSlopeVal = 0.7072 PrevLtfSlopeVal = 0.8338

    2012.08.18 13:36:18 2012.08.13 08:00 Slopey Slope_repaired EURUSD,M15: LtfSlopeVal = 0.1943 PrevLtfSlopeVal = 0.2748

    2012.08.18 13:36:17 2012.08.13 04:00 Slopey Slope_repaired EURUSD,M15: LtfSlopeVal = -0.175 PrevLtfSlopeVal = -0.1852

    2012.08.18 13:36:17 2012.08.13 00:00 Slopey Slope_repaired EURUSD,M15: LtfSlopeVal = -0.2773 PrevLtfSlopeVal = -0.3173

    2012.08.18 13:36:17 2012.08.13 00:00 Slopey Slope_repaired EURUSD,M15: open #1 buy 0.01 EURUSD at 1.22890 sl: 1.21890 tp: 1.24890 ok
    2012.08.18 13:36:17 Slopey Slope_repaired inputs: Lot=0.01; RiskPercent=0; TakeProfitPips=200; StopLossPips=100; MagicNumber=0; MaxSpread=12; MaxSlippagePips=5; TradingTimeFrame=240; PipsHiddenFromCriminal=0; HiddenPips=0; HtfTimeFrame=1440; HtfBuyLevel=0; HtfSellLevel=0; LtfTimeFrame=15; LtfBuyLevel=0; LtfSellLevel=0; start_hourm=0; end_hourm=12; start_houre=12; end_houre=24; BreakEvenTargetPips=50; BreakEvenTargetProfit=10; CstTimeFrame=0; CstTrailCandles=1; JumpingStopTargetPips=50; TrailingStopTargetPips=20; DisplayGapSiz


So now both values are changing every trading timeframe and showing the last values from 1*15 min and 2*15 (30) min before. As it should be.

The attachment is the modified version. Would be nice if someone also can take a look into the code...

happy weekend :)
Guido


PS: Harry45 got a version of slopeyslope from me which also includes the difference between two slope values and when a threshold is reached it takes a trade. The modifications i did now are also included in this EA and he says that there are no errors and seems to function the right way...
You do not have the required permissions to view the files attached to this post.
Last edited by hilavoku on Mon Aug 20, 2012 7:50 am, edited 1 time in total.
User avatar
Zypip
Trader
Posts: 148
Joined: Thu Apr 26, 2012 9:44 am

Re: Slopey Slope

Post by Zypip »

hilavoku wrote:Hi Steve,

i totally agree with the statement : 'never change a running system' . :!:
When you say the cpu load of an integrated indi can be neglected than it's okay. I haven't checked this.

But the changes to be made are not that much and i think you can use those in many other EA's...

The second thing i mentioned was about the calculation of the variable 'PrevLtfSlopeVal' . In the 'start' function i added the following line:
Hi there,

Just tried your version of the Slopeyslope and opened 20 sell trades when many of the pairs' slope I am watching were actually rising :? In contrast, Steve's version seemed to work alright. Not a criticism of course, just sharing my observations.

Cheers,

Zyp
hilavoku
Trader
Posts: 170
Joined: Mon May 28, 2012 7:54 pm
Location: Germany

Re: Slopey Slope

Post by hilavoku »

Thanks for the feedback Zyp. I just changed some lines in the 'ReadIndicatorValues' function. Even when Steve's version seems to work at the moment it calculates the wrong values as i stated above. This doesn't also mean that my version is 100% right :-|

Also personally i think that the information about the TMA rising or falling is not that meaningful. The difference between the current TMA and the previous TMA could be as little than 0.001. But on this information and the TMA value itself, i don't think you can say; 'okay the TMA is rising i go for long'. I think we should add an additionally threshold for the minimum difference between those two values as i said some post's before. But this is another story...


I found a copy and paste thingy. So it would be nice if you give it another try... (attachment updated in above post)

thx in advance
Guido
Last edited by hilavoku on Mon Aug 20, 2012 8:43 am, edited 2 times in total.
User avatar
Zypip
Trader
Posts: 148
Joined: Thu Apr 26, 2012 9:44 am

Re: Slopey Slope

Post by Zypip »

hilavoku wrote:Thanks for the feedback Zyp. I just changed some lines in the 'ReadIndicatorValues' function. Even when Steve's version seems to work at the moment it calculates the wrong values as i stated above. This doesn't also mean that my version is 100% right :-|

I will look at the code and can you give me some trades the EA has taken which seem to go wrong?

thx in advance
Guido

PS: I found a copy and paste thingy. So it would be nice if you give it another try... (attachment updated in above post)
Thanks Guido, not home at the mo but will try later today and report.

Cheers,

Zyp


EDIT: tried the new version but still only sell trades open :?
Post Reply

Return to “Automated trading systems”