regards to everyone.
this is something i have been thinking about for a long time but would be impossible for me to code on my own. there are a number of economic and political events which have dates that are known well in advance and have very significant effects on the prices of financial assets. elections, referenda, releases of economic data and other events have very significant influence on the behavior of market manipulators both before and after they occur.
i'm interested in adding code to my pure trend following strategies so that all positions would be liquidated before the close on every date in a list. and there are very different kinds of events (fomc meetings - minutes, elections, eia - api petroleum reports, unemployment reports, et cetera) that i would like to evaluate on their own or aggregated, so instead of hard coding this information into my strategies i'm interested in having code that would allow vectors (or lists, or arrays) of dates with very different numbers of components (from none to several tens of dates).
this below is the list of federal open market committee meetings for the last two years. ¿how could i add code to my strategies so that in every one of those dates all positions would be liquidated starting at 15:30?
November 05, 2020
September 16, 2020
August 27, 2020
July 29, 2020
June 10, 2020
April 29, 2020
March 31, 2020
March 23, 2020
March 19, 2020
March 15, 2020
March 3, 2020
October 30, 2019
September 18, 2019
July 31, 2019
December 19, 2018
i have this very simple, alternating strategy to work on:
#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 tealternatingcurrentbar : Strategy { protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"te alternating current bar."; Name = "tealternatingcurrentbar"; Calculate = Calculate.OnBarClose; EntriesPerDirection = 1; EntryHandling = EntryHandling.UniqueEntries; IsExitOnSessionCloseStrategy = true; ExitOnSessionCloseSeconds = 30; IsFillLimitOnTouch = false; MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix; OrderFillResolution = OrderFillResolution.Standard; Slippage = 6; StartBehavior = StartBehavior.ImmediatelySubmitSynchronizeAccount; TimeInForce = TimeInForce.Gtc; TraceOrders = false; RealtimeErrorHandling = RealtimeErrorHandling.StopCancelCloseIgnoreRejects ; StopTargetHandling = StopTargetHandling.PerEntryExecution; BarsRequiredToTrade = 1; // Disable this property for performance gains in Strategy Analyzer optimizations // See the Help Guide for additional information IsInstantiatedOnEachOptimizationIteration = true; Posi = 1; } else if (State == State.Configure) { } } protected override void OnBarUpdate() { if (BarsInProgress != 0) return; if (CurrentBars[0] < 1) return; // Set 1 if (CurrentBar % 2 == 0) { EnterShort(Convert.ToInt32(Posi), ""); } // Set 2 if (CurrentBar % 2 == 1) { EnterLong(Convert.ToInt32(Posi), ""); } } #region Properties [NinjaScriptProperty] [Range(1, int.MaxValue)] [Display(Name="Posi", Description="posi.", Order=1, GroupName="Parameters")] public int Posi { get; set; } #endregion } }
i think that first it would be helpful to create a no trade condition with a structure like the following:
if date = one of the elements in the vector and time >= 15:30 then do not trade = true.
the idea for this fragment would be that no more positions would be opened after some cutoff time i could determine.
and to liquidate all positions what i have in mind would be similar:
if date = one of the elements in the vector and time >= 15:30 and market position = short then exitshort.
this and an analog command for long positions would help to make sure that the strategy would not hold any positions over the dates i determined.
i could use help with everything, from the format that the dates must have, to how to input a vector (or vectors) into a strategy (¿could i just list them all separated with commas?), to the logic so that every date would be processed and evaluated individually, and so forth.
very well, hopefully this could also be an interesting coding challenge to the most proficient members in these fora. thanks in advance to everyone, regards.
Comment