Login Page - Create Account

Support Board


Date/Time: Sat, 27 Apr 2024 15:41:52 +0000



Post From: Spreadsheet trading study: canceling an unfilled limit order

[2018-02-21 17:49:53]
Shane - Posts: 31
In a spreadsheet trading study, I’ve implemented the code from the SC website to cancel an unfilled limit order after x number of bars.
http://www.sierrachart.com/index.php?page=doc/SpreadsheetExampleFormulasAndUsage.php


This works as expected for the first buy or sell order, however if there is a second order in the same direction, this approach fails (i.e., a buy order where the trade completes and then the next order that triggers is also a buy order).

What happens is (from the trade activity log) the second order is triggered and accepted, and then immediately *canceled* by the J27 cell formula.

I’m using the spreadsheet to trigger a buy or sell with attached orders. The attached orders then handle the exits for the order. The buy and sell exit columns of the spreadsheet study are not used.

Any ideas how to handle this case? I’m stuck.

*************

These two formulas (from the link above) count the number of cells since a buy and sell event.

In column P: =IF(M3,0,IF(OR(K3,P4>0),P4+1,P4))

In column Q: =IF(K3,0,IF(OR(M3,Q4>0),Q4+1,Q4))

This formula is in the J27 cell (cancel working orders):

=OR(AND(P4 >= H6 + 1, J4 > 0), AND(Q4 >= H6 + 1, J4 < 0))

…where H6 is the number of bars to wait for a fill before canceling the order. (The only difference from the website code is the use of H6 instead of H4 to hold the number of bars to wait).

*************

The formulas in P and Q will start counting the number of bars since a buy or sell event and will just keep counting until an order in the opposite direction is triggered. This is problematic if there are consecutive trades in the same direction.

I would have thought the use of “J4>0” and “J4<0” in the J27 formula would overcome this issue, but it consistently fails to work as expected. Is there an order of formula execution problem?

Am new to spreadsheet studies so any help greatly appreciated.

Regards,
shane
Date Time Of Last Edit: 2018-02-21 19:20:14