Adjustment in code because combined stops can not be used with pro order
Forums › ProRealTime English forum › ProOrder support › Adjustment in code because combined stops can not be used with pro order
- This topic has 34 replies, 4 voices, and was last updated 4 years ago by Vonasi.
-
-
09/03/2019 at 6:16 AM #106303
I need some help with this code please. First of all i cant run it on pro order because i get an error saying combined stops can not be used with pro order. Is there anyway i can change code so that it places sl first and when trailing conditions become true it cancels SL and continue with trailing? Will this be possible and how must i change the code..
Second I want to add like a buffer to the entry. For example if the close of candle is at 50 000 i want to add maybe 20 points so that my entry is at 50 020 and not exactly 50 000. Same for sell but just -20 points. Can someone please help me to change the code
Break of 8:45 candle123456789101112131415161718192021DEFPARAM CUMULATEORDERS=FALSEDEFPARAM FLATAFTER = 091500BeginTime = 090000LossValue = 15TraillingValue = 5TargetValue = 30IF Time = BeginTime THENCondition1 = (Close > Open)Condition2 = (Close < Open)IF Condition1 THENBUY 6 SHARE AT MARKETELSIF Condition2 THENSELLSHORT 6 SHARE AT MARKETENDIFENDIFSET STOP LOSS LossValue TRAILING TraillingValueSET TARGET PROFIT TargetValue09/03/2019 at 8:01 AM #106308Line 20 is not supported you have to choose whether using SET STOP LOSS LossValue or SET STOP TRAILING TraillingValue.
Even if you write them on separate lines, the last line will override the previous one, no matter the order.
I, and almost everybody else on this forum, use SET STOP LOSS LossValue, then add a snippet of code to trail stops in non-native form. Read https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/ for a full working breakeven/trailing stop code.
You may also read:
https://www.prorealcode.com/blog/learning/trailing-stop-max-favorable-excursion-mfe/
https://www.prorealcode.com/topics-tag/trailing/
09/03/2019 at 8:29 AM #106315Hi
Thank you for the reply.. I will try and change the code. DO you know how i can change my code to not buy exactly on the close high but to add 20 points. Because i need a small buffer. allot of trades just opens a buy immediately but then goes the other way. and if I had a small buffer of like 20 points it would not have taken the buy but the sell instead.
I hope its clear to understand.
Thanks for all the help
09/03/2019 at 8:37 AM #106317The simplest way is to use a pending Long(Short order, your line 13 would be (same for line 16, but using SELLSHORT):
1BUY 6 SHARE AT close + 20 * pipsize STOPbut pending orders only last one bar, so if a trade is not triggered and you still want it to be, you’ll need to place it again and again each candle.
Or you can slightly modify your code to save your desired price (the one you had increased, then check when CLOSE is >= and enter a trade).
09/04/2019 at 8:31 PM #106532Hi
Thank you very much for all your help and on the forum.. I changed the whole code with some codes you gave on other topics. I need your help please for the last time.(I hope)
- I think the code doesnt cancel the sell code when buy is triggered it will do both buy and sell on the same candle Can you help me how i must change to fix this please.
- I want to add the function to add to a winning so if system enters a buy trade and price moves 50 points in my direction i want to add another trade to it. So i try to explain buy order at 50 000 then price moves up 50 050 then i want to enter another buy.. Both if possible be managed by trailing. I dont know if its possible.
Thank you
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475DEFPARAM CumulateOrders = falseDEFPARAM FLATBefore = 084500 //09:00DEFPARAM FLATAfter = 091500 //21:00DEFPARAM PreLoadBars = 2000ONCE nLots = 5ONCE MaxPrice = 999999ONCE MinPrice = 0starttime = 090000SET STOP LOSS 150IF time = starttime THENMaxPrice = highest[1](high) //Il massimo/minimo delle ultime 12 barreMinPrice = lowest[1](low) // (ogni ora = 12 barre da 5 minuti)ENDIF//************************************************************************// trailing stop functiontrailingstart = 20 //5 trailing will start @trailinstart points profittrailingstep = 60 //5 trailing step to move the "stoploss"////reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL=0 AND close-tradeprice(1)>=trailingstart*pointsize THENnewSL = tradeprice(1)+trailingstep*pointsizeENDIF//next movesIF newSL>0 AND close-newSL>=trailingstep*pointsize THENnewSL = newSL+trailingstep*pointsizeENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND tradeprice(1)-close>=trailingstart*pointsize THENnewSL = tradeprice(1)-trailingstep*pointsizeENDIF//next movesIF newSL>0 AND newSL-close>=trailingstep*pointsize THENnewSL = newSL-trailingstep*pointsizeENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIF//************************************************************************// LONGif not onmarket and starttime thenbuy Nlots contract at MaxPrice + 20 * pointsize STOPif countofposition = 1 thenbuy 1 contract at tradeprice + 50 stopendifsellshort Nlots contract at MinPrice - 20 * pointsize STOPMaxPrice = 999999MinPrice = 0ENDIFif countofposition = 1 thenbuy 1 contract at tradeprice + 50 stopendifif countofposition = -1 thensellshort 1 contract at tradeprice - 50 stopendif09/04/2019 at 8:58 PM #106535I already answered this question for you in one of your similar topics. You seem to be asking the same questions in several different places!
https://www.prorealcode.com/topic/need-help-with-automatic-a-strategy-for-dax-and-sa40/#post-105408
You have to use MTF and trade in a faster time frame if you want to cancel a pending order when an opposite order is filled.
09/06/2019 at 7:49 AM #106667HI
Yes but this is a new code that I need help with. So what you are telling me is that its not possible to cancel another pending order if one is activated?
I dont have much coding experience and i need help please I am trying my best to code and learn but somethings i cant get right to work.. Thats why i am here to ask the experts.
Please help me to get this code right.
Thank you
09/06/2019 at 7:52 AM #106669Pending orders CANNOT ba cancelled because they are automatically cancelled by ProOrder at the closure of each candlestick. You simply need not place it again.
09/06/2019 at 11:08 AM #106693Yes it is possible to cancel one order if another one is filled (well within 1 second) but as I showed you in the other topic in order to cancel one order if another one is filled you have to use MTF and trade on the 1 second time frame otherwise the two orders are on the market until the close of whatever time frame candle you are using. So if it s a 15 minute chart you have 15 minutes in which both orders could be filled.
As I also said before using the 1 second chart will limit your available back test data to just about two and a half days if you have 100k bars and double that if you have 200k bars.
So someone could spend some time trying to work out what you are trying to do with the code (which seems a bit confused at the entry and exit part and also seems to be just other bits of code mixed together) but I doubt very much whether you will be happy with the results or that the back test on only two and a half days data would tell you very much at all about the strategies robustness.
Perhaps you should just set out in clear and simple terms what the complete strategy theory is and then maybe someone who has been messing around with strategies for a long time can tell you why your theory might or might not work before someone goes to a lot of effort to convert it to a code that you are not happy with.
09/06/2019 at 11:20 AM #106695I spent five minutes on your last code example and I got it to at least open and close trades. Whether they are what you want I have no idea!
Launch it on 1 second chart.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475DEFPARAM CumulateOrders = falseDEFPARAM FLATBefore = 084500 //09:00DEFPARAM FLATAfter = 091500 //21:00DEFPARAM PreLoadBars = 2000timeframe(1 second)ONCE nLots = 5ONCE MaxPrice = 999999ONCE MinPrice = 0starttime = 090000timeframe (15 minute, updateonclose)IF time = starttime THENMaxPrice15 = highest[1](high) //Il massimo/minimo delle ultime 12 barreMinPrice15 = lowest[1](low) // (ogni ora = 12 barre da 5 minuti)ENDIFtimeframe(1 second)//************************************************************************// trailing stop functiontrailingstart = 20 //5 trailing will start @trailinstart points profittrailingstep = 60 //5 trailing step to move the "stoploss"////reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL=0 AND close-tradeprice(1)>=trailingstart*pointsize THENnewSL = tradeprice(1)+trailingstep*pointsizeENDIF//next movesIF newSL>0 AND close-newSL>=trailingstep*pointsize THENnewSL = newSL+trailingstep*pointsizeENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND tradeprice(1)-close>=trailingstart*pointsize THENnewSL = tradeprice(1)-trailingstep*pointsizeENDIF//next movesIF newSL>0 AND newSL-close>=trailingstep*pointsize THENnewSL = newSL-trailingstep*pointsizeENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIF//************************************************************************// LONGminprice = minprice15maxprice = maxprice15if not onmarket then//and starttime thenbuy Nlots contract at MaxPrice + 20 * pointsize STOPsellshort Nlots contract at MinPrice - 20 * pointsize STOPMaxPrice = 999999MinPrice = 0ENDIFif countofposition = 1 thenbuy 1 contract at tradeprice + 50 stopendifif countofposition = -1 thensellshort 1 contract at tradeprice - 50 stopendifSET STOP LOSS 15009/08/2019 at 3:30 PM #106843Hi Guys
Thank you for the help.. I know my code is a few codes put together but it sort of does what is needed. I am not a coder and can really find someone who will write a complete code for me so i tried myself I want it to place a trade on the break of the 8:55 candle when market opens at 9:00. So when break up it buys and when breaks down it sell. I wonder of i can just change it somehow not to place pending order buy just buy at market when conditions are met. So not place stop order but just place order at market when price reaches the break, I am running it on South African 40 on 5 min timeframe. If you run it you will see that because of pending order it enters 2 trades on the same candle. Thats why i want to try and change it to just buy when it reaches conditions. If you can just help me to change the code so it buys at market rather then placing pending orders. And if buy is triggered it will not enter sell again if price moves a little down again. Because like you said it wont be possible to cancel pending orders in the same candle. With my exit of course i am trying to trail it as far as possible.
Thank you in advance
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566DEFPARAM CumulateOrders = falseDEFPARAM FLATBefore = 084500 //09:00DEFPARAM FLATAfter = 210000 //21:00DEFPARAM PreLoadBars = 2000ONCE nLots = 10ONCE MaxPrice = 999999ONCE MinPrice = 0starttime = 090000SET STOP LOSS 150IF time = starttime THENMaxPrice = highest[1](high) //Il massimo/minimo delle ultime 12 barreMinPrice = lowest[1](low) // (ogni ora = 12 barre da 5 minuti)ENDIF//************************************************************************// trailing stop functiontrailingstart = 20 //5 trailing will start @trailinstart points profittrailingstep = 80 //5 trailing step to move the "stoploss"////reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THENnewSL = tradeprice(1)+trailingstep*pipsizeENDIF//next movesIF newSL>0 AND close-newSL>=trailingstep*pipsize THENnewSL = newSL+trailingstep*pipsizeENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THENnewSL = tradeprice(1)-trailingstep*pipsizeENDIF//next movesIF newSL>0 AND newSL-close>=trailingstep*pipsize THENnewSL = newSL-trailingstep*pipsizeENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIF//************************************************************************// LONGif not onmarket and starttime thenbuy Nlots contract at MaxPrice + 20 * pointsize STOPif not onmarket and starttime thensellshort Nlots contract at MinPrice - 20 * pointsize STOPMaxPrice = 999999MinPrice = 0endifendif09/08/2019 at 5:10 PM #106857In PRT you have two choices pending orders or buy at market. If you place any pending order then it will be on the market from the open of the next candle until the candle closes. There is no way to cancel it mid candle and there is no way to cancel any other orders mid candle if another order is filled. In fact there is absolutely no way to add an order or change an order mid candle.
At market orders will simply be filled or closed at the opening price of the next candle.
So unless you use a very fast time frame such as the 1 second time frame just like I have shown you on what now feels like several occasions then you are trying to do the impossible. It is not possible to buy at market mid candle – it is not possible to cancel orders mid candle – unless you do what I have suggest many times and use MTF!
09/08/2019 at 5:40 PM #106870Yes this i understand maybe you understood me wrong.. but because of this problem i just want it to buy on the high of the candle and sell on the low. It must not place any stop/pending orders but just buy on the high and sell on the low. like you do it manually if price reach the high i just click on buy or when it reaches low i just click on sell.. So if i understand correct it is not possible to do this? I dont want to place any pending order rather just buy or sell on this condition. Can it be done? I hope its clear. I know about the pending orders but cant it just buy and no go into a sell while still in the buy trade?
09/08/2019 at 6:17 PM #106876So when you say ‘buy’ you really mean SELLSHORT and when you say ‘sell’ you really mean EXITSHORT. Trying to decipher what you are actually trying to do is hard enough without you saying buy when you mean sell!
All orders are sent to market at candle open so if you want to set a price to SELLSHORT at then you can use a pending LIMIT order to enter at a better price and if you know what price you want to EXITSHORT at then send another pending LIMIT order to market to exit at at a better price than your entry price.
To do what you want to do which is buy/sellshort at a price or sell/exitshort at a price you HAVE to use pending orders.
So the conclusion is that – no you can’t do what you want to do -without use pending orders.
09/11/2019 at 7:35 AM #107148123456789101112131415161718192021222324252627282930313233343536373839//-------------------------------------------------------------------------// Main code : MySystem(13)//-------------------------------------------------------------------------//-------------------------------------------------------------------------// Main code : MySystem(8)//-------------------------------------------------------------------------DEFPARAM CumulateOrders = falseDEFPARAM FLATBefore = 084500 //09:00DEFPARAM FLATAfter = 210000 //21:00DEFPARAM PreLoadBars = 2000ONCE nLots = 5ONCE MaxPrice = 999999ONCE MinPrice = 0starttime = 090000SET TARGET PROFIT 120IF time = starttime THENMaxPrice = highest[6](high) //Il massimo/minimo delle ultime 12 barreMinPrice = lowest[6](low) // (ogni ora = 12 barre da 5 minuti)ENDIF//************************************************************************// LONGif not onmarket and starttime thenbuy Nlots contract at MaxPrice + 20 * pointsize STOPset stop loss close- Minprice + 20 * pointsizeif not onmarket and starttime thensellshort Nlots contract at MinPrice - 20 * pointsize STOPset stop loss MaxPrice - close - 20 * pointsizeMaxPrice = 999999MinPrice = 0endifendifHi
Thank you for all the responses.. Can you please tell me whats wrong why the system will place trades on some days and other days not even though conditions were met? You can run it on 5 min chart South african 40.
Thanks
-
AuthorPosts
Find exclusive trading pro-tools on