ScrewTurn

Active Trader Strategies API Community ChartStyles Community Commissions Community Components Community Indicators Community Providers Community Visualizers Knowledge Base Misc Optimizers PosSizers Standard Indicators TASC Traders Tips TASCIndicators Tutorial Videos
RSS

Navigation







Quick Search
»
Advanced Search »

PoweredBy
Note: The code makes use of the Pinnacle Data's symbol naming conventions.


using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;

namespace WealthLab.Strategies { public class Adaptive_COT_Index : WealthScript { protected override void Execute() { WealthLab.LineStyle solid = WealthLab.LineStyle.Solid; WealthLab.LineStyle dashed = WealthLab.LineStyle.Dashed; WealthLab.Indicators.EMACalculation modern = WealthLab.Indicators.EMACalculation.Modern; /* To be used with Pinnacle data only. Works only with Daily timeframe. The Pinnacle COT data fields contain:

Open|High Commercial Long|Short Contacts Low|Close Non Commercial Long|Short Contracts Volume|Open_Interest Small Trader Long|Short Contracts */


if( Bars.Scale != BarScale.Daily ) return; try { Bars cotIdxSym = GetExternalSymbol( "ES_NCOTI", true ); // COT Index, Non commercials

Font font = new Font( "Impact", 12, FontStyle.Regular ); ChartPane idxPane = CreatePane( 30, false, false ); DrawHorzLine( idxPane, 10, Color.Blue, dashed, 2 ); DrawHorzLine( idxPane, 90, Color.Red, dashed, 2 );

DataSeries LargeSpeculatorsCOTIndex = ( cotIdxSym.Close ); DataSeries upper = BBandUpper.Series( LargeSpeculatorsCOTIndex, 100, 2.0 ); DataSeries lower = BBandLower.Series( LargeSpeculatorsCOTIndex, 100, 2.0 ); DataSeries ema13 = EMA.Series( Close, 13, modern ); ema13.Description = "EMA(13)"; LargeSpeculatorsCOTIndex.Description = "COT Index (NonCommercials)"; upper.Description = "Adaptive COT Index (Upper)"; lower.Description = "Adaptive COT Index (Lower)";

PlotSeries( idxPane, LargeSpeculatorsCOTIndex, Color.DarkBlue, solid, 2 ); PlotSeries( idxPane, upper, Color.FromArgb(0, 128, 128), solid, 2 ); PlotSeries( idxPane, lower, Color.FromArgb(0, 128, 128), solid, 2 ); PlotSeries( PricePane, ema13, Color.Red, dashed, 2 ); HideVolume(); for(int bar = 300; bar < Bars.Count; bar++) { if( IsLastPositionActive ) { Position p = LastPosition; double stop = ( p.PositionType == PositionType.Long ) ? p.EntryPrice*0.90 : p.EntryPrice*1.10;

if( p.PositionType == PositionType.Long ) { if( LargeSpeculatorsCOTIndex[bar] <= lower[bar] ) { SetBackgroundColor( bar, Color.FromArgb(231, 255, 231) ); if( SellAtMarket( bar+1, p, "Lower limit reached" ) ) AnnotateBar( "Sell", bar, false, Color.Red, Color.Empty, font ); } else if( SellAtStop( bar+1, p, stop, "Stop Loss" ) ) AnnotateBar( "Sell", bar, false, Color.Red, Color.Empty, font );

} else { if( LargeSpeculatorsCOTIndex[bar] >= upper[bar] ) { SetBackgroundColor( bar, Color.FromArgb(255, 227, 231) ); if( CoverAtMarket( bar+1, p, "Opposite signal" ) ) AnnotateBar( "Cover", bar, true, Color.DarkGreen, Color.Empty, font ); } else if( CoverAtStop( bar+1, p, stop, "Stop Loss" ) ) AnnotateBar( "Cover", bar, true, Color.DarkGreen, Color.Empty, font ); } } else { if( LargeSpeculatorsCOTIndex[bar] <= lower[bar] ) { SetBackgroundColor( bar, Color.FromArgb(231, 255, 231) ); if( Close[bar] < ema13[bar] ) if( ShortAtMarket( bar+1, "Lower limit reached" ) != null ) { LastActivePosition.Priority = Momentum.Value( bar, Close, 13 ); AnnotateBar( "Short", bar, true, Color.Brown, Color.Empty, font ); } } else if( LargeSpeculatorsCOTIndex[bar] >= upper[bar] ) { SetBackgroundColor( bar, Color.FromArgb(255, 227, 231) ); if( Close[bar] > ema13[bar] ) if( BuyAtMarket( bar+1, "Upper limit reached" ) != null ) { LastActivePosition.Priority = Momentum.Value( bar, Close, 13 ); AnnotateBar( "Buy", bar, false, Color.Blue, Color.Empty, font ); } } } } } catch { DrawLabel( PricePane, "No supporting data for ES_NCOTI", Color.Red ); } } } }

Important Disclaimer: The information provided by Wealth-Lab is strictly for informational purposes and is not to be construed as advice or solicitation to buy or sell any security.  The owner of Wealth-Lab.com assumes no liability resulting from the use of the material contained herein for investment purposes.

Used under license from FMR Corp. Copyright 2008 FMR Corp. All rights reserved.


ScrewTurn Wiki version 3.0.2.509. Some of the icons created by FamFamFam.