Attached shows where colours for trading icons are set
This is your working code:
Are you using the Roberto provided code? Also, are you incorporating Roberto suggestion re MyMACD etc.
Roberto will help I’m sure. Asking 1 or 2 specific questions / problems at a time is best.
Got that… thank you…
Yes, using Roberto’s code and the my* code handling, which is now amended… well, it is working better, but not resolved as per the entry and exit logic…
Trade entry logic (as a test)
——————————–
Long: DM+ cross over DM-
Short: DM- cross over DM+
Trade Exit Logic
——————–
1. stop loss hit (OR)
2. opposite signal triggered. Where the open trade is closed and the opposite signal trade is entered.
Here is the revised code, any assistance to rectify the process is very much appreciated.
// ========================================================================
// STRATEGY: DMI-ADX Crossover with Stop Loss + Opposite Signal Exit + Delayed Re-entry
// ========================================================================
// === INPUTS ===
DMIperiod = DMIPeriod // optimize from 1 to 20
ATRperiod = 14
ATRmultiplier = 2.5
PositionSize = 10
// === INDICATORS ===
myDIplus = DIPLUS[DMIperiod]
myDIminus = DIMINUS[DMIperiod]
ATR = ATR[ATRperiod]
// === SIGNALS ===
LongSignal = myDIplus CROSSES OVER myDIminus
ShortSignal = myDIminus CROSSES OVER myDIplus
// === STOP LOSS DISTANCE ===
StopLossDistance = ATR * ATRmultiplier
// === STATE FLAGS ===
reverseToLong = 0
reverseToShort = 0
// === POSITION MANAGEMENT ===
IF LongOnMarket THEN
// 1. Check stop loss
IF low <= (tradeprice(1) – StopLossDistance) THEN
SELL AT MARKET
// 2. Check for reversal
ELSIF ShortSignal THEN
SELL AT MARKET
reverseToShort = 1
ENDIF
ENDIF
IF ShortOnMarket THEN
// 1. Check stop loss
IF high >= (tradeprice(1) + StopLossDistance) THEN
EXITSHORT AT MARKET
// 2. Check for reversal
ELSIF LongSignal THEN
EXITSHORT AT MARKET
reverseToLong = 1
ENDIF
ENDIF
// === ENTRY WHEN FLAT ===
IF NOT LongOnMarket AND NOT ShortOnMarket THEN
IF reverseToLong THEN
BUY PositionSize SHARES AT MARKET
reverseToLong = 0
ELSIF reverseToShort THEN
SELLSHORT PositionSize SHARES AT MARKET
reverseToShort = 0
ELSE
IF LongSignal THEN
BUY PositionSize SHARES AT MARKET
ELSIF ShortSignal THEN
SELLSHORT PositionSize SHARES AT MARKET
ENDIF
ENDIF
ENDIF
summary output…
“Date” “Type” “Price” “Qty” “Value”
“9 Jan 2020, 05:00:00” “Sell (entry)” “3,972.3” “-10” “39,723.00”
“14 Jan 2020, 05:00:00” “Buy (exit)” “4,013.8” “10” “40,138.00”
“26 Feb 2020, 05:00:00” “Sell (entry)” “4,241.9” “-10” “42,419.00”
“18 Mar 2020, 04:00:00” “Buy (exit)” “4,053.6” “10” “40,536.00”
“23 Mar 2020, 04:00:00” “Sell (entry)” “3,451.0” “-10” “34,510.00”
“31 Mar 2020, 05:00:00” “Buy (exit)” “3,843.0” “10” “38,430.00”
“2 Apr 2020, 05:00:00” “Sell (entry)” “3,522.3” “-10” “35,223.00”
“7 Apr 2020, 05:00:00” “Buy (exit)” “3,839.0” “10” “38,390.00”
“9 Apr 2020, 05:00:00” “Sell (entry)” “3,838.1” “-10” “38,381.00”
“13 Apr 2020, 05:00:00” “Buy (exit)” “4,000.4” “10” “40,004.00”
“16 Apr 2020, 05:00:00” “Sell (entry)” “3,635.8” “-10” “36,358.00”
“21 May 2020, 05:00:00” “Buy (exit)” “3,359.1” “10” “33,591.00”
“26 May 2020, 05:00:00” “Sell (entry)” “3,351.1” “-10” “33,511.00”
“27 May 2020, 05:00:00” “Buy (exit)” “3,441.2” “10” “34,412.00”
“12 Jun 2020, 05:00:00” “Sell (entry)” “3,283.2” “-10” “32,832.00”
“6 Jul 2020, 05:00:00” “Buy (exit)” “3,204.3” “10” “32,043.00”