PerParticipant
Average
Intro to the strategies which is based on my view of a Daily trend break out:
- The Close is > DonchianUp (40 day )
- Volume > 1,5 Volume[20]
- Buy on the next day open.
The strategy criteria is:
- Duration – 4-5 monts
- Ref. index – SPY, which shall be BULL ie. MA 65D > 195D
- The instrument, shall be BULL i.e. MA 40D > 120D
The target is based on a ATR based trailing stop loss that is optimize by the parameter optimization function (it varies from instrument to instrument as 5-8 x ATR).
Here is the code:
REM Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
REM Basic Condition to trade
myPriceCriteria = Close > 5.00
myVolumeCriteria = (Average[20](volume) > 100000)
myMA40 = Average[40](Close)
myMA120 = Average[120](Close)
myBullCriteria = myMA40 > myMA120
c1 = myPriceCriteria and myVolumeCriteria and myBullCriteria
REM Trigger to enter long positions
// Condition 1 - DoncianUP - Break out
myDonchianUp = (highest[40](high[1]))
//myDonchianDown = LOWEST[40](LOW[1])
c2 = close >= myDonchianUp
//Condition 2 - Daily volume-breaks up > 1,5 x Volume(average) (20)
myBOVolume = Volume > 1.5*(Average[20](Volume))
c3 = myBOVolume
REM Trading target = Trailing Stop loss based on ATR
myATR = 4*averagetruerange[20]
IF C1 AND C2 AND C3 THEN
If myATR > 30 THEN
BUY ((30/myATR) * close) CASH AT MARKET
ELSIF myATR <= 30 THEN
BUY 1500 CASH AT MARKET
ELSE
ENDIF
ENDIF
SET STOP TRAILING myAtr
I ran a back-test on a NYSE stock (GOL LINHAS …) , with this outcome:

The ProOrder order part (bellow t REM Trading target = Trailing Stop loss based on ATR) is a challenge as it does not place trades.
I have been reading the manual and seen lots of support on this site, while eventually seeking an advice so to progress with the development of this back testing script.
Hoping for a positive reply.
Best regards,
Per Inge
PerParticipant
Average
I found the following money management setup, to which I will appreciate any comment to code enhancements:
REM Trading target = Trailing Stop loss based on ATR a changing ATR
myATR = averagetruerange[20]
mySL = myATR * 5
myBetSize = 1500*0.03 //3% loss, unit of $1500 = $45
myNoOStock = myBetSize/mySL //No of stocks at SL is = $45 (if ATR was fixed)
myPosSize = myNoOStock * close //No. of stocks x close
IF C1 AND C2 AND C3 THEN
If myPosSize > 1500 THEN
BUY 1500 CASH AT MARKET
ELSIF myPosSize <= 1500 THEN
BUY myPosSize CASH AT MARKET
ELSE
ENDIF
ENDIF
SET STOP TRAILING mySL
The weakness is:
- Small position at high ATR
- Fluctuation of the ATR gives an innacurate SL