Adding Orders Near Take Profit/Short Sell Near Stop Loss
Forums › ProRealTime English forum › ProOrder support › Adding Orders Near Take Profit/Short Sell Near Stop Loss
- This topic has 3 replies, 3 voices, and was last updated 3 years ago by Vonasi.
-
-
06/03/2020 at 12:07 AM #134309
Hi I’d like to add Orders Near Take Profit/Short Sell Near Stop Loss levels.
So far I have this which is to initiate another trade when the price reaches 90% of it’s take profit level. How would I make this so the new order has a different stop loss/take profit level to the orders in the rest of the code?
So I want a separate stop loss, trailing step and take profit just this part of the code below. How do I do that?
The Code So Far12345678//within reach of the take profitIF Close-TRADEPRICE(1)>(TKPROFIT*0.9) AND CountOfPosition < 3 AND LONGONMARKET THENBUY 1 PERPOINT AT MARKETENDIFIF TRADEPRICE(1)-Close>(TKPROFIT*0.9) AND CountOfPosition < 3 AND SHORTONMARKET THENSELLSHORT 1 PERPOINT AT MARKETENDIFHere is the whole thing
Whole Thing1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980DEFPARAM CumulateOrders = True // Cumulating positions deactivatedATR = AverageTrueRange[186]//take profitSET TARGET pPROFIT TKPROFITIF NOT ONMARKET AND (PositionPerf(1) + PositionPerf(2) + PositionPerf(3) + PositionPerf(4)) < -100 OR STRATEGYPROFIT < -100 THENQUITENDIF//trailing stop function (make equal to absolute value when trailing stop and absolute value)IF CountOfPosition < 2 AND ONMARKET AND PositionPerf(1) > 0 THEN//trailing will start @trailinstart points profitTRSTART = (ATR*0.50)*40//trailing step to move the "stoploss"TRSTEP = (ATR*0.50)*4// Target profit = S*TTKPROFIT = (ATR*0.50)*16ENDIFIF CountOfPosition < 2 AND ONMARKET AND PositionPerf(1) <= 0 THEN//trailing will start @trailinstart points profitTRSTART = (ATR*0.25)*40//trailing step to move the "stoploss"TRSTEP = (ATR*0.25)*4// Target profit = S*TTKPROFIT = (ATR*0.25)*16ENDIF//reset the stoploss valueIF NOT ONMARKET THENSPLOSS = 0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF SPLOSS = 0 AND close-TradePrice(1)>=TRSTART THENSPLOSS = TradePrice(1)+TRSTEPENDIF//next movesIF SPLOSS > 0 AND close-SPLOSS>TRSTEP THENSPLOSS = SPLOSS+TRSTEPENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF SPLOSS = 0 AND TradePrice(1)-close>=TRSTART THENSPLOSS = TradePrice(1)-TRSTEPENDIF//next movesIF SPLOSS> 0 AND SPLOSS-close>TRSTEP THENSPLOSS = SPLOSS-TRSTEPENDIFENDIF//stop order to exit the positionsIF SPLOSS > 0 THENSELL AT SPLOSS STOPEXITSHORT AT SPLOSS STOPENDIF//put the first stoplossIF ONMARKET AND SPLOSS = 0 THENSET STOP pTRAILING TRSTARTENDIF//within reach of the take profitIF Close-TRADEPRICE(1)>(TKPROFIT*0.9) AND CountOfPosition < 3 AND LONGONMARKET THENBUY 1 PERPOINT AT MARKETENDIFIF TRADEPRICE(1)-Close>(TKPROFIT*0.9) AND CountOfPosition < 3 AND SHORTONMARKET THENSELLSHORT 1 PERPOINT AT MARKETENDIF06/03/2020 at 7:42 AM #134321So I want a separate stop loss, trailing step and take profit just this part of the code below. How do I do that?
That would mean a partial exit and we can’t do that currently in PRT due to IG not allowing us.
06/04/2020 at 11:04 PM #134607Hi Thanks. So just to make sure we are on the same page just wanted to clarify what I was asking and even if we are then I wanted to ask you the part at the end anyway.
So basically I got the idea from the article at this link https://www.prorealcode.com/documentation/tradeprice/ Here he adds a second order in the same direction as the the first trade when the first trade goes 10 points in his favour.
So I’m saying can I substitute out 10 point in my favour as a command and substitute in if the price reaches 90% of my take profit number?
So that’s the first part. Then I was saying if you can then can you set a different take profit level for the second order like for example when they are both buys.
Then even if you can’t set a different take profit level, stop loss etc, and even if I had to do it his way and order a second trade once it goes ten points in my favour, would the second trade automatically have the same take profit level of e.g. 16 combined or would they both have to hit 16 each. So 32 in total?
Basically This1234567891011121314151617181920myMACD = MACD[12,26,9](close)long = myMACD crosses over 0exit = myMACD crosses under 0//first orderIF NOT LongOnMarket AND long THENBUY 1 CONTRACTS AT MARKETENDIFIf LongOnMarket AND exit THENSELL AT MARKETENDIF//let's add another order while price continue to get higher (more than 10 points) than the last order taken with a condition of 5 bars elapsed since thenIF BARINDEX-TRADEINDEX(1)>5 AND Close-TRADEPRICE(1)>10 AND LongOnMarket THENBUY 1 CONTRACTS AT MARKETENDIF//trailing stop for the whole ordersSET STOP %TRAILING 1.506/05/2020 at 8:10 AM #134638Topic moved to the correct forum.
@tradetrader101 – read the rules before posting in the forums again to ensure that you post your topics in the correct place.
-
AuthorPosts
Find exclusive trading pro-tools on