Hi Roberto,
with my poor knownledge of program, I added short entry but It doesn’t work as I want; First of all for some reason it opens positions even if close of price is under EXP100, and it doesn’t open short position at all. I don’t know what I’m doing wrong. I summarize what I’d like to obtain:
Long if close of price up EXP100 or Short close under EXP100,in alternative a condition to enter long only if there is a higher low or at least a low higher than one of the two previous lows (better if I can set the percentage of variation to determine highs and lows, in order to avoid small fluctuation).
An additional condition something similar to ” stopping volume”, so for example looking at the previous 20 candles, determine the most bearish climax candles and to set a condition only if the last climax bearish candle have a ratio volume/body greater than the previous climax bearish candle.
more difficult is to determine exit strategy. actually it’s not good, it’s would be great if it could set a partial 50% take profit when the price cross over (not at close) the upper band and the rest when it closes under the band, the opposite for short. I’d like to add also a moving stop loss in a defined percentage under the last higher low.
Thank you very much for everything
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
EXP1 = ExponentialAverage[1](close)
up = PRTBANDSUP
dn = PRTBANDSDOWN
if close crosses over up and trend<=0 then
trend=1
elsif close crosses under dn and trend>=0 then
trend=-1
ENDIF
c1 = (EXP1 CROSSES OVER up )
EXP50 = ExponentialAverage[50](close)
EXP100 = ExponentialAverage[100](close)
c2 = close >= exp100
c3 = trend<>trend[1]
// Conditions to enter long positions
IF NOT SHORTONMARKET AND c1 and c2 and c3 then
BUY 10 SHARES AT MARKET
ENDIF
// Conditions to exit long positions
c4 = (EXP1 CROSSES UNDER dn )
IF c3 and c4 THEN
SELL AT MARKET
ENDIF
// Conditions to enter short positions
c4 = (EXP1 CROSSES UNDER dn )
c5 = close <= exp100
IF NOT LONGONMARKET AND c4 and c5 then
SELL 10 SHARES AT MARKET
ENDIF
// Conditions to exit short positions
IF c1 and c3 THEN
BUY AT MARKET
ENDIF
// Stops and targets
SET STOP pLOSS 4