At the request of Adrian and JMWilk, I tried to predict extreme volatility using the crossing of daily ranges over its 5-day EMA. You can see very sharp spikes after the crossover on the Volatility Chart.
Another interesting finding: limiting trades to high volatile days improves the performance of longs but hurts the profitability of shorts.
Fade Extreme Price Actions v1 limits longs to days with predicted high volatility in ^GSPC. All other components stay the unchanged. Your comments and suggestions are welcome for future improvements.
Another interesting finding: limiting trades to high volatile days improves the performance of longs but hurts the profitability of shorts.
Fade Extreme Price Actions v1 limits longs to days with predicted high volatility in ^GSPC. All other components stay the unchanged. Your comments and suggestions are welcome for future improvements.
Try understand
void run()
{
installTimeBasedExit(5);
installProfitTarget( 5 );
Bars sp5 = bars( "^GSPC" );
if( !sp5 )
exit("Can't load data for ref symbol, exiting");
synchronize( sp5 );
Series rangeSeries = sp5.highSeries() - sp5.lowSeries();
Series smaRange = rangeSeries.EMA(5);
Series frROCP = smaRange.ROCP(1);
Series smaFRROCP = frROCP.SMA(5);
Pane defPane = getDefaultPane();
Pane pane1 = createPane("Volatility Chart", LIGHTBLUE);
pane1.drawSeries("Range EMA", smaRange, MAGENTA);
pane1.drawSeries("Daily Range", rangeSeries, BLACK);
for( Index bar = 0; bar <> 0
AND rangeSeries[bar]>smaRange[bar]
AND !hasOpenPositions() )
{
buyAtLimit( bar + 1, 0.9*low(bar), 1000, "" );
}
shortAtLimit( bar + 1, 1.1*high(bar), 1000, "" );
}
}
Try implement it in Java with TA-lib Java version. I know my code is ugly, just a quick hack.
import com.tictactec.ta.lib.*;
/*
* Fade Extreme Price Actions v1
* From http://www.tradery.com
*/
public class FEPAv1 {
private static int DEFAULT_ARRAY_SIZE = 50;
private static int DEFAULT_STATIC_SIZE = 20;
private int _range = 5;
private int _inputsize = 0;
private double _rangeSeries[];
private double _smaRange[];
private double _frROCP[];
private double _smaFRROCP[];
private int _size;
private Core lib;
private RetCode retCode;
private MInteger outBegIdx;
private MInteger outNbElement;
public FEPAv1 (double[] sp5, int size) {
_inputsize = size;
_rangeSeries = new double [DEFAULT_ARRAY_SIZE];
_frROCP = new double [DEFAULT_ARRAY_SIZE];
if (size > DEFAULT_ARRAY_SIZE)
return ;
_size = size;
for (int i=0;i<_size;i++)
_rangeSeries[i]=sp5[i];
lib = new Core();
_smaRange = new double [DEFAULT_ARRAY_SIZE];
_smaFRROCP = new double [DEFAULT_ARRAY_SIZE];
outBegIdx = new MInteger();
outNbElement = new MInteger();
for (int i=0; i<=DEFAULT_STATIC_SIZE;i++)
System.out.println( "_rangeSeries "+i+"="+_rangeSeries[i]);
retCode = lib.ema(0,size -1,_rangeSeries,_range,outBegIdx,outNbElement,_smaRange);
for (int i=0; i<=DEFAULT_STATIC_SIZE;i++)
System.out.println( "_smaRange "+i+"="+_smaRange[i]);
retCode = lib.rocP(0,size - _range, _smaRange,1,outBegIdx, outNbElement, _frROCP);
for (int i=0; i<=DEFAULT_STATIC_SIZE;i++)
System.out.println( "_frROCP "+i+"="+_frROCP[i]);
retCode = lib.sma(0,size - _range -1, _frROCP, _range, outBegIdx, outNbElement, _smaFRROCP);
for (int i=0; i<=DEFAULT_STATIC_SIZE;i++)
System.out.println( "_smaFRROCP "+i+"="+_smaFRROCP[i]);
}
public int ShouldBuy() {
System.out.println("_smaFRROCP[10="+(_inputsize - _range - _range) +"]"+_smaFRROCP[_inputsize - _range - _range ]);
System.out.println("_rangeSeries[19="+(_inputsize -1)+"]"+_rangeSeries[_inputsize -1]);
System.out.println("_smaRange[15="+(_inputsize - _range)+"]"+_smaRange[_inputsize - _range ]);
if (_smaFRROCP[_inputsize - _range - _range]>0 && _rangeSeries[_inputsize -1] > _smaRange[_inputsize - _range])
{
return 1;
}
if (_smaFRROCP[_inputsize - _range - _range]<0> _smaRange[_inputsize - _range])
{
return 2;
}
return 0;
}
public double[] getSMARange(){
return _smaRange;
}
}
No comments:
Post a Comment