Move to BE on Confirmation of Market Structure
Forums › ProRealTime English forum › ProOrder support › Move to BE on Confirmation of Market Structure
- This topic has 19 replies, 4 voices, and was last updated 3 years ago by Steveaw.
-
-
06/27/2020 at 1:11 PM #137284
Hi All
One key strategy I use manually is confirmation of direction with market structure or break of market structure. This uses significant higher highs and significant lower lows.
I am wondering if it is possible to code this? For example if I enter into a Long trade with defined target (say TP=100) and stop loss (say SL=20), then when the market structure continues in my favour I want to move my SL to BE & then continue to move my SL via trailing stop as market continues in my favour
I currently do this by (on a Long Trade) looking for a past significant high to be broken up after entering ( current higher high) and a higher low been established after a previous significant Low.
I’ve attached a Line & Point as well as a candlestick chart to illustrate the strategy, so basically I would be looking for a sequence as below as price cycles up:
- H2 > H1
- L2 > L1
- Then move SL to break even
- IF H3 > H2 & L3 > L2 Then
- Move SL to L1 etc etc
- Exit would be if price breaks this market structure say if
- H3 < H2 & L3 < L2
The strategy obviously would need to be scanning previous reference bars from entering into the trade (or last reference bar if first BE condition has already been met) to establish these significant Highs & Lows rather than just the previous bar.
Does this sound feasible?
06/27/2020 at 2:18 PM #137288There you go (I did not test it, though):
123456789101112131415161718192021222324252627282930313233ONCE SigHI1 = 0ONCE SigHI2 = 0ONCE SigLO1 = 0ONCE SigLO2 = 0ONCE LookBack = 10IF Not OnMarket ThenMySL = 0ENDIFMaxHI = max(open,close)MinLO = min(open,close)Bullish = close > openBearish = close < openSwingHI = highest[LookBack](MaxHI)SwingLO = lowest[LookBack](MinLO)SigHI = SwingHI AND Bearish AND Bullish[1]SigLO = SwingLO AND Bullish AND Bearish[1]IF LongOnMarket AND SigHI > 0 AND SigHI > SigHI1 THENSigHI2 = SigHI1SigHI1 = SigHIIF SigHI1 > SigLO1 THENMySL = max(TradePrice,max(MySL,SigLO1))ENDIFELSIF ShortOnMarket AND SigLO > 0 AND SigLO < SigLO1 THENSigLO2 = SigLO1SigLO1 = SigLOIF SigLO1 < SigHI1 THENMySL = min(TradePrice,min(MySL,SigLO1))ENDIFENDIFIF OnMarket AND MySL <> 0 THENSELL AT MySL StopEXITSHORT AT MySL StopENDIFa significant Swing point is often recognized as such by the space to its left, so I used a LOOKBACK value of 10 bars, which you can adjust to suit your needs.
Of course this snippet is to be added to your existing code.
06/27/2020 at 2:53 PM #137290Above added as Log 228 to here …
1 user thanked author for this post.
06/27/2020 at 3:07 PM #13729206/27/2020 at 3:31 PM #137293I changed line 6 to “ Not OnMarket” (there was a missing space). Sorry.
06/27/2020 at 3:48 PM #13729706/27/2020 at 5:19 PM #137314Indeed they are not used, so you can delete lines 2, 4, 18 and 24.
1 user thanked author for this post.
06/28/2020 at 5:15 PM #137413TAKE PROFITS AT BREAK OF MARKET STRUCTURE12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667//TAKE PROFITS AT BREAK OF MARKET STRUCTURE//-------------------------------------------------------------------------// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivateddaysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0if onmarket or strategyprofit<>strategyprofit[1] thenflag = 1endifif dayofweek <> dayofweek[1] thenflag = 0endifentry=13495SET STOP pLOSS slSET TARGET pPROFIT tpsl=20tp=100// Conditions to enter long positionnotradetime1=213000notradetime2=233000notradetime=time>notradetime1 and time<notradetime2timeframe (20 seconds, updateonclose)c1=low<=entrytimeframe(default, updateonclose)IF not daysForbiddenEntry and not flag and not onmarket and not notradetime and c1 ThenBuy 1 perpoint AT MARKETENDIF// from PRCtimeframe (60 minutes, updateonclose)ONCE SigHI1 = 0//ONCE SigHI2 = 0ONCE SigLO1 = 0//ONCE SigLO2 = 0ONCE LookBack = 5IF Not OnMarket ThenMySL = 0ENDIFMaxHI = max(open,close)MinLO = min(open,close)Bullish = close > openBearish = close < openSwingHI = highest[LookBack](MaxHI)SwingLO = lowest[LookBack](MinLO)SigHI = SwingHI AND Bearish AND Bullish[1]SigLO = SwingLO AND Bullish AND Bearish[1]IF LongOnMarket AND SigHI > 0 AND SigHI > SigHI1 THEN//SigHI2 = SigHI1SigHI1 = SigHIIF SigHI1 > SigLO1 THENMySL = max(TradePrice,max(MySL,SigLO1))ENDIFELSIF ShortOnMarket AND SigLO > 0 AND SigLO < SigLO1 THEN//SigLO2 = SigLO1SigLO1 = SigLOIF SigLO1 < SigHI1 THENMySL = min(TradePrice,min(MySL,SigLO1))ENDIFENDIFIF OnMarket AND MySL <> 0 THENSELL AT MySL StopEXITSHORT AT MySL StopENDIFHi Roberto
Please find attached the code in which I’ve inserted your modified suggestion. I’ve also attached the results.
I cannot see why it doesn’t take profits at the first break of Market structure (I’ve marked up the chart)?
The code I’ve used gets me in at a set point on the 20 sec chart & I’me using your code on the 1 hr to monitor when there is a sign of it reversing.
The plan is if I can get this recognising a change in market structure (either a break, hence reversal or a continuation I can then ask it to either move my stop to BE and follow it up on subsequent significant higher highs etc. Or take profits if a definite
break of structure.
Any suggestions
Steve06/28/2020 at 5:22 PM #137416I’ll take a look at your code tomorrow morning.
Please do not add text to your code, unless each line is commented with leading double slashes “//“. Thank you 🙂
I moved it below your code.
06/28/2020 at 8:09 PM #13742706/28/2020 at 8:22 PM #13742806/29/2020 at 11:10 AM #137477I tested it on Usd/Cad, 1h + 20s, but no trade was enterd on June 23rd at 13:00 (my first trade was entered on the 24th.
Can you post a more recent trade (20 seconds only have about 5 days of data history) ?
06/29/2020 at 2:42 PM #13751106/29/2020 at 4:55 PM #13752906/29/2020 at 5:52 PM #137538Sorry, buy I don’t jave thet instrument and can’t replicate your trades.
I have Spot UsdJpy, or IG’s CFD.
-
AuthorPosts
Find exclusive trading pro-tools on