The salient long entry code reads:
if (Historical) return;
Print ("Line 485, Bar" + Bars.BarsSinceSession + " " + Time[0].TimeOfDay + " Pre anything Order Entry: Strategy Id: " + atmStrategyId + ", Order Id: " + orderId);
if((atmStrategyId.Length > 0 ? GetAtmStrategyMarketPosition(atmStrategyId) == MarketPosition.Flat : 1==1)
&& realized_profit > loss_exit && realized_profit < profit_exit
&& PatternDesc != "")//wait til flat
{
Print("490");
if (orderId.Length == 0 && atmStrategyId.Length == 0 && trade > 0 && trade < 10
&& (!string.IsNullOrEmpty(from_time_1) ? ((ToTime(Time[1]) >= start_time && ToTime(Time[1]) <= end_time) || (ToTime(Time[1]) >= start_time_1 && ToTime(Time[1]) <= end_time_1)) : (ToTime(Time[1]) >= start_time && ToTime(Time[1]) <= end_time))
&& btnLongEntry.Text == "Enter Long")
{
Print("496 Long Order Entry, Pre Set Ids " + atmStrategyId);
entrybar = Bars.BarsSinceSession;
atmStrategyId = GetAtmStrategyUniqueId();
orderId = GetAtmStrategyUniqueId();
Print("498: " + Time[0] + "Pattern #: " + trade + ", " + entrybar + ", Bar: " + Bars.BarsSinceSession + ", Position: " + GetAtmStrategyMarketPosition(atmStrategyId) + ", StratId: " + atmStrategyId + ", Order Id: " + orderId);
AtmStrategyCreate(OrderAction.Buy, TypeEntry, (TypeEntry != OrderType.Market ? Close[1]+LimitOffset*TickSize : 0),
(TypeEntry != OrderType.StopLimit ? 0 : (Close[1]+StopOffset*TickSize)), TimeInForce.Day, orderId,
(closeat == 1 ? PatternDesc : PatternDesc), atmStrategyId);
and the Output window looks like:
Line 485, Bar104 11:51:35 Pre anything Order Entry: Strategy Id: , Order Id:
490
496 Long Order Entry, Pre Set Ids
**NT** GetAtmStrategyMarketPosition() method error: AtmStrategyId '8f881c91764d43998a46fa8a5ecb2bdd' does not exist
498: 3/17/2011 11:51:35 AMPattern #: 5, 104, Bar: 104, Position: Flat, StratId: 8f881c91764d43998a46fa8a5ecb2bdd, Order Id: 01f5580fafa94ab8960874ec842b555f
**NT** Submitting order with strategy 'TRO ATM w/ Buttons/a6d7ec29f4f247df967d037f94aa3495'
548 3/17/2011 11:51:35 AM OrderID: 01f5580fafa94ab8960874ec842b555f, Entry Order Status: PendingSubmit, atmId: 8f881c91764d43998a46fa8a5ecb2bdd, Entry Bar: 104, Current Bar: 104
328: 3/17/2011 11:51:35 AM atmStratId: 8f881c91764d43998a46fa8a5ecb2bdd, Position: Flat, Status: PendingSubmit
548 3/17/2011 11:51:35 AM OrderID: 01f5580fafa94ab8960874ec842b555f, Entry Order Status: PendingSubmit, atmId: 8f881c91764d43998a46fa8a5ecb2bdd, Entry Bar: 104, Current Bar: 104
After the entry, the order is placed and filled, the code checks for a completed trade with the following code:
Print("328: " + Time[0] + " atmStratId: " + atmStrategyId + ", Position: " + GetAtmStrategyMarketPosition(atmStrategyId) + ", Status: " + status[2]);
if((atmStrategyId.Length > 0 ? GetAtmStrategyMarketPosition(atmStrategyId)==Marke tPosition.Flat : 1==2) && (status[2] == "Filled" || status[2] == "Cancelled" || status[2] == "Rejected"))
{
Print("331 " + Time[0] + " StratId = " + atmStrategyId + " Position: " + GetAtmStrategyMarketPosition(atmStrategyId) + ", Order: " + status[2]);
realized_profit += GetAtmStrategyRealizedProfitLoss(atmStrategyId);
Print("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
Print("Your Realized Profit for today's trading is: " + realized_profit.ToString("C"));
if(realized_profit < loss_exit || realized_profit > profit_exit)
Print("Your trading is finished for today.");
if(realized_profit > profit_exit) Print("Awesome day. Now go celebrate.");
else if(realized_profit < loss_exit)
Print("Tomorrow will be a new day and the sun will come up and the birds will sing. All is not lost.");
Print("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
atmStrategyId = string.Empty;
orderId = string.Empty;
oldprojectedlow = 0;
oldprojectedhigh = 0;
Print("345: " + Time[0] + " reset the strategy id");
But the Output window displays:
328: 3/17/2011 11:51:36 AM atmStratId: 8f881c91764d43998a46fa8a5ecb2bdd, Position: Flat, Status: Filled
331 3/17/2011 11:51:36 AM StratId = 8f881c91764d43998a46fa8a5ecb2bdd Position: Flat, Order: Filled
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Your Realized Profit for today's trading is: $0.00
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
345: 3/17/2011 11:51:36 AM reset the strategy id
At the time it Prints line 328: Market Status is LONG, not Flat.
I hesitate to ask because I know your job is not my programming, but can you see any reason I am getting that NT error and why it shows the order Filled but the position is Flat. It seems the code is losing or misplacing the atmStrategyId.
Thanks,
Snap
p.s., The really aggravating thing is that sometimes it does remember the Id and works properly.
Comment