Dear ones.
I need your help again. I’m sorry, but that’s the way it is. Please. Maybe one or the other can shake it from the sleeve.
We have for the sake of simplicity an Outside.
Now I would like to set the buy stop 5 points above the high of the candles. But the buy stop should only be executed within 5 candles (n -candles).
This kind of stops after trigger candles can be found in the strategies of e.g. the Hikkake here
https://www.prorealcode.com/prorealtime-indicators/hikkake-pattern/.
Please, do anyone help?
There you go:
ONCE Tally = 0
OutSideBAR = (high > high[1]) AND (low < low[1])
IF OutSideBAR AND Not OnMarket THEN
Tally = 1
Entry = high + 5 * PipSize //Entry price = HIGH + 5 pips
ENDIF
IF Tally > 5 OR OnMarket THEN
Tally = 0
ELSIF Tally[1] > 0 THEN
Tally = Tally + 1
ENDIF
IF Tally AND Not OnMarket THEN
BUY 1 CONTRACT AT Entry STOP
SET STOP pLOSS 20
SET TARGET pPROFIT 20
ENDIF
//graph Tally
Hello Roberto.
Thank you very much for the code. I just got around to looking at it today and ! – I want to say your code really helps me a lot. Now I can implement it in several (known) strategies. I will offer the strategies here if done. Thank you very much.
As I see the program performs the buy stop several times within the 5 candles provided the conditions are met. See the screenshot and more detailed there after the 2.Outside.
Can you change me the code so that it enters only 1 position within the predefined 5 candles? “not onmarket” does not help because the SL/TP is very low and new positions can be entered again and again. If I set the SL/TP on my 200 points, then it works, but is not in my sense. One ( first) position should be opened and then no more within the 5 candles.
very kind regards to you
Thank you! It should be like this?
ONCE Tally = 0
OutSideBAR = (high > high[1]) AND (low < low[1])
IF OutSideBAR AND Not OnMarket THEN
Tally = 1
Entry = high + 5 * PipSize //Entry price = HIGH + 5 pips
ENDIF
IF Tally > 5 OR OnMarket THEN
Tally = 0
ELSIF Tally[1] > 0 THEN
Tally = Tally + 1
ENDIF
MaxShares = abs(COUNTOFPOSITION) <= 1
IF Tally AND Not OnMarket AND MaxShares THEN
BUY 1 CONTRACT AT Entry STOP
SET STOP pLOSS 20
SET TARGET pPROFIT 20
ENDIF
//graph Tally
I tried it to optimize this setup, but the results are in all timeframes with tick-by-tick backup, horrible.
with tick-by-tick backup, horrible.
Any ideas why this is so and / or any ideas for improvement?
with tick-by-tick backup, horrible.
Any ideas why this is so and / or any ideas for improvement?
Well, I think SL/TP are to close
Please excuse me. It was not about the strategy of trading exactly this breakout. It was about the coding itself, how the code can look like – to trade the breakout after n candles after one candle.
Examples
We have a new 20 candle high that is immediately sold. We want to buy on a breakout above the high candle, but only within 10 candles.
We are trading an IDNR4 and want to buy/sell on a breakout (long/short) within the next 2 candles.
The same with PopGuns.
Or finer. We buy on a breakout above a bearish divergence within the next n candles.
Etc etc
I miss the basic programming skills, I’m sorry, thanks for your help
JSParticipant
Senior
Hi @f1_maik
I tried Roberto’s first code and don’t see that the code opens multiple positions within 5 candles…
In your answer #204467 you talk about a screenshot and more details but unfortunately this screenshot has not been uploaded…
Can you post it again?
Enclosed is the screenshot, 4H candle in the Dax
You can try it yourself, big candle small SL/TP
Try replacing line 9 with this one, to account for trades opened and closed on the same bar:
IF Tally > 5 OR OnMarket OR (StrategyProfit <> StrategyProfit[1]) THEN
Thank you Roberto for making this clear.
My mistake not to read you correctly, I would never have noticed otherwise
Thank you
Hello Roberto.
Again me and again on the subject of breakout in the next 5 candles.
The problem is as follows.
Above we have the SL and TP with 20 points and the trade starts directly in the 1.candle after the Outside and wins.
Then the price immediately falls below the StopBuy and in the next candle we trigger the StopBuy and a 2nd trade is started within the 5 candles. This 2nd or 3rd or 4….. Trade I would like to prevent.
How to code that the breakout is traded only once within the 5 candles? Cumulateorders false does not work sufficiently, dito not onmarket and the like. It must be ensured that the trade starts only 1x.
Can it solve countofposition? Countofposition <= 1 within the last 5 candles? Something like that? Can this be programmed in PRT, what would be the code for it?
lg
This should work (I added the OTD check, One Trade per Day):
ONCE Tally = 0
OTD = (Barindex - TradeIndex(1) > IntradayBarIndex)
OutSideBAR = (high > high[1]) AND (low < low[1])
IF OutSideBAR AND Not OnMarket THEN
Tally = 1
Entry = high + 5 * PipSize //Entry price = HIGH + 5 pips
ENDIF
IF Tally > 5 OR OnMarket OR (StrategyProfit <> StrategyProfit[1]) THEN
Tally = 0
ELSIF Tally[1] > 0 THEN
Tally = Tally + 1
ENDIF
MaxShares = abs(COUNTOFPOSITION) <= 1
IF Tally AND Not OnMarket AND MaxShares AND OTD THEN
BUY 1 CONTRACT AT Entry STOP
SET STOP pLOSS 20
SET TARGET pPROFIT 20
ENDIF
//graph Tally