-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathRenkoSniper.cs
113 lines (100 loc) · 3.35 KB
/
RenkoSniper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#region Using declarations
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Gui.Tools;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.Indicators;
using NinjaTrader.NinjaScript.DrawingTools;
#endregion
//This namespace holds Strategies in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Strategies
{
public class RenkoSniper : Strategy
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Looks for fast ticks";
Name = "RenkoSniper";
Calculate = Calculate.OnBarClose;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 30;
IsFillLimitOnTouch = false;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
OrderFillResolution = OrderFillResolution.Standard;
Slippage = 0;
StartBehavior = StartBehavior.WaitUntilFlat;
TimeInForce = TimeInForce.Gtc;
TraceOrders = false;
RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
StopTargetHandling = StopTargetHandling.PerEntryExecution;
BarsRequiredToTrade = 20;
// Disable this property for performance gains in Strategy Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = true;
RenkoTick = 2.0;
MSTrigger = 250;
}
else if (State == State.Configure)
{
SetProfitTarget(CalculationMode.Ticks,(RenkoTick*1.0));
SetStopLoss(CalculationMode.Ticks,(RenkoTick*1.5));
//SetTrailStop(CalculationMode.Ticks,(RenkoTick*2.1));
}
}
protected override void OnBarUpdate()
{
//check if we have enough bars to trade
if (CurrentBars[0] < (BarsRequiredToTrade))
return;
if(Position.MarketPosition == MarketPosition.Flat)
{
//evaluate
//if (Time[0].Subtract(Time[1]).TotalMilliseconds <= MSTrigger)
//{
//bar created in < trigger
//if(Close[0] > High[1] && (((Close[0]-Open[0])*4)/RenkoTick)>=0.90)
if ((((Close[0]-Open[0])*4)/RenkoTick)>=0.9 && Close[0]>EMA(14)[0] && Open[0]<EMA(14)[0])
{
EnterLong();
}
//if(Close[0] < Low[1] && (((Open[0]-Close[0])*4)/RenkoTick)>=0.90)
if((((Open[0]-Close[0])*4)/RenkoTick)>=0.9 && Close[0]<EMA(14)[0] && Open[0]>EMA(14)[0])
{
EnterShort();
}
//}
}
}
#region Properties
[NinjaScriptProperty]
[Range(1, double.MaxValue)]
[Display(Name="Renko Chart Tick", Description="The renko chart tick size.", Order=0, GroupName="Config")]
public double RenkoTick
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="MS Trigger", Description="The millisecond trigger size.", Order=0, GroupName="Config")]
public double MSTrigger
{ get; set; }
#endregion
}
}