Skip to content

Instantly share code, notes, and snippets.

View DexterHaslem's full-sized avatar
💭
why are you taking advice from a site that goes down weekly?

Dexter M Haslem DexterHaslem

💭
why are you taking advice from a site that goes down weekly?
View GitHub Profile
@DexterHaslem
DexterHaslem / gist:1348944
Created November 8, 2011 19:53
debug print streaming web request
let printStreamingWebReq (url : string, postContent : string) =
let req = WebRequest.Create url :?> HttpWebRequest
req.Method <- "POST"
req.Proxy <- null
let postDataEncoded = ASCIIEncoding.ASCII.GetBytes(postContent)
let len : int64 = int64 postDataEncoded.Length
req.ContentLength <- len
let reqStream = req.GetRequestStream()
reqStream.Write(postDataEncoded, 0, postDataEncoded.Length)
use response = req.GetResponse()
open System
type bar =
{ Symbol : string; Timestamp : DateTime;
Open : string; High : string; Low : string; Close : string;
Volume: int;
}
// F.US.DGH12 20111201 0107 110020 110020 110020 110020 1
let parse_bar (line : string, delim : char) =
@DexterHaslem
DexterHaslem / gist:2648306
Created May 9, 2012 19:45
depth first search (kill ur stack)
public static IEnumerable<T> DepthFirstSearch<T>(IEnumerable<T> start, Func<T, IEnumerable<T>> selector, Func<T, bool> predicate)
{
var results = new List<T>();
foreach (T item in start)
{
if (predicate != null && predicate(item))
results.Add(item);
else if (predicate == null)
results.Add(item);
var subItems = selector(item);
public static IEnumerable<T> FlattenTree<T>(IEnumerable<T> list, Func<T, IEnumerable<T>> subitems)
{
foreach (T child in list)
{
yield return child;
foreach (T other in FlattenTree(subitems(child), subitems))
yield return other;
}
}
protected override void OnBarUpdate()
{
if (Historical) return;Enumerable.Range(0,14).ToList().ForEach(i =>DrawText((CurrentBar+i).ToString(),"\u0CA0_\u0CA0",0, i % 2 == 0 ? (Close[0]+TickSize) + (TickSize*i) : (Close[0]-TickSize)-(TickSize*i),i % 2 == 0 ? Color.FromArgb(255 - (i*15),0, 0,255):Color.FromArgb(255 - (i*15),255, 0,0)));
}
@DexterHaslem
DexterHaslem / gist:3084661
Created July 10, 2012 16:54
runtime indicator
protected override void OnBarUpdate()
{
string indicator = "EMA";
Type indicatorType = Type.GetType("NinjaTrader.Indicator." + indicator);
IndicatorBase indicatorBase = (IndicatorBase) Activator.CreateInstance(indicatorType);
Print(indicatorBase.GetHashCode() + ":" + indicatorBase.GetType().FullName);
indicatorBase.BarsRequired = BarsRequired;
indicatorBase.CalculateOnBarClose = CalculateOnBarClose;
indicatorBase.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
indicatorBase.MaximumBarsLookBack = MaximumBarsLookBack;
@DexterHaslem
DexterHaslem / gist:3085590
Created July 10, 2012 19:13
NinjaTrader create Indicator type @ runtime
using System;
using System.ComponentModel;
namespace NinjaTrader.Indicator
{
[Description("f")]
public class derp : Indicator
{
IndicatorBase myEMA;
protected override void Initialize()
:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Microsoft.VisualStudio.QualityTools.CodedUITestFramework". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
c:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Microsoft.VisualStudio.TestTools.UITest.Common". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
c:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Microsoft.VisualStudio.TestTools.UITest.Extension". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
c:\W
@DexterHaslem
DexterHaslem / gist:3249480
Created August 3, 2012 16:56
AutomationElement pinvoke right click
// add references WindowsBase, UIAutomationClient, UIAutomationTypes
// using System.Windows.Automation;
// using System.Windows;
[DllImport("user32.dll", CharSet = CharSet.Auto)] static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
public void RightClick(AutomationElement element)
{
const int WM_LBUTTONDOWN = 0x0201;
const int WM_LBUTTONUP = 0x0202;
Point point = element.GetClickablePoint();
@DexterHaslem
DexterHaslem / gist:3252136
Created August 3, 2012 22:24
C# Right click Pinvoke w/ coord conversion for UI automation
public static class NativeMethods
{
[DllImport("user32.dll")]
internal static extern void mouse_event([In]uint dwFlags, [In]int dx, [In]int dy, [In]uint dwData, [In]uint dwExtraInfo);
[Flags]
internal enum MOUSEEVENTF : uint
{
MOVE = 0x00001,
LEFTDOWN = 0x00002,