Referencing Existing Trades

When creating a new trade, there may be situations where you would like to reference specific attributes from existing positions / trades. 

  • Trade a new option spread whose strikes overlap with the short strikes of an existing option spread
  • Trade a new option spread with the same expiration dates as an existing option spread

You can reference the attributes of existing trades using the SetVariable block combined with the Order block.


We will use the following example to explain how to reference the attributes of an existing trade when entering a new trade.

Example: Long Put To Put Vertical Spread Adjustment

  • Buy a long put on the SPX

  • When the long put has achieved 50% or greater profit, adjust the long put into a put vertical spread by selling a further out of the money put with the following attributes:
    • new short put should have the same expiration date of the existing long put
    • new short put should be 20 points further out of the money from the existing long put


  • Buy a long at-the-money put on the SPX


  • Create variables referencing the attributes of the BuyPut order using the SetVariable block.  We will reference these variables when constructing the new short put trade.

    • StrikeVariable – reference the strike price of the long put
    • ExpirationVariable – reference the expiration date of the long put


  • Variables that reference the attributes of an existing order must be enclosed inside a WHEN block with matching OrderID’s
  • Create a WHEN block with matching OrderID’s, and place the variables inside the WHEN block.


  • Create a Strategy block with strategy filters that use the strike / expiration variables above.
    • Strategy:  Sell Put
    • DaysToExpiration:  Use the ExpirationVariable to set the same expiration date as the long put
    • StrikePrice: Use the (StrikeVariable – 20) to set the new strike price to be 20 points lower than the strike price of the existing long put




Debugging Variables

You can use the Log block to print the value of the variables. The values of the variables will be outputted into the Log tab where you can view the state of the variables over time.

To preview trades which use the SetVariable blocks, please print the value of the variables using the Log Block, and temporarily set the variables to the values printed in the Logs.

Please see https://www.optionstack.com/debug-your-trading-system/ for more information.