Is there a way to close half of the position as soon as it triggers?
Forums › ProRealTime English forum › ProOrder support › Is there a way to close half of the position as soon as it triggers?
- This topic has 2 replies, 2 voices, and was last updated 3 years ago by crolakstrading.
-
-
06/02/2020 at 12:06 AM #134126Close half a position when breakeven12345678910111213141516171819202122232425262728293031323334353637383940414243444546// --- settingsamount = 2 //amount of contract/lot/shares to open for each ordertakeprofit = 30 //takeprofit in pointsstoploss = 60 //stoploss in pointsBreakevenAt = 25 //percent achieved of target to move stop to entry (breakeven)PointsToKeep = 1 //how much pips/points to keep in profit above of below our entry price when the breakeven is activated (beware of spread)Lot2Close = 1 //amount of contract/lot/shares quantity to close when breakeven occurs// --- end of settings//reset the breakevenLevel when no trade are on marketIF NOT ONMARKET THENbreakevenLevel=0ENDIFstartBreakeven = takeprofit*(BreakevenAt/100)//how much pips/points in gain to activate the breakeven function?// --- BUY SIDE ---//test if the price have moved favourably of "startBreakeven" points alreadyIF LONGONMARKET AND close-tradeprice(1)>=startBreakeven*pipsize THEN//calculate the breakevenLevelbreakevenLevel = tradeprice(1)+PointsToKeep*pipsizeENDIF//place the new stop orders on market at breakevenLevelIF LONGONMARKET AND breakevenLevel>0 THENSELL AT breakevenLevel STOPif countoflongshares=amount thensell Lot2Close contract at marketendifENDIF// --- end of BUY SIDE ---// --- SELL SIDE ---//test if the price have moved favourably of "startBreakeven" points alreadyIF SHORTONMARKET AND tradeprice(1)-close>=startBreakeven*pipsize THEN//calculate the breakevenLevelbreakevenLevel = tradeprice(1)-PointsToKeep*pipsizeENDIF//place the new stop orders on market at breakevenLevelIF SHORTONMARKET AND breakevenLevel>0 THENEXITSHORT AT breakevenLevel STOPif countofshortshares=amount thenexitshort Lot2Close contract at marketendifENDIF// --- end of SELL SIDE ---
I have found the above coding from @nicolas which close half the position when breakeven.
I just wanted to know if there a way to close half the position as soon as it triggered or 1pips in profit?? just to reduce risk straight away!! appreciate if anyone could help.
Thanks in advanced
06/02/2020 at 8:07 AM #13414606/02/2020 at 9:31 AM #134157Thank you for your response @Nicolas. above coding shows as its working on IG Pr0Order but i haven’t tried it!
how can i make this work separately, please.. means breakeven and close half working separatelylet’s say.. 50pips stop loss, 100pips Target and once 50pips in profit stop loss to breakeven!! also when trade triggered and 2pips in profit close half of the position to reduce risk!! i have tried but really need some help.
breakeven and close half of the position seperately12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970defparam cumulateorders = false// --- settingsamount = 0.2 //amount of contract/lot/shares to open for each ordertakeprofit = 150 //takeprofit in pointsstoploss = 50 //stoploss in pointsLot2Close = 0.1 //amount of contract/lot/shares quantity to close when breakeven occurs// --- end of settings// Conditions to enter long positionsIF NOT LongOnMarket AND xxxxxx THENBUY amount CONTRACTS AT EntryPrice STOPif countoflongshares=amount thensell Lot2Close contract at marketendifENDIF// Conditions to exit long positionsIf LongOnMarket AND short THENSELL AT MARKETENDIF// Conditions to enter short positionsIF NOT ShortOnMarket AND xxxxxxx THENSELLSHORT amount CONTRACTS AT EntryPrice STOPif countofshortshares=amount thenbuy Lot2Close contract at marketENDIFENDIF// Conditions to exit short positionsIF ShortOnMarket AND long THENEXITSHORT AT MARKETENDIF// Stops and targets : Enter your protection stops and profit targets here// points based STOP LOSS and TRAILING STOP// initial STOP LOSSSET STOP pLOSS stoploss//set target of positions at 100 pointsSET TARGET PROFIT takeprofitstartBreakeven = 50 //how much pips/points in gain to activate the breakeven function?PointsToKeep = 3 //how much pips/points to keep in profit above of below our entry price when the breakeven is activated (beware of spread)// --- BUY SIDE ---//test if the price have moved favourably of "startBreakeven" points alreadyIF LONGONMARKET AND close-tradeprice(1)>=startBreakeven*pipsize THEN//calculate the breakevenLevelbreakevenLevel = tradeprice(1)+PointsToKeep*pipsizeENDIF//place the new stop orders on market at breakevenLevelIF breakevenLevel>0 THENSELL AT breakevenLevel STOPENDIF// --- end of BUY SIDE ---// --- SELL SIDE ---//test if the price have moved favourably of "startBreakeven" points alreadyIF SHORTONMARKET AND tradeprice(1)-close>startBreakeven*pipsize THEN//calculate the breakevenLevelbreakevenLevel = tradeprice(1)-PointsToKeep*pipsizeENDIF//place the new stop orders on market at breakevenLevelIF breakevenLevel>0 THENEXITSHORT AT breakevenLevel STOPENDIF// --- end of SELL SIDE --- -
AuthorPosts
Find exclusive trading pro-tools on