Make 2 positions into 1
Forums › ProRealTime English forum › ProOrder support › Make 2 positions into 1
- This topic has 6 replies, 3 voices, and was last updated 6 years ago by
Vonasi.
-
-
12/27/2019 at 11:39 PM #115507
Hello,
What i would like help with is if my system opens up X amounts of positions i want them all to count as 1. Meaning when all of the positions is = to X amount of + pips/$ i want it to close all open positions. The problem i have atm is that my system closes one of the positions as soon as it hits TP and dont care if there is more then 1 position open.
this is what is what im using atm to close my open positions if there is more then 1 open;
123IF countoflongshares=>2 AND close>(positionprice+extrapips*pipsize) THENSELL AT MARKETENDIF12/28/2019 at 12:45 AM #115514All open positions are always closed at one time. Whenever you place a SELL order ProOrder closes all positions in live trading, while ProBackTest allows closing partial positions.
In case of multiple open positions there can only be one SL and one TP.
12/28/2019 at 8:57 AM #115516marcuscn – Please use the ‘Insert PRT Code’ button when posting code to make it more readable. I have tidied up your post 🙂
Your code will close all positions at the close of a candle if price is extrapips above your average entry price. To close mid candle you need to calculate your desired exit prices for TP and SL and use LIMIT and STOP orders. Your code cannot know what your average entry price is until the close of the following candle which might lead to some issues however. You need to send these STOP and LIMIT orders every candle as they only last for one candle before being cancelled.
Example for long positions:
12345tp = positionprice + extrapipssl = positionprice - extrapipssell at tp limitsell at sl stop12/28/2019 at 5:47 PM #115533thanks. this should work?
123456789101112131415IF not daysForbiddenEntry and MAXSHARES and onmarket = 0 thenif diff1 > gransvarde1 and n1 and n2 and c1 and c2 and c3 and c4 and onmarket = 0 thenBUY 1 SHARES AT MARKETENDIFENDIFif MAXSHARES and countofposition = 1 and positionprice - close > 20 thenbuy 2 shares at marketendifextrapips=5IF LONGONMARKET AND countoflongshares=>3 AND close>(positionprice+extrapips*pipsize) THENSELL AT MARKETendif12/28/2019 at 8:06 PM #11553712/28/2019 at 8:38 PM #115538Okey, well i dont have a tp only trailing. But when i use ur code to close it dont work at all, maybe u can help me. I use this;
123456789101112131415161718192021222324252627282930313233343536//trailing stop functiontrailingstart = 14trailingstep = 5//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//next movesIF newSL>0 AND newSL-close>=trailingstep*pipsize THENnewSL = newSL-trailingstep*pipsizeENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIFextrapips1 = 20tp = positionprice + extrapips1sell at tp limit12/29/2019 at 12:13 AM #115552How you have coded it will not work in the candle that the position is opened on as there is no value for POSITIONPRICE when the decision to enter is made and if you add to a position then the new value for POSITIONPRICE is not known until the next candle is closed. To overcome this you have to assume that the open of the next candle is the same as the close of the candle where the decision to buy is made and place a pending limit order at the same time as you enter based on this value. Then use the actual POSITIONPRICE once it is known at the close of a candle when you are actually on the market and not looking to buy again.
Something like this (not tested):
1234567891011121314if longonmarket thensell at positionprice + 20 limitendifif (your long conditions) thenbuy 1 contract at marketif longonmarket thensell at (((positionprice*countofposition) + close)/(countofposition+1)) + 20 limitelseif not longonmarketsell at close + 20 limitendifendifendif -
AuthorPosts
Find exclusive trading pro-tools on