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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
// 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 |