- ago
I'm having another issue with Dummy Broker account. It appears to be ignoring Live Positions trading preference as strategy is signaling buys for the same positions every intraday bar.
0
446
Solved
8 Replies

Reply

Bookmark

Sort
Cone8
 ( 23.46% )
- ago
#1
I don't agree. I just tested it and it worked correctly.
There's not any information in your post, but my intuition would be to make sure you're pointing to the correct the Dummy Broker ACCOUNT that has the position you're trading.
0
- ago
#2
It's placing the positions in the correct Dummy account. Let me do some troubleshooting.
0
- ago
#3
I added the following debug code in the Execute method.
CODE:
         if (_lastDay && _lastTrade)          {             WriteToDebugLog("*** Open Positions ***", false);             WriteToDebugLog("There are " + OpenPositionsAllSymbols.Count + " open positions", false);             foreach (Position op in OpenPositionsAllSymbols)             {                WriteToDebugLog(op.ToString(), false);             }                   }


Debug result
QUOTE:
*** Open Positions ***
There are 0 open positions


Should OpenPositionsAllSymbols detect the open positions in the Dummy account? The open positions are options contracts. Pls let me know if I am doing something wrong.

0
Cone8
 ( 23.46% )
- ago
#4
QUOTE:
Should OpenPositionsAllSymbols detect the open positions in the Dummy account?
No. OpenPositionsAllSymbols is a Backtester function.

Is the script's primary symbol one of those option symbols? Live Positions only works for the primary symbol.
0
- ago
#5
QUOTE:
Is the script's primary symbol one of those option symbols?

If you mean, what's in the DataSet, it's the primary symbol, not the option symbol. The trading signal is based indicators that run on the primary symbol. If the signal is a BUY, the code searches for the option contract that best meets several criteria and buys that.

QUOTE:
Live Positions only works for the primary symbol.

I think it makes sense to me now.. Let me know if I have this right: the Execute code is looping through the symbols in the DataSet and with Live Positions enabled, on the last bar it will be looking for the current symbol in the account, not just querying the account for all open positions.
0
Cone8
 ( 23.46% )
- ago
#6
Correct. The "Current Symbol" is the Primary BarHistory - the "bars" in passed to Initialize() and Execute(), etc.

Here's the key point from the Help -


To refresh your memory about how to get live account positions in a script .... see Post #18 and below here: https://www.wealth-lab.com/Discussion/7914
0
Best Answer
- ago
#7
Thanks for the confirm and info. I was wondering what the "Pairs trading" exception was. Didn't realize that was what I was doing.

The code for the post you referred me to

CODE:
//see if we have a live position in the broker account BrokerPosition bp = GetBrokerPosition("Account 1", bars.Symbol, PositionType.Long);


would be checking for the primary symbol. How do I check for the option contract symbol if the strategy doesn't know what it is? The strategy knows what the primary is but I can't see how it can operate on the active symbol before it knows what it is (at least with this code method).

Can I tag positions with the primary symbol? Or is that only a backtester function?

I see in the Options Trading Tutorial Live Trading:Example 6 the code snippet
CODE:
         Position pos1 = FindOpenPositionAllSymbols(_hash1);          Position pos2 = FindOpenPositionAllSymbols(_hash2);


...but I'm unclear if that's only for the backtest part of the strategy, not live trading.

Is there a way to create a list of all positions in the broker account? Or to operate on the active option contract positions using something like the Option Helper tools?

What's the best example of code that does what I am doing: live trading of option contracts based on the underlying?
0
Cone8
 ( 23.46% )
- ago
#8
You're not pairs trading. It says "strategies that external symbols, such as..." - and gives an example of a strategy type that uses external symbols.

QUOTE:
How do I check for the option contract symbol if the strategy doesn't know what it is?
You can use QuickRef -> 'OptionsHelper' to determine if a broker position is an option of the underlying.

QUOTE:
Can I tag positions with the primary symbol?
I don't know what you mean, but positionTag has to be a positive integer.

QUOTE:
...but I'm unclear if that's only for the backtest part of the strategy, not live trading.
It's always backtest unless you go out of your way to query something external, like the BrokerAccount.

QUOTE:
Is there a way to create a list of all positions in the broker account?

Post #21 and #31 in the topic I keep pointing you back to. Once you have a reference to BrokerAccount -> brokerAccount.Positions

QUOTE:
What's the best example of code that does what I am doing: live trading of option contracts based on the underlying?
It's pretty straightforward. If the brokerPosition exists, then you can write a condition to exit it. If you need more help, we have the Concierge Service for custom programming jobs and consulting.
0

Reply

Bookmark

Sort