Have you tested the code editor?
1 replies
eastpeace
9 years ago #116753
Have you tried to write you own indicator in Sq4 alpha4?
I found it’s very tough without API docs.
Is there api docs? Or it would be published when beta released? @ Mark Fric
AND I Suggest that sq should set the build-in indicators read only, or have some a button to “back to origin “. When I open 2 or more indicators, some indicators display nothing , and compiling would modify the original codes. (Stoch is overwrited by BB)
At last, would somebody help to make the AMA work?
Thank you in advance.
/**
*
*/
/*
* Copyright (c) 2016, StrategyQuant - All rights reserved.
*
* Code in this file was made in a good faith that it is correct and does what it should.
* If you found a bug in this code OR you have an improvement suggestion OR you want to include
* your own code snippet into our standard library please contact us at:
* http://tasks.strategyquant.com/projects/snippets/
*
* This code can be used only within StrategyQuant products.
* Every owner of valid (free, trial or commercial) license of any StrategyQuant product
* is allowed to freely use, copy, modify or make derivative work of this code without limitations,
* to be used in all StrategyQuant products and share his/her modifications or derivative work
* with the StrategyQuant community.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
package SQ.Blocks.Values.Indicators;
import SQ.Internal.IndicatorBlock;
import com.strategyquant.lib.blocks.ReturnTypes;
import com.strategyquant.lib.blocks.annotations.Buffer;
import com.strategyquant.lib.blocks.annotations.BuildingBlock;
import com.strategyquant.lib.blocks.annotations.Output;
import com.strategyquant.lib.blocks.annotations.Parameter;
import com.strategyquant.lib.data.series.DataSeries;
import com.strategyquant.lib.exception.TradingException;
import com.strategyquant.lib.indicator.Colors;
/**
* @author eastpeace
*
*/
@BuildingBlock(name="(AMA) Adapt Moving Average", display="AMA(#Period#, #FastP#,#SlowP#).[#Shift#]", returnType = ReturnTypes.Price)
public class AMA extends IndicatorBlock {
@Parameter
public DataSeries Input;
@Parameter(minValue=1, maxValue=10000, defaultValue="10", step=1)
public int Period;
@Parameter(minValue=1, maxValue=1000, defaultValue="2", step=1)
public int FastP;
@Parameter(minValue=1, maxValue=1000, defaultValue="30", step=1)
public int SlowP;
@Output(name="AMA", color=Colors.Green)
public DataSeries KAMA;
@Buffer
public DataSeries ER, Smooth;
//------------------------------------------------------------------------
//------------------------------------------------------------------------
//------------------------------------------------------------------------
@Override
public double OnBlockEvaluate(int relativeShift) throws TradingException {
return Indicators.AMA(Input, Period, FastP, SlowP).KAMA.get(relativeShift + Shift);
}
//------------------------------------------------------------------------
@Override
protected void OnBarUpdate() throws TradingException {
if (CurrentBar < Period){
KAMA.set(0, Input.get(0));
}
else{
ER.set(0,Math.Sum(Functions.Abs(Input.get(0)-Input.get(1)),Period)/Functions.Abs(Input.get(0)-Input.get(Period)));
Smooth.set(0,Math.Power(ER.get(0) * (2/(FastP+1) - 2/(SlowP+1)) + 2/(FastP+1),2));
KAMA.set(0,KAMA.get(1) + Smooth.get(0)*(Input.get(0) - KAMA.get(1)));
}
}
}
0
Tomas Matejka
9 years ago #142913
Hello,
the documentation will be available after the final version is ready. We could add a feature for restoring the default code. I will let Mark know about this idea.
0
Viewing 1 replies (of 1 total)