hi
I’m trying to figure out how to use candles to define the initial stop as well as the exit. I have attached what I have coded so far, which runs though doesn’t quite capture what I am trying to do.
For long positions, the initial stop would be the low of the opening candle or previous candle and for short positions the stop would be the high of the opening candle or previous candle.
For long positions, the exit is a stop order below a bull candle with a body > 50% ATR and for short positions, the exit is a stop order above a bear candle with a body >50% ATR. The obvious problem is the stop order expires after the close of the following candle – is there some way to keep the stop at that level? I have done the video training on loops though am not yet experienced or smart enough to figure it out 🙂
Any tips or suggestions greatly appreciated,
cheers
Chris
// Definition of code parameters
DEFPARAM CumulateOrders = false // Cumulating positions
Position = 1
ma = triangularAverage[10](close)
myatr = factor*AverageTrueRange[period](close)
longcross = close crosses over ma
shortcross = close crosses under ma
bullcandle = close - open > myatr
bearcandle = open - close > myatr
// Conditions to enter long positions
IF longcross and bullcandle then
BUY Position CONTRACT AT high + 0.0001 stop
set stop loss low[0]
endif
// Conditions to exit long positions
if longonmarket and bullcandle then
stopsignal = low
sell at highest[5](stopsignal) -0.0001 stop
else
stopsignal = 0
endif
// Conditions to enter short positions
IF shortcross and bearcandle THEN
SELLSHORT Position CONTRACT AT low - 0.0001 stop
set stop loss high[0]
ENDIF
// Conditions to exit short positions
if shortonmarket and bearcandle then
stopsignal = high
exitshort at stopsignal +0.0001 stop
else
stopsignal =0
endif
// Stops and targets
LeoParticipant
Veteran
Hi. when the condition, make a variable than save the barindex of the crossing. Like CrossingPosition=barindex
Then make another condition for decide how many bars after crossing you still wanted tho open trades. Like: lowest[5](conditionToTrade)=1
Then set the set stoploss at low[barindex-CrossingPosition]
Keep learning! That’s the most important thing.
One suggestion, try to avoid using +-0.0001, since it is instrument dependent, use
+ 1 * pipsize //or -1 * pipsize
instead and let ProOrder do the math.
Between lines 13 and 14 insert the following
SL = low[0]
then replace line 14 with
set stop loss SL
do the same at line 28 with high[0].
This will save your SL values, they will only be overwritten when conditions at line 12 and 26 will be true again.