Orders Rejected due to incorrect SL an TP
Forums › ProRealTime English forum › ProOrder support › Orders Rejected due to incorrect SL an TP
- This topic has 7 replies, 4 voices, and was last updated 3 years ago by
15482847.
-
-
04/19/2022 at 5:07 PM #191912
Good evening everyone,
I am struggling to get my code to open new orders. I have a simple entry rule and a set stop loss and set take profit. I am trying to update the code so that as it approaches the Stop Loss, it enters more trades (Up to 3 additional trades) – all with the same stop loss and take profit as the original trade.
The problem I am getting now is that all my orders are rejected as stop loss tries to enter with price 16,000 and Take Profit 115,000 while the index price is around 66,000. I have tried every combination of PipSize/p/$ and can’t get it to work. In reality take profit and stop loss should only be a few hundred points away from the index price, not tens of thousands!
If anyone could point out where I am going wrong, I would greatly appreciate it!
Kind regards,
Anton
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102//Code parametersDEFPARAM CumulateOrders = TRUEDEFPARAM FLATBEFORE = 083500DEFPARAM FLATAFTER = 180000noEntryBeforeTime = 083500noEntryAfterTime = 180000timeEnterAfter = time < noEntryAfterTimedaysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0SSS = 270TPT = 110GAP2 = SSS/3//ONCE Capital = 100000//ONCE Risk = 0.05//equity = Capital + StrategyProfit//maxrisk = round(equity*Risk)//PositionSize = abs(round((maxrisk/SSS)/2))PositionSize = 5//Positions = abs(CountOfPosition)IF Positions > Positions[1] THENIF LongOnMarket THENSSS2 = (Close - SSS)*PipSizeELSIF ShortOnMarket THENSSS2 = (Close + SSS)*PipSizeENDIFENDIF// Conditions to enter new positionsIF NOT ONMARKET THENLONGRULE = (close[0] >= open[0])SHORTRULE = (open[0] >=close[0])IF LONGRULE THENBUY PositionSize CONTRACT AT MARKETSSS2 = (close - SSS)*PipSizeTPT2 = (close + TPT)*PipSizeSET TARGET PROFIT TPT2SET STOP LOSS SSS2ENDIFIF SHORTRULE THENSELLSHORT PositionSize CONTRACT AT MARKETSSS2 = (close + SSS)*PipSizeTPT2 = (close - TPT)*PipSizeSET STOP LOSS SSS2SET TARGET PROFIT TPT2ENDIFENDIF// Conditions to add addition positionsIF LONGONMARKET THENALR = (close[0] < tradeprice(1)-(GAP2*PipSize))IF ALR THENBUY PositionSize CONTRACT AT MARKETSSS2 = (TradePrice[Positions] - SSS)*PipSizeTPT2 = (TradePrice[Positions] + TPT)*PipSizeSET STOP LOSS SSS2SET TARGET PROFIT TPT2ENDIFENDIFIF SHORTONMARKET THENASR = (close[0] >= tradeprice(1)+(GAP2*PipSize))IF ASR THENSELLSHORT PositionSize CONTRACT AT MARKETSSS2 = (TradePrice[Positions] + SSS)*PipSizeTPT2 = (TradePrice[Positions] - TPT)*PipSizeSET TARGET PROFIT TPT2SET STOP LOSS SSS2ENDIFENDIFIF LongOnMarket THENSELL AT SSS2 STOPELSIF ShortOnMarket THENEXITSHORT AT SSS2 STOPENDIF04/20/2022 at 7:42 AM #191931You are multiplying with PIPSIZE your stoploss/takeprofit calculation, I don’t understand why? Because you already get a price value and use it with SET TARGET PROFIT and SET STOP LOSS which are both using a price distance value.
1 user thanked author for this post.
04/20/2022 at 8:00 AM #191933Thank you Nicolas, I’ve updated and they are still giving the same issue. So below, I changed Take Profit to a set amount (TPT) and Stop loss to (SSS) instead of the variables TPT2 and SSS2.
All orders now seem to use the original Stop Loss level. But the take profits are still all different. I’ve attached a picture as an example. It shows an original Long Trade then as the price dropped it entered another Long. Both have the same Stop loss but different Take profits.
Both Take profits should be where the top one is (the original level)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102//Code parametersDEFPARAM CumulateOrders = TRUEDEFPARAM FLATBEFORE = 080000 //083500DEFPARAM FLATAFTER = 180000noEntryBeforeTime = 080000//083500noEntryAfterTime = 180000timeEnterAfter = time < noEntryAfterTimedaysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0SSS = 270TPT = 110GAP2 = SSS/3//ONCE Capital = 100000//ONCE Risk = 0.05//equity = Capital + StrategyProfit//maxrisk = round(equity*Risk)//PositionSize = abs(round((maxrisk/SSS)/2))PositionSize = 5//Positions = abs(CountOfPosition)IF Positions > Positions[1] THENIF LongOnMarket THENSSS2 = TradePrice - SSS*PipSizeELSIF ShortOnMarket THENSSS2 = TradePrice + SSS*PipSizeENDIFENDIF// Conditions to enter new positionsIF NOT ONMARKET THENLONGRULE = (close[0] >= open[0])SHORTRULE = (open[0] >=close[0])IF LONGRULE THENBUY PositionSize CONTRACT AT MARKETSSS2 = close - SSS*PipSizeTPT2 = close + TPT*PipSizeSET TARGET PROFIT TPT //TPT2SET STOP LOSS SSS //SSS2ENDIFIF SHORTRULE THENSELLSHORT PositionSize CONTRACT AT MARKETSSS2 = close + SSS*PipSizeTPT2 = close - TPT*PipSizeSET STOP LOSS SSS//SSS2SET TARGET PROFIT TPT//TPT2ENDIFENDIF// Conditions to add addition positionsIF LONGONMARKET THENALR = (close[0] < tradeprice(1)-(GAP2*PipSize))IF ALR THENBUY PositionSize CONTRACT AT MARKETSSS2 = TradePrice[1] - SSS*PipSizeTPT2 = TradePrice[1] + TPT*PipSizeSET STOP LOSS SSSSET TARGET PROFIT TPTENDIFENDIFIF SHORTONMARKET THENASR = (close[0] >= tradeprice(1)+(GAP2*PipSize))IF ASR THENSELLSHORT PositionSize CONTRACT AT MARKETSSS2 = TradePrice[1] + SSS*PipSizeTPT2 = TradePrice[1] - TPT*PipSizeSET TARGET PROFIT TPTSET STOP LOSS SSSENDIFENDIFIF LongOnMarket THENSELL AT SSS2 STOPELSIF ShortOnMarket THENEXITSHORT AT SSS2 STOPENDIF04/20/2022 at 8:24 AM #191939Try using TradePrice(1), instead of TradePrice[1].
1 user thanked author for this post.
04/20/2022 at 3:17 PM #19196904/20/2022 at 4:25 PM #19197804/20/2022 at 5:06 PM #191980Graph12345678910111213.........IF LongOnMarket THENSELL AT SSS2 STOPELSIF ShortOnMarket THENEXITSHORT AT SSS2 STOPENDIFGraph SSS2 as "sss2"Graph TPT2 as "TPT2"......Hi @15482847
Just simply add “Graph” at the end of your code… (and BackTest)
This will show you the “Graph” variables in your graph…
1 user thanked author for this post.
04/20/2022 at 5:28 PM #191982 -
AuthorPosts
Find exclusive trading pro-tools on