├── README.md
├── indicators
├── Order Flow Tools
│ ├── DOM totals lines.cs
│ ├── Order Flow Tools.dll
│ ├── Order Flow Tools.pdb
│ └── README.md
└── README.md
└── strategies
├── README.md
├── SendTelegramMsg.cs
└── VolumeAccess
├── README.md
└── VolumeAccess.cs
/README.md:
--------------------------------------------------------------------------------
1 | # quantower
2 | Indicators and strategies for Quantower trading platform (C#)\
3 |
4 |
5 |
6 |
7 |
8 | ***
9 |
10 | ## Risk Disclosure
11 |
12 | ***Futures, stocks and forex trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones’ financial security or life style. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results.***
13 |
14 |
15 | ## CFTC RULE 4.41
16 |
17 | ***Hypothetical or simulated performance results have a certain limitations. Unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades may not have been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs, in general, can also be subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.***
18 |
--------------------------------------------------------------------------------
/indicators/Order Flow Tools/DOM totals lines.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Alejandro Galindo Cháirez. 2021
3 | //
4 | using System;
5 | using System.Drawing;
6 | using TradingPlatform.BusinessLayer;
7 |
8 |
9 | namespace Order_Flow_Tools
10 | {
11 | public class DOM_totals_lines : Indicator
12 | {
13 | [InputParameter("Level count", 10, 1, 9999, 1, 0)]
14 | public int InputLevelsCount = 10;
15 |
16 | [InputParameter("Custom tick size", 20, 0.0001, 9999, 0.0001, 4)]
17 | public double InputCustomTicksize = 0.0001;
18 |
19 | [InputParameter("Font size", 30, 1, 30, 1, 0)]
20 | public int fontSize = 8;
21 |
22 | [InputParameter("Paint rectangle", 40, 0, 1, 1, 0)]
23 | public bool paintRect = true;
24 |
25 | [InputParameter("X coordinate", 50, 1, 9999, 1, 0)]
26 | public int x = 775;
27 |
28 | [InputParameter("Y coordinate", 60, 1, 9999, 1, 0)]
29 | public int y = 20;
30 |
31 | double _askcumulative = 0.0;
32 | double _bidcumulative = 0.0;
33 |
34 | public DOM_totals_lines()
35 | : base()
36 | {
37 | Name = "DOM_totals_lines";
38 | Description = "Show the total Bid/Ask from DOM, needs level II data";
39 |
40 | AddLineSeries("Bids cumulative", Color.DarkRed, 2, LineStyle.Solid);
41 | AddLineSeries("Asks cumulative", Color.DarkGreen, 2, LineStyle.Solid);
42 |
43 | SeparateWindow = true;
44 | }
45 |
46 | protected override void OnInit()
47 | {
48 | this.Symbol.NewLevel2 += Symbol_NewLevel2Handler;
49 |
50 | }
51 |
52 | protected override void OnUpdate(UpdateArgs args)
53 | {
54 | if (args.Reason == UpdateReason.HistoricalBar)
55 | return;
56 | //get current 'order book' snapshot
57 | //var dom = this.Symbol.DepthOfMarket.GetDepthOfMarketAggregatedCollections();
58 | var dom = this.Symbol.DepthOfMarket.GetDepthOfMarketAggregatedCollections(new GetLevel2ItemsParameters()
59 | {
60 | AggregateMethod = AggregateMethod.ByPriceLVL,
61 | LevelsCount = this.InputLevelsCount,
62 | CalculateCumulative = true,
63 | CustomTickSize = this.InputCustomTicksize
64 | });
65 |
66 | _askcumulative = 0.0;
67 | _bidcumulative = 0.0;
68 |
69 | for (int i = 0; i < dom.Asks.Length; i++)
70 | _askcumulative += dom.Asks[i].Size;
71 |
72 | for (int i = 0; i < dom.Bids.Length; i++)
73 | _bidcumulative += dom.Bids[i].Size;
74 |
75 | SetValue(_bidcumulative, 0);
76 | SetValue(_askcumulative, 1);
77 |
78 | }
79 |
80 | private void Symbol_NewLevel2Handler(Symbol symbol, Level2Quote level2, DOMQuote dom)
81 | {
82 |
83 | }
84 | protected override void OnClear()
85 | {
86 | this.Symbol.NewLevel2 -= Symbol_NewLevel2Handler;
87 | }
88 |
89 | public override void OnPaintChart(PaintChartEventArgs args)
90 | {
91 | if (paintRect)
92 | {
93 | Graphics gr = Graphics.FromHdc(args.Hdc);
94 |
95 | // Create a font
96 | Font font = new Font("Arial", fontSize);
97 |
98 | Color rectColor = Color.Teal;
99 | if (_bidcumulative > _askcumulative)
100 | rectColor = Color.Red;
101 | else if (_bidcumulative < _askcumulative)
102 | rectColor = Color.Green;
103 | else
104 | rectColor = Color.Teal;
105 | Pen lpen = new Pen(rectColor, 3);
106 |
107 | Brush brushBids = Brushes.DarkRed;
108 | Brush brushAsks = Brushes.DarkGreen;
109 | gr.DrawRectangle(lpen, x, y, 60, 20);
110 | gr.DrawString(_bidcumulative.ToString(), font, brushBids, x+5, y+3);
111 | gr.DrawString(_askcumulative.ToString(), font, brushAsks, x+35, y+3);
112 |
113 | }
114 |
115 | }
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/indicators/Order Flow Tools/Order Flow Tools.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/agalindoc/quantower/56c475d777bebe926a0e0f399bcbb176af2cc9bc/indicators/Order Flow Tools/Order Flow Tools.dll
--------------------------------------------------------------------------------
/indicators/Order Flow Tools/Order Flow Tools.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/agalindoc/quantower/56c475d777bebe926a0e0f399bcbb176af2cc9bc/indicators/Order Flow Tools/Order Flow Tools.pdb
--------------------------------------------------------------------------------
/indicators/Order Flow Tools/README.md:
--------------------------------------------------------------------------------
1 | # **DOM totals lines**
2 | This is a resume of the DOM.\
3 | You need Data II level to get the level values.\
4 | I use this indicator as a filter when i have a trading setup.
5 |
6 | It plots:
7 | * Two lines, so i can see the history of the DOM across my chart\
8 | Green: are the Asks from the DOM (Sell limit orders)\
9 | Red: are the Bids of the DOM (Buy limit orders)
10 | * A small rectangle by default in the upper right corner with the same data.
11 |
12 |
13 | Parameters:
14 | * Level count: the number of DOM levels to consider the totals
15 | * Custom tick size: Value required by **GetLevel2ItemsParameters** class
16 | * Font size: for the values inside the rectangle
17 | * Paint rectangle: if true it plots the rectangle on the chart, if false the rectangle is off\
18 | Red: Ask limit orders bigger than bid limit orders\
19 | Green: Bid limit orders are bigger than ask limit orders\
20 | Gray: Bid and Ask limit orders are equal
21 | * X & Y coordinates for the rectangle
22 |
23 | 
24 |
25 | ## Example
26 |
27 | 
28 |
29 |
30 | As you can see in the previous image the indicator has a delay vs the original DOM, this is because the chart updates the values each tick and the DOM moves faster (100ms by default). For my use, this doesnt matter because i use it only as a filter.
31 |
32 | This indicator lines does not follow the normal logic.
33 |
--------------------------------------------------------------------------------
/indicators/README.md:
--------------------------------------------------------------------------------
1 | ## here you can find some indicators that i use to simplify my trading
2 |
3 | You will find 3 files for each indicator\
4 | **cs** file is the source code
5 |
6 | If you are not a developer and want to use the indicator you can download the **dll** and **pdb** extension files
7 |
8 | Copy them on a new folder inside your Quantower strategy location, example, mine is:\
9 | **C:\Users\Alejandro\Downloads\AMP Quantower\Settings\Scripts\Indicators\**
10 |
11 | inside Indicators folder create a new one, example, for "Order Flow Tools" i will create a folder called the same "Order Flow Tools", now we have the next folder location:\
12 | **C:\Users\Alejandro\Downloads\AMP Quantower\Settings\Scripts\Indicators\Order Flow Tools\**
13 |
14 | Here copy the **dll** and **pdb** files
15 |
16 | 
17 |
18 |
19 | Restart QuanTower if it does not detect the files automatically
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/strategies/README.md:
--------------------------------------------------------------------------------
1 | # QuanTower strategy examples
2 |
3 | Remember, all this is for educational purposes.
4 |
5 | ## SendTelegramMsg.cs
6 | This is just the simplest way to get alerts from NinjaTrader in your telegram bot.\
7 |
8 | I taked the example at Quantower GitHub code for a simple moving average cross trade with the Telegram message alert.
9 | https://github.com/Quantower/Examples/blob/master/Strategies/SimpleMACross.cs
10 |
11 | Replace from the input parameters:
12 | * the Telegram ID by your ID (@RawDataBot start then type anything and it will show your ID)
13 | * the Telegram Token by the token of your bot where you will get the messages (@BotFather -> start -> /newbot -> type the bot name and it will show you the token)
14 |
--------------------------------------------------------------------------------
/strategies/SendTelegramMsg.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using TradingPlatform.BusinessLayer;
4 | using System.Net;
5 | using System.IO;
6 |
7 |
8 | namespace SimpleMACross
9 | {
10 | public class SimpleMACross : Strategy
11 | {
12 | [InputParameter("Telegam Chat ID")]
13 | public string TelegramID = "1111";
14 |
15 | [InputParameter("Telegam BOT token")]
16 | public string TelegramToken = "aaaaaaaaaa";
17 |
18 | [InputParameter("Symbol", 0)]
19 | public Symbol symbol;
20 |
21 | [InputParameter("Account", 1)]
22 | public Account account;
23 |
24 | [InputParameter("Period", 5)]
25 | private Period period = Period.MIN5;
26 |
27 | [InputParameter("Fast MA", 2, minimum: 1, maximum: 100, increment: 1, decimalPlaces: 0)]
28 | public int fastMA = 5;
29 |
30 | [InputParameter("Slow MA", 3, minimum: 1, maximum: 100, increment: 1, decimalPlaces: 0)]
31 | public int slowMA = 10;
32 |
33 | [InputParameter("Quantity", 4, 0.1, 99999, 0.1, 2)]
34 | public double quantity = 1.0;
35 |
36 | public Indicator indicatorFastMA;
37 | public Indicator indicatorSlowMA;
38 |
39 | public HistoricalData hdm;
40 | private int longPositionsCount;
41 | private int shortPositionsCount;
42 |
43 | public SimpleMACross()
44 | : base()
45 | {
46 | this.Name = "Simple MA Cross strategy";
47 | this.Description = "Raw strategy without any additional functional";
48 | }
49 |
50 | protected override void OnCreated()
51 | {
52 | base.OnCreated();
53 | }
54 |
55 | protected override void OnRun()
56 | {
57 | if (symbol == null || account == null || symbol.ConnectionId != account.ConnectionId)
58 | {
59 | Log("Incorrect input parameters... Symbol or Account are not specified or they have diffent connectionID.", StrategyLoggingLevel.Error);
60 | return;
61 | }
62 |
63 | this.symbol.NewQuote += this.QuoteHandler;
64 |
65 | this.indicatorFastMA = Core.Instance.Indicators.BuiltIn.SMA(this.fastMA, PriceType.Close);
66 | this.indicatorSlowMA = Core.Instance.Indicators.BuiltIn.SMA(this.slowMA, PriceType.Close);
67 |
68 | this.hdm = this.symbol.GetHistory(period, this.symbol.HistoryType, DateTime.UtcNow.AddDays(-100));
69 |
70 | this.hdm.AddIndicator(this.indicatorFastMA);
71 | this.hdm.AddIndicator(this.indicatorSlowMA);
72 | }
73 |
74 | protected override void OnStop()
75 | {
76 | base.OnStop();
77 |
78 | if (this.symbol != null)
79 | {
80 | this.symbol.NewQuote -= this.QuoteHandler;
81 | }
82 |
83 | }
84 |
85 | protected override void OnRemove()
86 | {
87 | base.OnRemove();
88 | }
89 |
90 | protected override List OnGetMetrics()
91 | {
92 | List result = base.OnGetMetrics();
93 |
94 | // An example of adding custom strategy metrics:
95 | result.Add("Total long positions", longPositionsCount.ToString());
96 | result.Add("Total short positions", shortPositionsCount.ToString());
97 |
98 | return result;
99 | }
100 |
101 | private void QuoteHandler(Symbol instrument, Quote quote)
102 | {
103 | if (Core.Instance.Positions.Length != 0)
104 | {
105 | //Закрытие позиций
106 | if (this.indicatorFastMA.GetValue(1) < this.indicatorSlowMA.GetValue(1) || this.indicatorFastMA.GetValue(1) > this.indicatorSlowMA.GetValue(1))
107 | {
108 | TradingOperationResult result = Core.Instance.ClosePosition(new ClosePositionRequestParameters()
109 | {
110 | Position = Core.Instance.Positions[0],
111 | CloseQuantity = Core.Instance.Positions[0].Quantity
112 | });
113 |
114 | if (result.Status == TradingOperationResultStatus.Success)
115 | Log($"{result.Status}. Position was closed.", StrategyLoggingLevel.Trading);
116 | }
117 | }
118 |
119 | if (Core.Instance.Positions.Length == 0)
120 | {
121 | //Открытие новых позиций
122 | if (this.indicatorFastMA.GetValue(1) > this.indicatorSlowMA.GetValue(1))
123 | {
124 | TradingOperationResult result = Core.Instance.PlaceOrder(new PlaceOrderRequestParameters()
125 | {
126 | OrderTypeId = OrderType.Market,
127 | Quantity = quantity,
128 | Side = Side.Buy,
129 | Account = this.account,
130 | Symbol = this.symbol
131 | });
132 | if (result.Status == TradingOperationResultStatus.Success)
133 | {
134 | Log($"{result.Status}. Long position was placed.", StrategyLoggingLevel.Trading);
135 | SendTelegramMessage(" Long position was placed.");
136 | }
137 |
138 |
139 | longPositionsCount++;
140 | }
141 |
142 | else if (this.indicatorFastMA.GetValue(1) < this.indicatorSlowMA.GetValue(1))
143 | {
144 | TradingOperationResult result = Core.Instance.PlaceOrder(new PlaceOrderRequestParameters()
145 | {
146 | OrderTypeId = OrderType.Market,
147 | Quantity = quantity,
148 | Side = Side.Sell,
149 | Account = this.account,
150 | Symbol = this.symbol
151 | });
152 | if (result.Status == TradingOperationResultStatus.Success)
153 | {
154 | Log($"{result.Status}. Short position was placed.", StrategyLoggingLevel.Trading);
155 | SendTelegramMessage(" Short position was placed.");
156 | }
157 |
158 |
159 | shortPositionsCount++;
160 | }
161 | }
162 | }
163 |
164 | private void SendTelegramMessage(string txtMsg)
165 | {
166 | if (TelegramToken == "" || TelegramID == "")
167 | return;
168 | try
169 | {
170 | string TelegramURLString = "https://api.telegram.org/bot{0}/sendMessage?chat_id={1}&text={2}";
171 | TelegramURLString = String.Format(TelegramURLString, TelegramToken, TelegramID, txtMsg);
172 |
173 | WebRequest request = WebRequest.Create(TelegramURLString);
174 | Core.Instance.Loggers.Log(TelegramURLString);
175 |
176 | Stream rs = request.GetResponse().GetResponseStream();
177 | StreamReader reader = new StreamReader(rs);
178 | string strResponse = reader.ReadToEnd();
179 | reader.Close();
180 | Core.Instance.Loggers.Log(strResponse);
181 | }
182 | catch
183 | {
184 | Core.Instance.Loggers.Log("Error sending Telegram.");
185 | }
186 | }
187 | }
188 | }
189 |
--------------------------------------------------------------------------------
/strategies/VolumeAccess/README.md:
--------------------------------------------------------------------------------
1 | # VolumeAccess
2 |
3 | this code shows how to use volume data from the chart
4 |
5 | 
6 |
--------------------------------------------------------------------------------
/strategies/VolumeAccess/VolumeAccess.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Dev Alejandro Galindo Cháirez. 2021
3 | //
4 | using System;
5 | using System.Collections.Generic;
6 | using TradingPlatform.BusinessLayer;
7 |
8 | namespace VolumeAccess
9 | {
10 | public class VolumeAccess : Strategy
11 | {
12 | [InputParameter("Symbol", 0)]
13 | public Symbol symbol;
14 |
15 | [InputParameter("Account", 1)]
16 | public Account account;
17 |
18 | [InputParameter("Period", 2)]
19 | private Period period = Period.MIN1;
20 |
21 | [InputParameter("Bar Shift", 2)]
22 | private int barShift = 0;
23 |
24 |
25 | public HistoricalData hdm;
26 |
27 | double _askVolume = 0.0;
28 | double _bidVolume = 0.0;
29 | double _volume = 0.0;
30 | double _volumeOF = 0.0;
31 | double _delta = 0.0;
32 | bool _dataLoaded = false;
33 | DateTime _dateTimeLeft;
34 | DateTime _dateTimeRight;
35 | int _count = 0;
36 |
37 |
38 | public VolumeAccess()
39 | : base()
40 | {
41 | this.Name = "VolumeAccess";
42 | this.Description = "use of volume on a strategy";
43 | }
44 |
45 | protected override void OnCreated()
46 | {
47 | base.OnCreated();
48 | }
49 |
50 | protected override void OnRun()
51 | {
52 | if (symbol == null || account == null || symbol.ConnectionId != account.ConnectionId)
53 | {
54 | Log("Incorrect input parameters... Symbol or Account are not specified or they have diffent connectionID.", StrategyLoggingLevel.Error);
55 | return;
56 | }
57 |
58 | this.hdm = this.symbol.GetHistory(period, this.symbol.HistoryType, DateTime.UtcNow.AddDays(-100));
59 |
60 | symbol.NewQuote += OnNewQuote;
61 | symbol.NewLast += OnNewLast;
62 |
63 | IVolumeAnalysisCalculationProgress progress = Core.Instance.VolumeAnalysis.CalculateProfile(this.hdm, new VolumeAnalysisCalculationParameters()
64 | {
65 | CalculatePriceLevels = true,
66 | DeltaCalculationType = this.symbol.DeltaCalculationType
67 | });
68 | progress.StateChanged += this.Progress_StateChanged;
69 |
70 | Log("OnRun executed", StrategyLoggingLevel.Info);
71 |
72 | }
73 |
74 | protected override void OnStop()
75 | {
76 | base.OnStop();
77 |
78 | if (this.symbol != null)
79 | {
80 | symbol.NewQuote -= OnNewQuote;
81 | symbol.NewLast -= OnNewLast;
82 | }
83 |
84 | Log("OnStop executed", StrategyLoggingLevel.Info);
85 |
86 | }
87 |
88 | protected override void OnRemove()
89 | {
90 | base.OnRemove();
91 | }
92 |
93 | protected override List OnGetMetrics()
94 | {
95 | List result = base.OnGetMetrics();
96 |
97 | //if (_dataLoaded)
98 | //{
99 | // An example of adding custom strategy metrics:
100 | result.Add("Volume", _volume.ToString());
101 | result.Add("Current Ask volume", _askVolume.ToString());
102 | result.Add("Current Bid volume", _bidVolume.ToString());
103 | result.Add("Volume OF", _volumeOF.ToString());
104 | result.Add("Count", _count.ToString());
105 | result.Add("Time left:", _dateTimeLeft.ToString());
106 | result.Add("Time right:", _dateTimeRight.ToString());
107 | result.Add("Delta", _delta.ToString());
108 | //}
109 |
110 |
111 |
112 | return result;
113 | }
114 |
115 |
116 | private void OnNewLast(Symbol symbol, Last last)
117 | {
118 | StrategyProcess(last);
119 | //Log("OnNewLast executed", StrategyLoggingLevel.Info);
120 | }
121 |
122 | public void VolumeAnalysisData_Loaded()
123 | {
124 |
125 | }
126 |
127 | private void Progress_StateChanged(object sender, VolumeAnalysisTaskEventArgs a)
128 | {
129 |
130 | if (a.CalculationState == VolumeAnalysisCalculationState.Finished)
131 | {
132 | this._dataLoaded = true;
133 |
134 | Log("History Loaded", StrategyLoggingLevel.Info);
135 | }
136 |
137 | }
138 |
139 |
140 | private void OnNewQuote(Symbol symbol, Quote quote)
141 | {
142 | Log($"State: {this.hdm.VolumeAnalysisCalculationProgress.State.ToString()}");
143 |
144 | if (this.hdm.VolumeAnalysisCalculationProgress == null)
145 | Log("Progress is null");
146 |
147 | if (this.hdm.VolumeAnalysisCalculationProgress == null || this.hdm.VolumeAnalysisCalculationProgress.State != VolumeAnalysisCalculationState.Finished)
148 | return;
149 |
150 | StrategyProcess(quote);
151 |
152 | _volume = ((HistoryItemBar)hdm[barShift]).Volume;
153 | _askVolume = ((HistoryItemBar)hdm[barShift]).VolumeAnalysisData.Total.SellVolume;
154 | _bidVolume = ((HistoryItemBar)hdm[barShift]).VolumeAnalysisData.Total.BuyVolume;
155 | _volumeOF = ((HistoryItemBar)hdm[barShift]).VolumeAnalysisData.Total.Volume;
156 | _dateTimeLeft = ((HistoryItemBar)hdm[barShift]).VolumeAnalysisData.TimeLeft;
157 | _delta = ((HistoryItemBar)hdm[barShift]).VolumeAnalysisData.Total.Delta;
158 | _dateTimeRight = hdm.FromTime;
159 | _count = hdm.Count;
160 | if (double.IsNaN(_askVolume))
161 | Log("_askVolume is NaN");
162 |
163 | //if (_dataLoaded)
164 | //{
165 | //
166 | // Execute here yor strategy based on volume data
167 | //
168 | // _askVolume = hdm[0, SeekOriginHistory.End].VolumeAnalysisData.Total.SellVolume;
169 | // _bidVolume = hdm[0, SeekOriginHistory.End].VolumeAnalysisData.Total.BuyVolume;
170 | //}
171 |
172 | //Log("OnNewQuote executed", StrategyLoggingLevel.Info);
173 |
174 |
175 | }
176 |
177 |
178 | private void StrategyProcess(MessageQuote message)
179 | {
180 | //Log("StrategyProcess executed", StrategyLoggingLevel.Info);
181 | }
182 |
183 | private void QuoteHandler(Symbol instrument, Quote quote)
184 | {
185 | //Log("QuoteHandler executed", StrategyLoggingLevel.Info);
186 | }
187 | }
188 | }
189 |
--------------------------------------------------------------------------------