NexusFi: Find Your Edge


Home Menu

 





(Kaufman adaptive moving average + ROC) Strategy Transcode


Discussion in NinjaTrader

Updated
    1. trending_up 3,161 views
    2. thumb_up 0 thanks given
    3. group 2 followers
    1. forum 1 posts
    2. attach_file 0 attachments




 
Search this Thread

(Kaufman adaptive moving average + ROC) Strategy Transcode

  #1 (permalink)
 
Pharmakon's Avatar
 Pharmakon 
Paris France
 
Experience: Beginner
Platform: TradingView
Broker: CQG
Trading: ES1!, CL1!, DY1!
Posts: 45 since Jan 2016
Thanks Given: 119
Thanks Received: 27

Hi everybody !

Firstly, I'd like to give many thanks to everybody working hard to give this community a lot of value. It's very helpful to find almost one post about everything I'm looking to know about trading methodology.

I'm very new to strategy programming but I'd really like to make progress on it. I've only done the BigMike Tutorial. Thank you Big Mike. And, I've understood that I won't be able to progress alone or in a very slow way. So I come here looking to share ideas and help if I can but I don't want to flood the forum. I'm trying to give the most value to my post.

I've found a nice working strategy on TradingView website. It works very well on many securities (see pictures at the bottom of the post) with this platform trading simulator. I give the link to the strategy just to respect sourcing.

https://www.tradingview.com/script/Y49ipujG-Kama-VS-HeikinAshi-Strategy-synapticex/

It's a combination of Kaufman Adaptive Moving Average and ROC.

Source code is here (TradingView Proprietary Language) :

 
Code
//@version=2
//synapticex.com
kamaPeriod = input(8, minval=1) 
ROCLength=input(4, minval=1) 

kama(length)=>
    volatility = sum(abs(close-close[1]), length)
    change = abs(close-close[length-1])
    er = iff(volatility != 0, change/volatility, 0)
    sc = pow((er*(0.666666-0.064516))+0.064516, 2)
    k = nz(k[1])+(sc*(hl2-nz(k[1])))
    
kamaEntry = security(tickerid,period,kama(kamaPeriod))

plot(kamaEntry, color=gray, title="Kama",transp=0, trackprice=false, style=line)
roc = roc(close, ROCLength)

strategy("Kama VS HeikinAshi", overlay=true, pyramiding=0, calc_on_every_tick=true, calc_on_order_fills=true)

buyEntry =  kamaEntry[0]>kamaEntry[1] and roc[1]<0 and roc >0
sellEntry = kamaEntry[0]<kamaEntry[1] and roc[1]<0 and roc <0

buyExit = kamaEntry<kamaEntry[1] or (roc[1]>0 and roc<0)
sellExit =  kamaEntry>kamaEntry[1] or (roc[1]<0 and roc>0)

if (buyEntry)
    strategy.entry("KAMAL", strategy.long, comment="KAMAL")
else
    strategy.close("KAMAL", when=buyExit)

if (sellEntry)
    strategy.entry("KAMAS", strategy.short, comment="KAMAS")
else
    strategy.close("KAMAS", when=sellExit)

I'm trying to transcode it to NinjaTrader to be able to share it to do a small real backtest. But I'm confronted with some issues on coding it. I'm stuck ! I don't how to transcode two of these function :

- nz : Not a Number function (NaN)
- security : which returns another series of the input data given.

I've already started to code it. I hope it will help :

 
Code
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;
#endregion

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
    /// <summary>
    /// 20160428 My first money maker strategy based with SMA, EMA, HMA
    /// </summary>
    [Description("20160428 My first money maker strategy based with SMA, EMA, HMA")]
    public class MyMoneyMaker : Strategy
    {
        #region Variables
        // Wizard generated variables
        private int myInput0 = 1; // Default setting for MyInput0
        // User defined variables (add any user defined variables below)
        #endregion
		
		private int		kamaPeriod 		= 8;		//variables en minuscules
		private int		rocLength 		= 4;
		
        /// <summary>
        /// This method is used to configure the strategy and is called once before any strategy method is called.
        /// </summary>
        protected override void Initialize()
        {
            CalculateOnBarClose = true;
			EntryHandling		= EntryHandling.UniqueEntries; //Unique entry if you have multiple longs signal at same time
			
        }		
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
			EntryHandling		= EntryHandling.UniqueEntries;
			
			if (Position.MarketPosition != MarketPosition.Flat) return;
			if (CurrentBar < kamaPeriod) return;
			
			//length = kamaPeriod
			
			double 		volatility 		= 0;
			double 		change			= 0;
			double		er				= 0;
			double		sc				= 0;
			double		k				= 0;
			double		roc				= 0;
			
			for (int barsAgo = 0; barsAgo < kamaPeriod; barsAgo++)
			{
				volatility = volatility + Math.Abs(Close[barsAgo] - Close[barsAgo+1]);
			}
			
			change = Math.Abs(Close[0] - Close[kamaPeriod - 1]);
			
			if (volatility != 0)
				er = change/volatility;
			else
				er = 0;
			
			sc = Math.Pow((er*(0.666666-0.064516))+0.064516, 2);
			
			// left: 
			// security ?
			// k : NaN function ?
			// Plot ?
			
			//ROC
			
			roc = ROC(Close[0],rocLength);
			
			
			// Long/Sell entry orders
			
			
			// exit orders
			
			
			
			
		
        }

        #region Properties
        [Description("")]
        [GridCategory("Parameters")]
        public int KamaPeriod	//Fonction 1ere lettre en Majuscule ?
        {
            get { return kamaPeriod; }
            set { kamaPeriod = Math.Max(1, value); }
        }        
		[Description("")]
        [GridCategory("Parameters")]
		public int RocLength
        {
            get { return rocLength; }
            set { rocLength = Math.Max(1, value); }
        }        
        #endregion
    }
}


 
Code







Regards,
M.

Follow me on Twitter Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Trade idea based off three indicators.
Traders Hideout
Better Renko Gaps
The Elite Circle
ZombieSqueeze
Platforms and Indicators
MC PL editor upgrade
MultiCharts
REcommedations for programming help
Sierra Chart
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
48 thanks
Just another trading journal: PA, Wyckoff & Trends
33 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
24 thanks
GFIs1 1 DAX trade per day journal
22 thanks




Last Updated on April 29, 2016


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts