stopLoss on highest [2] high issue
Forums › ProRealTime English forum › ProOrder support › stopLoss on highest [2] high issue
- This topic has 11 replies, 3 voices, and was last updated 2 years ago by slevinkelevra.
-
-
03/04/2022 at 1:50 PM #189321
Hi there, I am having an issue and don’t know how to move forward with this, I want for the code to set my stop loss when long in the lowest of the past 2 candles and when shorting the market on the highest of the last 2 candles.
I am using function Highest but not getting the expected results, also the TP is not corresponding with the instructions I am giving. I am really new to programing though! my code is:
thank you so much in advance 🙂
1234567891011121314151617181920212223242526272829303132333435363738394041424344// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// The system will cancel all pending orders and close all positions at 0:00. No new ones will be allowed until after the "FLATBEFORE" time.DEFPARAM FLATBEFORE = 080000// Cancel all pending orders and close all positions at the "FLATAFTER" timeDEFPARAM FLATAFTER = 173000st1= lowest[2](low)tp1= st1*2st2= highest[2](high)tp2= st2*2// Conditions to enter long positionsindicator1 = ExponentialAverage[200](close)c1 = (close > indicator1)indicator2 = RSI[14](close)c2 = (indicator2 > 50)indicator3 = CALL "ENGULFING"c3 = (indicator3 > 0.5)IF c1 AND c2 AND c3 THENBUY 1 SHARES AT MARKETSET STOP pLOSS st1SET TARGET pPROFIT tp1ENDIF// Conditions to enter short positionsindicator4 = ExponentialAverage[200](close)c4 = (close < indicator4)indicator5 = RSI[14](close)c5 = (indicator5 < 50)indicator6 = CALL "ENGULFING"c6 = (indicator6 < -0.5)IF c4 AND c5 AND c6 THENSELLSHORT 1 SHARES AT MARKETSET STOP pLOSS st2SET TARGET pPROFIT tp2ENDIF03/04/2022 at 2:17 PM #189323Substitute figures in your code below and I think you will see 2 reasons it’s not working?
st1= lowest[2](low)tp1= st1*2So on DJI if lowest[2](low) is, for example, 35,000 so you be exiting at 35000 points loss or 70,000 points profit at lines 27 and 28.1 user thanked author for this post.
03/04/2022 at 2:42 PM #189324Is it because I am only entreing the value of the market and not the points value right? I have tried from different angles one of them beeing this
st2= (highest[2](high)-open[0])
but results don’t differ, in my mind that would subtract those hypothetical 35,000 from the opening of the current candle (candle that the trade is open) so I could get the number of points that its needed but the results are the same, I did try to look into many codes now to see if anyone would use this kind of stop but didn’t found one so far or found many, way more complex to my knowledge..
is there any book on the Pro Realt Time code or so? besides the courses?
03/04/2022 at 2:52 PM #189325Is it because I am only entreing the value of the market and not the points value right? I have tried from different angles one of them beeing this
st2= (highest[2](high)-open[0])
or
st2= (highest[2](high)-close[1])
but results don’t differ, in my mind that would subtract those hypothetical 35,000 from the opening of the current candle (candle that the trade is open) so I could get the number of points that its needed but the results are the same, I did try to look into many codes now to see if anyone would use this kind of stop but didn’t found one so far or found many, way more complex to my knowledge..
is there any book on the Pro Realt Time code or so? besides the courses and besides the manual PRT gives us
Want to learn more about it but have barely any base in coding
also didn’t know how to edit the post or to delete the other one
03/04/2022 at 3:19 PM #189326Is it because I am only entreing the value of the market and not the points value right?
Yes
If you wanted to use the value of the market, you would need to use something like below …
I say something like as I started with barely any base in coding also 6 years ago and even now I rely on the syntax checker in the code editor to put me straight.
If you use …
GRAPH ST1
GRAPH TP1then you will see the values as a separate area under the positions after backtest.
12345IF c1 AND c2 AND c3 THENBUY 1 SHARES AT MARKETSEll at st1 StopSEll at tp1 LimitENDIFThese may help you, but they have not been updated to current version 11, but nonetheless are very useful?
https://www.prorealtime.com/en/pdf/probacktest.pdf
https://www.prorealtime.com/en/help-manual/quick-tour
PS
We get 5 mins to edit a post after posting
Or you could do …
If Longonmarket Then
SEll at st1 Stop
SEll at tp1 Limit
ENDIF1 user thanked author for this post.
03/04/2022 at 3:28 PM #189327yeah I get it this is quite hard but it’s a really interesting tool to make us not lose so much time in backtesting stuff, especially the part where we can add variables and it automatically finds the best one.
I am really sorry But I was looking at another thing: I was looking to set the stop (while shorting the market) at the highest point of the last 2 candles and vice versa, not the high of the market.
I hope you have been getting good results with it! it’s already been a long time in coding, hope to trace a similar path.
I have read that on another post about the 5 minutes to edit still don’t find where to
thank you so much for you time
PS: I got it now the Edit part!
03/04/2022 at 4:03 PM #189331SET STOP pLOSS (and SET TARGET pPROFIT, as well), need a difference in price exèpressed as pips, NOT a price, otherwise, as suggested by GraHal, it will NEVER be hit and, in live trading, your strategy will be stopped due to a too far stop loss.
SET STOP pLOSS and SET TARGET pPROFIT should only be set ONCE per trade. To change the SL while on market you should use a pending order.
1 user thanked author for this post.
03/04/2022 at 4:18 PM #189332Hi Roberto, first of all thank you so much for THE great works and strategies that you have shared!
“need a difference in price exèpressed as pips, NOT a price”
yeah, I am getting that now but still can’t figure out how to make it, and perhaps I am also expressing myself the wrong way..
the objective is every single time it triggers a buy order long – the code should calculate what is the amount of pips between the opening of the candle that trade opened (or the close from the candle before trade opens) and the lowest pricepoint in the 2 last candles – in other words, I want to open a position and define my stop loss at the lowest point of the wave we are in. That will change in a trade by trade basis.
thats is why I thought:
lowest [2] (low) – (open[0])
or
lowest [2] (low) – (close[1]) //meaning the lowest of the two last candles (price) minus the opening of the entry candle or the close of the candle before opening trade would give me an amount of pips for the stoploss
03/04/2022 at 5:26 PM #189337SET STOP pLOSS (or LOSS) is not a trailing STOP, su using SET STOP LOSS ABS(lowest [2] (low) – (open[0])) or SET STOP pLOSS ABS(lowest [2] (low) – (open[0])) / PipSize won’t follow the price as it rises (if you opened a LONG trade), but will always modify your original distance from the Entry Price. It actually could become bigger, in case of some huge bars!
Use a STOP pending order:123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// The system will cancel all pending orders and close all positions at 0:00. No new ones will be allowed until after the "FLATBEFORE" time.DEFPARAM FLATBEFORE = 080000// Cancel all pending orders and close all positions at the "FLATAFTER" timeDEFPARAM FLATAFTER = 173000IF Not OnMarket THENst1= (close - lowest[2](low)) / PipSizetp1= st1*2myStopLoss = lowest[2](low)st2= (highest[2](high) - close) / PipSizetp2= st2*2myStopLoss = highest[2](high)ELSEIF LongOnMarket THENmyStopLoss = max(myStopLoss,lowest[2](low))SELL AT myStopLoss STOPELSEmyStopLoss = min(myStopLoss,highest[2](high))EXITSHORT AT myStopLoss STOPENDIFENDIF// Conditions to enter long positionsindicator1 = ExponentialAverage[200](close)c1 = (close > indicator1)indicator2 = RSI[14](close)c2 = (indicator2 > 50)indicator3 = 1//CALL "ENGULFING"c3 = (indicator3 > 0.5)IF c1 AND c2 AND c3 AND Not OnMarket THENBUY 1 SHARES AT MARKETSET STOP pLOSS st1SET TARGET pPROFIT tp1ENDIF// Conditions to enter short positionsindicator4 = ExponentialAverage[200](close)c4 = (close < indicator4)indicator5 = RSI[14](close)c5 = (indicator5 < 50)indicator6 = 1//CALL "ENGULFING"c6 = (indicator6 < -0.5)IF c4 AND c5 AND c6 AND Not OnMarket THENSELLSHORT 1 SHARES AT MARKETSET STOP pLOSS st2SET TARGET pPROFIT tp2ENDIF//graphonprice TradePrice(1)graphonprice myStopLoss coloured(255,0,0,255)03/04/2022 at 6:05 PM #189343oh man thank you so much for the amazing effort and I am understanding further the issue “”but will always modify your original distance from the Entry Price””. Especially this part since in reality, I don’t want a trailing stop loss, rather a fixed one but at the same time, I don’t want it to increase.
I have attached an example of what I would love to get as a result. In layman terms is just a simple entry with a fixed stop on the highest point of the two candles before the opening, and a Take profit of double that amount of pips, it either goes one way or the other without moving anything, nor the stopL neither the TP.
This is such a journey to even get one simple thing done, but such an interesting thing because on the other hand spares us months of manual work.
once again thank you so much for you time and sorry if miss explain myself
03/04/2022 at 6:45 PM #189348There you go:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// The system will cancel all pending orders and close all positions at 0:00. No new ones will be allowed until after the "FLATBEFORE" time.DEFPARAM FLATBEFORE = 080000// Cancel all pending orders and close all positions at the "FLATAFTER" timeDEFPARAM FLATAFTER = 173000st1 = abs(close - lowest[2](low))tp1 = st1*2st2 = abs(close - highest[2](high))tp2 = st2*2IF OnMarket AND Not OnMarket[1] THENst1 = abs(TradePrice - lowest[2](low[1]))tp1 = st1*2st2 = abs(TradePrice - highest[2](high[1]))tp2 = st2*2IF LongOnMarket THENSET STOP LOSS st1SET TARGET PROFIT tp1ELSESET STOP LOSS st2SET TARGET PROFIT tp2ENDIFENDIF// Conditions to enter long positionsindicator1 = ExponentialAverage[200](close)c1 = (close > indicator1)indicator2 = RSI[14](close)c2 = (indicator2 > 50)indicator3 = CALL "ENGULFING"c3 = (indicator3 > 0.5)IF c1 AND c2 AND c3 AND Not OnMarket THENBUY 1 SHARES AT MARKETSET STOP LOSS st1SET TARGET PROFIT tp1ENDIF// Conditions to enter short positionsindicator4 = ExponentialAverage[200](close)c4 = (close < indicator4)indicator5 = RSI[14](close)c5 = (indicator5 < 50)indicator6 = CALL "ENGULFING"c6 = (indicator6 < -0.5)IF c4 AND c5 AND c6 AND Not OnMarket THENSELLSHORT 1 SHARES AT MARKETSET STOP LOSS st2SET TARGET PROFIT tp2ENDIF1 user thanked author for this post.
03/04/2022 at 6:50 PM #189349thank you so much!! you just made my day!
and thank you once again for the time and dedication for both of you
cheers
2 users thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on