I have created a simple script to get help with. This is just for demonstrative purposes. My script is making use of several lists, as this replicates my real script, where I hold prices for a bunch of different trades.
The script looks for an outside bar. Once that outside bar is found, I have Lists that store the following:
- -Bool, if an order has been placed(HasTriggered)
- -Int, how many bars have passed since that condition occurred(BarsPassed)
- -Int, what the bar of that condition was(BarLow)
You will also notice I have another list(MyEntryOrders). I understand this should be used, with the OnOrderUpdate() function to use CancelOrder(). I saw THIS example in the docs, but I can't quit figure out how to get it to work for my script as I am using the lists to store order info instead of just a single variable.
The script the loops through the Lists. If no order has been placed for a given bar, an order is placed, and flag HasTriggered is set, this way only one order per entry condition. BarsPassed is incremented.
The next set of code is unfinished, here you see I say if BarsPassed, cancel the order associated with this portion of the loop.
public class nt8ForumCancelOrderHelp : Strategy { private List<bool> HasTriggered; //Flag when entry condition occurrs, so only one entry per condition private List<Order> MyEntryOrders; private List<int> BarsPassed; //Count of Bars since outside bar private List<int> BarLow; //Bar Where Entry condition was created
else if (State == State.Configure) { HasTriggered = new List<bool>(); MyEntryOrders = new List<Order>(); BarsPassed = new List<int>(); BarLow = new List<int>(); }
protected override void OnBarUpdate() { if (BarsInProgress != 0) return; if (CurrentBars[0] < 2) return; if(High[0] > High[1] &&Low[0] < Low[1]) { Draw.TriangleUp(this,"lowBaseBarTR"+CurrentBar, false, 0, Low[0] - 0*TickSize, Brushes.Yellow); HasTriggered.Add(false); //Has order been places BarsPassed.Add(0); //How many bars have passed since condition BarLow.Add(CurrentBar); //What was the bar number of the condition } for (int i=0; i < HasTriggered.Count; i++) //Loop through the lists to check conditions { BarsPassed[i]++; //increment Bars passed if(!HasTriggered[i]) //If no order for that condition has been placed { EnterLongLimit(0, true, Convert.ToInt32(DefaultQuantity), Low[CurrentBar-BarLow[i]], "LongLimit"); HasTriggered[i]=true; //Only one entry per condition } //Want to figure out how to cancel here? if( BarsPassed[i] > 10) { // CancelOrder("LongLimit"); } } }
Comment