Hello folks,
I’m trying to enter the market on a pullback that can occur up to five bars after one of the entry conditions is met.
I would like to enter on the furthermost right bar in this screengrab (when price pulls back to the 15EMA), but it currently doesn’t work. I can tell from the graph drawing that it is because my entry rule of close >=highfractal+7 has become invalid. How can I save this entry rule to memory and allow the system to wait 5 bars for the price to pull back to the EMA?
Thanks in advance for your help 🙂
DEFPARAM CumulateOrders = False
ONCE HighCount = Undefined
ONCE HighFractal = Undefined
ONCE NbBarLimit = 10
IF (High > High[1]) AND (High > High[2]) and high= highest[4](high) THEN
HighLevel = High
MyLimitBuy = ExponentialAverage[15](close)
MyIndex = Barindex
ENDIF
IF BarIndex >= MyIndex + NbBarLimit THEN
MyLimitBuy = 0
ENDIF
IF (High < HighLevel) THEN
HighCount = HighCount - 1
ELSIF (High >= HighLevel) THEN
HighCount = 0
ENDIF
IF HighCount = -1 THEN
HighFractal = HighLevel
ELSE
HighFractal = HighFractal
ENDIF
IF MyLimitBuy > 0 AND NOT LongOnMarket and close >=highfractal+7 THEN
BUY 1 perpoint AT MyLimitBuy LIMIT
ENDIF
SET STOP pLOSS 10
SET TARGET pPROFIT 20
graph close >=highfractal+7
You should post more details about the strategy conditions, along with a screenshot where trigger and entry points are highlighted.
Thank you for bumping this, Roberto.
Rules are:
- New higher high, 7 points or more higher than previous
- Enter when price pulls back to 15ema
I’ve attached a better screengrab showing what ought to be trigger bar and entry bar.
@Mike Boorman
I want to try to understand and help, wich Time Frame for your strategy to do some test ?
and maybe also you can change de first groupe of condition to C1 and draw the C1 condition, maybe it’s can be help you :
C1 = (High > High[1]) AND (High > High[2]) and high= highest[4](high)
IF C1 THEN
HighLevel = High
MyLimitBuy = ExponentialAverage[15](close)
MyIndex = Barindex
ENDIF
Graph C1 AS "C1"
Thanks for the response, @ZeroCafeine
I’ve amended the code like you said and created a screengrab.
I’m working on the DAX 5 minute, April 14 2023.
Hi
I don’t understand every think from your code, if you can explain more what do you want to do,
But after cheking your code and try to understand it, I saw a first problem in the line 8 :
IF (High > High[1]) AND (High > High[2]) and high= highest[4](high) THEN
// Last condition : high= highest[4](high)
this last condition is useless because it will always be true,
First case : when you use the Highset function on the last 4 candles, don’t forget that you also include the last candle (Candle[0]), so if the High of the last candle is higher than the last 3 then your code means the same thing as this: Highest[0] = High[0] and this is always true, so you don’t need this condition,
Second case : if you don’t want to include the last candle [0] in the Highest fonction, it’s possible but you have to use like this :
high = highest[4](high[1])
in this case you compare the last high with the high of the other candlestick, on the other hand in this case you want the high of the last candle to be equal to the highest high you will find, and then in this case there is a high probability that you will not find this case, it is possible but rare
I hope to be clear and not to be mistaken, if you do not understand I can make you a diagram
I’ve changed the code to the high=highest[4](high[1]) you suggested, but this isn’t the problem. My problem is that I want PRT to remember that the high condition WAS true, and then enter the market once the price drops back to the 15EMA.
I’ve done another screengrab with the new code, pointing to the bar I want to enter (in this case it comes two bars after the high condition is true). How can I enter the market here?
DEFPARAM CumulateOrders = False
ONCE HighCount = Undefined
ONCE HighFractal = Undefined
ONCE NbBarLimit = 5
C1 = high= highest[4](high[1])
If c1 then
HighLevel = High
MyLimitBuy = ExponentialAverage[15](close)
MyIndex = Barindex
ENDIF
IF BarIndex >= MyIndex + NbBarLimit THEN
MyLimitBuy = 0
ENDIF
IF (High < HighLevel) THEN
HighCount = HighCount - 1
ELSIF (High >= HighLevel) THEN
HighCount = 0
ENDIF
IF HighCount = -1 THEN
HighFractal = HighLevel
ELSE
HighFractal = HighFractal
ENDIF
IF MyLimitBuy > 0 AND NOT LongOnMarket and close >=highfractal+7 THEN
BUY 1 perpoint AT MyLimitBuy LIMIT
ENDIF
SET STOP pLOSS 10
SET TARGET pPROFIT 20
//graph highfractal
graph C1 as "C1"
@Mike Boorman
I don’t understand what you want to do between line 19 and 29, but maybe this can helo you, change all your buy condition to one condition and graph it like that :
BuyConditions = MyLimitBuy > 0 AND NOT LongOnMarket and close >=highfractal+7
IF BuyConditions THEN
BUY 1 Shares AT MyLimitBuy LIMIT
ENDIF
Graph BuyConditions AS "BuyCondition"
and you will see on the graphique, your BuyConditions is all the time false so all the time the BuyConditions = 0, So that is maybe why your code no buy anythink
There you go:
ONCE Signal = 0
Ema15 = average[15,1](close)
IF high > (high[1] + 7*PipSize) THEN
Signal = 1
ENDIF
IF OnMarket THEN
Signal = 0
ELSE
IF Signal = 1 THEN
IF low <= Ema15 THEN
BUY 1 Contract at Market
SET STOP pLOSS 50
SET TARGET pPROFIT 100
ENDIF
ENDIF
ENDIF
Thank you for your help Roberto. I’ve just run a test. As you can see from the screengrab, signal = 1 even when the market is going down, which isn’t what I want.
If the market is going down with red bars, I can’t understand how the high of the current bar could possibly be greater than the high[1] + 7? But PRT is saying it’s true.
It’s because the SIGNAL is never cleared, unless OnMarket, so if the trend reverses the signals is still retained.
This version will clear the SIGNAL whenever a candle closes BELOW Ema15:
ONCE Signal = 0
Ema15 = average[15,1](close)
IF high > (high[1] + 7*PipSize) THEN
Signal = 1
ENDIF
IF close < Ema15 THEN
Signal = 0
ENDIF
IF Not OnMarket AND Signal AND ((low <= Ema15) AND (min(open,close) >= Ema15)) THEN
BUY 1 Contract at Market
SET STOP pLOSS 50
SET TARGET pPROFIT 100
Signal = 0
ENDIF
Thanks Roberto. It’s getting closer 🙂
I want to be more clever with the previous high. At the moment signal is true if high is +7 from the previous bar, but I’d like it to be +7 from a previous high. I’m not exactly sure how to define the ‘previous high’ I am seeing with my eyes, but I’ve attached a screengrab to show what I mean.
I was trying to understand what’s the issue, but I need your latest code used.
Thanks for you offer of help, Roberto. These are the rules:
-New higher high, 7 points or more higher than last significant high
-Enter when price pulls back to 15ema
StartTime = 080000
Limitentrytime = 230000
daysforbiddenentry = OpenDayOfWeek=6 OR OpenDayOfWeek=0
Definitehigh=highest[10](high)
ONCE Signal = 0
Ema15 = average[15,1](close)
IF high > (high[1] + 7) THEN
Signal = 1
ENDIF
IF close < Ema15 THEN
Signal = 0
ENDIF
IF Not OnMarket AND Signal AND ((low <= Ema15) AND (min(open,close) >= Ema15)) and time >=StartTime and time <=LimitEntrytime and not daysForbiddenEntry THEN
BUY 1 perpoint at Market
SET STOP pLOSS 16
SET TARGET pPROFIT 5
ENDIF
graph signal
The problem is that ‘signal’ is currently derived from high[1], which is the previous bar. I don’t want to consider the previous bar. I want to consider the previous significant high with a look back. In the screengrab I have attached, I want ‘signal’ to become true on the bar where I have put the left green arrow. Once the signal becomes true, the green arrow to the right should then become an entry when the price pulls back to the 15ema.
Thank you again for your help.
Try replacing line 9 with:
IF high >= (Definitehigh[1] + 7) THEN