Hi guys,
kind of new to this platform and to algo trading so wanted to catch some help here.
I would like to accomplish the following,
If a trade is profitable, move the stop loss to break even and open up a second order in the same direction with new stop loss and profit target
Thanks!
Code:
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Indicators
indicator1 = Stochastic[14,3](close)
indicator2 = Average[5](indicator1)
indicator3 = RSI[6](close)
// Conditions to enter long positions
c1 = (indicator1 CROSSES OVER indicator2)
c2 = (indicator3 <= 30)
IF c1 AND c2 THEN
BUY 1 CONTRACT AT MARKET
ENDIF
// Conditions to exit long positions
c3 = (indicator1 CROSSES UNDER indicator2)
IF c3 THEN
SELL AT MARKET
ENDIF
// Conditions to enter short positions
c4 = (indicator1 CROSSES UNDER indicator2)
c5 = (indicator3 >= 70)
IF c4 AND c5 THEN
SELLSHORT 1 CONTRACT AT MARKET
ENDIF
// Conditions to exit short positions
c6 = (indicator1 CROSSES OVER indicator2)
IF c6 THEN
EXITSHORT AT MARKET
ENDIF
// Stops and targets
SET STOP pLOSS 8
SET TARGET pPROFIT 15
Hi,
Didnt really go through your code but shouldnt in the first line cumulateorders=true if you want to add orders on profitable trades?
Despair is right. You can find a complete breakeven function code in this blog article: https://www.prorealcode.com/blog/learning/breakeven-code-automated-trading-strategy/
Hi guys, that’s true, Just copy/pasted my current one.
Ill give it a shoot with Nicolas link.
Thanks!