Hi,
this is my very first blog post ever so please be kind. I have no experience in programming but i am really keen to try and learn. i would like to and develop some auto trading systems. due to my lack of experience i am having trouble understanding
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Conditions to enter long positions
indicator1 = Average[10](close)
c1 = (close > indicator1)
IF c1 THEN
BUY 1 CONTRACT AT MARKET
ENDIF
// Conditions to exit long positions
indicator2 = Average[10](close)
c2 = (close < indicator2)
IF c2 THEN
SELL AT MARKET
ENDIF
// Conditions to enter short positions
indicator3 = Average[10](close)
c3 = (close < indicator3)
IF c3 THEN
SELLSHORT 1 CONTRACT AT MARKET
ENDIF
// Conditions to exit short positions
indicator4 = Average[10](close)
c4 = (close > indicator4)
IF c4 THEN
EXITSHORT AT MARKET
ENDIF
// Stops and targets
SET STOP ploss 20 pTRAILING 10
the use of combined stops. i would like to use an initial stop loss, then trail as the trade is in profit.
for example – if i have ” SET STOP ploss 20 pTRAILING 10. does that mean a hard stop of 20 is in place until the trade moves in my favour? once in profit the trail stop is activated and is closer to price so the 10p trail stop is in place. i have added the code as per the instruction but like i said, i am mainly interested in how the stop loss section reads.
many thanks,
Lee
Line 37 is not allowed, you can’t combine two different kind of SL’s.
Use
SET STOP ploss 20
then use Nicolas’code at https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/
(lines 17-56) as a trailing stop.
you can’t combine two different kind of SL’s.
Several of the Guidance Notes (one example below) in the link below need deleting then @Nicolas?
In the meantime I will delete the Log to the link below in the Snippet Library to save confusion.
|
|
SET STOP pLOSS x pTRAILING y
|
A stop loss is placed at x points from average position price and it becomes a trailing stop of y points if the trailing stop level becomes closer to current price than the stop loss level (this occurs price varies favourably by
y points – x points).
This kind of instruction doesn’t work in real trading because IG doesn’t allow it. It doesn’t mean that it will not be compatible with the automated trading function that will come for Interactive Broker accounts.
Thanks so much guys. This has really cleared it up for me.
cheers,
Lee