Aim & Shoot (Long) - Strategy Automation thru AFL Code

#1
Hi,

I am new to Amibroker and AFL. I am working to automate one strategy that I call it as Aim & Shoot

I have few doubts if this strategy can be automated fully (i.e. without any manual intervention).
This is a multi timeframe/tradeframe strategy. Pls allow me to describe the strategy.

Strategy Name - Aim & Shoot (Long)

Trade Frame (TF) e.g. Daily​
(a) Awesome Oscillator (AO) must be greater than zero​
(b) Stochastic Oscillator [%K Period = 4, %K Slow = 1, %D Period = 1, %D Type = Simple] (I have named it as Aim) < 20​
(c) Stochastic Oscillator [%K Period = 4, %K Slow = 3, %D Period = 2, %D Type = Simple ] (I have named it as Shoot) => Should have positive crossover (i.e. %K must be cutting the %D from below)​
(d) There must be a Positive Hidden Divergence (PHD) between Price and RSI-14 (14 period RSI) during the time whne Aim and Shoot happened. Positive Hidden Divergence is when Price is making Higher Lows while the RSI-14 makes the Lower Lows
.
One Level Higher Trade Frame (TF+1) e.g. Weekly​
(e) Awesome Oscillator must be rising (atleast 3 bars on the AO histogram)​

An example of Aim & Shoot (Long) is attached here from Titan Industries. There can be a time lag between Aim and Shoot, meaning that Aim and shoot may or may not happen on the same candle.

Here is the sample code that I am currently working on -
_SECTION_BEGIN("Aim & Shoot - Long using Multi Timeframe");

// Start with Daily Time Frame
TimeFrameSet(inDaily);

ShortEMA = Param("Short EMA",13);
LongEMA = Param("Long EMA",34);
AO = EMA((H+L)/2,ShortEMA)-EMA((H+L)/2,LongEMA);
Aim = StochK(4,1); //Aim
Lean = StochK(4,3) - StochD(4,3,2);

_TRACE("AO is >>>>"+AO);


// switch to weekly time frame.
TimeFrameSet( inWeekly );
AOWeekly = EMA((H+L)/2,ShortEMA)-EMA((H+L)/2,LongEMA);

AORisingInHigherTF = AOWeekly > Ref(AOWeekly, -1) > Ref(AOWeekly, -2);

/* Restore the time frame*/
TimeFrameRestore();


// I am having challenge calculating the positive hidden divergence (PHD) between price and RSI-14 during the time when Aim and Shoot happened thru AFL Code.

_SECTION_END();


My main doubt is -
- Can this strategy (I described above) be automated fully thru AFL Code (including the hidden divergence calculations)? My objective here is to have it scan set of stocks and tell me which all scripts are currently forming or have formed Aim & Shoot (Long) and accordingly the algo should be able to place the order with proper stoploss and targets.

Can anyone pls help/provide some directions to me ??

Thanks much in advance
 

Attachments

#2
Hi,

I am new to Amibroker and AFL. I am working to automate one strategy that I call it as Aim & Shoot

I have few doubts if this strategy can be automated fully (i.e. without any manual intervention).
This is a multi timeframe/tradeframe strategy. Pls allow me to describe the strategy.

Strategy Name - Aim & Shoot (Long)

Trade Frame (TF) e.g. Daily​
(a) Awesome Oscillator (AO) must be greater than zero​
(b) Stochastic Oscillator [%K Period = 4, %K Slow = 1, %D Period = 1, %D Type = Simple] (I have named it as Aim) < 20​
(c) Stochastic Oscillator [%K Period = 4, %K Slow = 3, %D Period = 2, %D Type = Simple ] (I have named it as Shoot) => Should have positive crossover (i.e. %K must be cutting the %D from below)​
(d) There must be a Positive Hidden Divergence (PHD) between Price and RSI-14 (14 period RSI) during the time whne Aim and Shoot happened. Positive Hidden Divergence is when Price is making Higher Lows while the RSI-14 makes the Lower Lows
.
One Level Higher Trade Frame (TF+1) e.g. Weekly​
(e) Awesome Oscillator must be rising (atleast 3 bars on the AO histogram)​

An example of Aim & Shoot (Long) is attached here from Titan Industries. There can be a time lag between Aim and Shoot, meaning that Aim and shoot may or may not happen on the same candle.

Here is the sample code that I am currently working on -
_SECTION_BEGIN("Aim & Shoot - Long using Multi Timeframe");

// Start with Daily Time Frame
TimeFrameSet(inDaily);

ShortEMA = Param("Short EMA",13);
LongEMA = Param("Long EMA",34);
AO = EMA((H+L)/2,ShortEMA)-EMA((H+L)/2,LongEMA);
Aim = StochK(4,1); //Aim
Lean = StochK(4,3) - StochD(4,3,2);

_TRACE("AO is >>>>"+AO);


// switch to weekly time frame.
TimeFrameSet( inWeekly );
AOWeekly = EMA((H+L)/2,ShortEMA)-EMA((H+L)/2,LongEMA);

AORisingInHigherTF = AOWeekly > Ref(AOWeekly, -1) > Ref(AOWeekly, -2);

/* Restore the time frame*/
TimeFrameRestore();


// I am having challenge calculating the positive hidden divergence (PHD) between price and RSI-14 during the time when Aim and Shoot happened thru AFL Code.

_SECTION_END();


My main doubt is -
- Can this strategy (I described above) be automated fully thru AFL Code (including the hidden divergence calculations)? My objective here is to have it scan set of stocks and tell me which all scripts are currently forming or have formed Aim & Shoot (Long) and accordingly the algo should be able to place the order with proper stoploss and targets.

Can anyone pls help/provide some directions to me ??

Thanks much in advance
Divergence calculations may be difficult

One way out is to calculate LinRegSlope on the chart and the indicator and subtract the two to measure divergence. But again this won’t be fool proof


Sent from my iPhone using Tapatalk
 

Similar threads