[BOUNTY] Adaptive ATR-ADX Trend
#6
(03-01-2018, 10:50 AM)Gryphon Wrote: I realise there is no bounty here, but the strategy looked interesting so I gave it a shot. I wasn't sure if i should post it here or in Strat Dev.

The strategy in the link looks excellent - unfortunately I've not been able to get behaviour anywhere close!

Logically I think my code is correct, but a fresh pair of eyes on it would be very welcome... I'm running a genetic algorithm on the parameters to see if I can get some parameters that do more than marginally beat the market. On the plus side, it does seem to give decent sharpe ratios. I think the next step is writing out price and stop to a csv and plotting it to get a better idea of what is going on.

EDIT: Done some plotting, it's behaving as desired, although with a slightly big spike in the stop at each trade. Looks like it's a case of tuning the parameters properly: 

I've made some changes to the behaviour of the described strategy which have improved it in my testing:

Original strategy used the max high and min low of the last X candles as a base value for the stop. I have changed this to use the average highs and lows, and also reset this to the high or low of the current candle each time a trade is made. This makes it slightly more resilient to the more wild fluctuations, and means it ignores highs or lows that happened before the current trade, which improved performance considerably.

I have also separated the high and low ATR multipliers for Bull and Bear markets to give more flexibility in tuning.

Using Heiken Ashi candles also seemed to help.

NPM Requirements: lodash (npm i --save lodash)

ATR_ADX.toml - values are as recommended in OP's link, don't work very well for me thoug

Hi and thanks very much for your work on this, it's a pretty good strategy as is. I'm neither a javascript nor a pine expert but I've been going through the code and how the stop works and I may have found something of use. Are you still looking into this?

The stop movements that I see on a TradingView chart that I don't see in your code occurs when the +DI drops below 30 in a long. In this situation the stop is increased in value (decreased in a short) by an adaptive amount that I haven't figured out how to clearly calculate... yet. This obviously brings the stop closer to the current price as a trend is running out of steam.

The code to bring the stop closer is calculating a normalised adx that has a slightly different value to the regular ADX. I plotted the graph and in the areas I checked it was +2-5, for example, if regular ADX was 15, this other adx was 20 or 17. I went through the pine code where he normalised the data to achieve this adaptive stop and I changed some of the variable names to make them a bit more descriptive. These are lines 64-77 from the original script 

Code:
highChange = currentHigh - prevHigh;
lowChange = -(currentLow - prevLow);

if (highChange > lowChange) {
dmPos = max(highChange, 0);
}
else {
dmPos = 0;
}
if (lowChange > highChange) {
dmNeg = max(lowChange, 0);
}
else {
dmNeg = 0;
}


trueRange = (prevTR - prevTR/adxLen + currentTR;
DMPos = prevDMPos - prevDMPos/adxLen + currentDMPos;
DMNeg = prevDMNeg - prevDMNeg/adxLen + currentDMNeg;

DiPos = DMPos/trueRange * 100;
DiNeg = DMNeg/trueRange  * 100;
DX = abs(DiPos - DiNeg) / (DiPos + DiNeg) * 100;
adx = sma(DX, adxLen);

It looks like he is normalising the values by dividing the previous periods values of (TR/+DMI/-DMI) by ADX length, then dividing them again by the normalised true range in the final block. After that he calculates the DX using what looks like a relative change/difference formula. This gives a regularised and smoothed adx based on TR and DM.

This is not the complete part of the code that is missing but it is a start. I may have overlooked something in your code as I have been focusing more on the original to get to grips with that first. Please let me know if I have missed anything obvious so far. I'll continue looking at how this is used later on in the original script.
  Reply


Messages In This Thread
[BOUNTY] Adaptive ATR-ADX Trend - by briancrypto - 02-03-2018, 02:36 PM
RE: [BOUNTY] Adaptive ATR-ADX Trend - by askmike - 02-03-2018, 05:54 PM
RE: [BOUNTY] Adaptive ATR-ADX Trend - by askmike - 02-04-2018, 08:48 AM
RE: [BOUNTY] Adaptive ATR-ADX Trend - by Gryphon - 03-01-2018, 10:50 AM
RE: [BOUNTY] Adaptive ATR-ADX Trend - by hasitt - 06-08-2018, 06:26 AM

Forum Jump:


Users browsing this thread: