Help with an EA - one variable seems to counteract another statement - page 3

 
RaptorUK:

You seem to be missing my point . . .

You said . . .

  . . .   you need to remember that price has passed into and out of the zone to initiate a buy,  but this may have happened 4 days ago so you need to know when to forget that the price has passed into and out of the zone,  hence my question earlier in this thread about when the condition is invalided so that you can "forget" that price went into and out of the zone.  Don't think about code,  get the logic right first . . .


I am trying :) I appreciate the help...

 

This all happens whilst Trend  = uptrend.

If trend becomes a downtrend it resets everytning, and the zone changes.

Price just needs to "touch" the zone to validate. (I may add a one bar close in the zone later during testing if necessary to validate the setup further, but that is speculative for now and can be added later)

Naturally on the same bar price may move in and out of the zone.  Is there some time series function I should be using?

 
simoncs:


I am trying :) I appreciate the help...

 

This all happens whilst Trend  = uptrend.

If trend becomes a downtrend it resets everytning, and the zone changes.

Price just needs to "touch" the zone to validate. (I may add a one bar close in the zone later during testing if necessary to validate the setup further, but that is speculative for now and can be added later)

Naturally on the same bar price may move in and out of the zone.  Is there some time series function I should be using?

OK,  so does this make sense ( bear in mind that I don't fully understand your strategy ) . . .

  • Create an additional bool called  BarCheckSet
  • Only call BarCheck if BarCheckSet == false 
  • When BarCheck returns true also set BarCheckSet to true
  • When the trend changes from uptrend to downtrend or downtrend to uptrend unset (set to false) BarCheckSet 

 
RaptorUK:

OK,  so does this make sense ( bear in mind that I don't fully understand your strategy ) . . .

  • Create an additional bool called  BarCheckSet
  • Only call BarCheck if BarCheckSet == false 
  • When BarCheck returns true also set BarCheckSet to true
  • When the trend changes from uptrend to downtrend or downtrend to uptrend unset (set to false) BarCheckSet 


hmmm - ok will have a play with that tomorrow and let you know.. thks

 

so BarCheck - checks price is in correct zone - as it is currently doing

and then BarCheckSet,  encompasses Barcheck and price moving out again?

 
simoncs:


hmmm - ok will have a play with that tomorrow and let you know.. thks

 

so BarCheck - checks price is in correct zone - as it is currently doing

and then BarCheckSet,  encompasses Barcheck and price moving out again?

BarCheckSet tells you that you have recorded the fact that BarCheck has returned tue and allows you to keep this value set.  You are probably going to have to do something with BarCheckSet in the BarCheck function, maybe return true if BarCheckSet is true.
 
RaptorUK:
BarCheckSet tells you that you have recorded the fact that BarCheck has returned tue and allows you to keep this value set.  You are probably going to have to do something with BarCheckSet in the BarCheck function, maybe return true if BarCheckSet is true.


Didn't have much luck with adding the BarCheckSet - the principal of it makes complete sense to me, but unfortunately I couldn't work out where to put it so that when the BarCheck became false, it din't impact the BarCheckSet. I am guessing this has to do with the correct use of brackets, but my efforts didn't seem to work.

However whilst doing this I did manage to get BarCheck to not reset by principally changing where BarCheck is reset (yes I know this could now be used for BarCheckSet). But this led onto another issue in that even though Barcheck was set and ready for a trade, if price continued down and out the bottom of the zone before coming back up, it wasn't picking this up.

So what I am thinking is split out BarCheck to be two variables.

  •  one for Price enters zone = true
  • one for price must not drop below the bottom of the zone whilst trend is up. - This one got me thinking though, back to what you said earlier about knowing when price was in the zone. I don't think I can use either the Ask/Bid to lookback over a period of time to make sure price did not go through the bottom of the zone, can I ? So i started looking at ilowest and ihighest.

I am thinking I could then declare a variable that is the lowest low whilst trend is up (which I can then reset when necessary - but I wasn't sure how to achieve that - ilowest syntax seems to require the number of bars to lookback. So how can I get the lowest low since trend is up?

is it something like declare variable  - int i then if (Trend = Uptrend) count bars ?  Then use "i" in the ilowest syntax?

I am just not sure how I can construct that, or if it will do what I want.

Any suggestions? 

 
simoncs:

I am thinking I could then declare a variable that is the lowest low whilst trend is up (which I can then reset when necessary - but I wasn't sure how to achieve that - ilowest syntax seems to require the number of bars to lookback. So how can I get the lowest low since trend is up?

is it something like declare variable  - int i then if (Trend = Uptrend) count bars ?  Then use "i" in the ilowest syntax?

If you know when the trend switched from down to up you can get the bar number from the datetime using iBarShift() . . . but if you need to look back and determine this you can probably just as easily get the bar number, one thing to be said for using the datetime,  it doesn't change when a new bar forms,  the bar number for the place where the trend changed will.
 
RaptorUK:
If you know when the trend switched from down to up you can get the bar number from the datetime using iBarShift() . . . but if you need to look back and determine this you can probably just as easily get the bar number, one thing to be said for using the datetime,  it doesn't change when a new bar forms,  the bar number for the place where the trend changed will.


Thanks Raptor for all your help. I think I solved the issue for now.

I created the Highestprice and Lowestprice variables that I can use to compare. These get reset as well when the trend changes. So now the EA seems to be doing what it should.

 

//first calculate number of Bars
CountSwingBars = iBarShift(Symbol(),ExtBarCheckTF,SwingDate[0]);


if (Trend == UpTrend)
{
LowestPrice = iLow(NULL,ExtBarCheckTF,iLowest(Symbol(),ExtBarCheckTF,MODE_LOW,CountSwingBars,0));
}
if (Trend == DownTrend)
{
HighestPrice = iHigh(NULL,ExtBarCheckTF,iHighest(Symbol(),ExtBarCheckTF,MODE_HIGH,CountSwingBars,0));
}      
         
}