Index futures automation

Can a fully automated trading strategy work in the long run?

  • YES!

    Votes: 56 67.5%
  • Hell naw.

    Votes: 14 16.9%
  • I don't know, I got my own trading to worry about.

    Votes: 13 15.7%

  • Total voters
    83
And this is in a normal market not a disorderly one. One needs to assume everything can go wrong. Even the "corrections" can go wrong. With these assumptions the code is very complex. It will be more than the algo code, way more. Examine transaction roll back methods. Draw up a framework for Algo wrong, Algo-broker wrong, broker exchange wrong, XXX wrong, but only delayed and then corrects.

Basically for every transaction, you need to hold it in a sand box and compare it to the reported state, then keep all those until the entire transaction is complete. With OCO orders, this is a lot. With reversals, more and more with multiple contracts (positions).

Do this on a branched version of the code base. There about 2x-3x more code to write for this. That is why your "dev" did not do it. Testing is even more work because, as you know, you cannot do it in Sim, but you will have to create the error conditions live and include the broker and exchange, such as loss connection or very large delays not only in the sending, but in the confirmation.

If you want to go down this path, write a separate order handler that works with all algos not just this one.

PS: I think the NASDAQ site has some information on order handlers and best practices that they implement between the exchange and the FCM-IB.

Thanks for posting this. I'm no code guru, far from it. I know enough to get my own algos coded, and then use the VS debugger to work out problems. It works, but it's all pretty sloppy. I so need to learn how to do all that and more. You've just given me the push I needed. Thanks, again. :)
 
Thanks for posting this. I'm no code guru, far from it. I know enough to get my own algos coded, and then use the VS debugger to work out problems. It works, but it's all pretty sloppy. I so need to learn how to do all that and more. You've just given me the push I needed. Thanks, again. :)
Glad to add value!:fistbump:

BTW: sloppy is not necessarily bad. I have one running now that I describe as a "squirrel nest". Leaves and branches everywhere, no grand architecture besides being wedged between three branches. But every wind hole, every rain hole is double -triple blocked so it is warm and cozy inside despite high winds, driving rain and melting snow. It makes money.

I wrote this one to do test exactly what Hilmy83 is describing. Live trading and order handling is a risk factor itself. It is not really extendable, or portable to anything else. Next version has an actual design that is extendable to add things like multi contracts, reversals while keeping the order handling mechanism.

It is the type of "snake oil" system a lot of the wannabe posers want to sell to newbies. "Look at that equity curve!" lol, but the inter-trade drawdowns are too large for the gains, imo and I can do way better. Hilmy's next version will be even better too!
 
Last edited:
Ok. So here's the current code:
When target is completed and position is flat, message is sent out to indicate the pnl.

upload_2023-9-12_22-29-16.png


So at that point, I want to add a check:

upload_2023-9-12_22-31-56.png


I want to add this section into the code. Basically the intent is once target is met, I want to retrieve any orders that may be around at that point and cancel it.
 
Ok. So here's the current code:
When target is completed and position is flat, message is sent out to indicate the pnl.

View attachment 322949

So at that point, I want to add a check:

View attachment 322951

I want to add this section into the code. Basically the intent is once target is met, I want to retrieve any orders that may be around at that point and cancel it.

per chatgpt

The provided code is written in C# and appears to be part of a trading or financial application. Let's break down what each part of the code does:

  1. void OnFlatten()
    • This is a method that appears to be called when you want to "flatten" your trading positions, which means closing all open orders or positions.
  2. if (position_quantity == 0)
    • This condition checks whether the position_quantity is equal to 0.
    • If position_quantity is indeed 0 (meaning you have no open positions), the code inside the if block is executed.
  3. Inside the if block:
    • It calculates the result as the sum of realized_commission and closed_result, formatted as a string with two decimal places.
    • It creates a message string indicating that trading for the day has finished, and it displays the realized profit or loss in the message.
    • It uses Core.Instance.Alert(...) to display the message as an alert, potentially in a trading platform or application. The this.Symbol.Name is used as a parameter for the alert.
  4. After the if block, it retrieves a collection of orders using Core.Instance.Orders.

  5. It iterates through the collection of orders using a foreach loop.
    • Inside the loop, it attempts to cancel each order using the order?.Cancel() syntax. The ?. operator is used to prevent null reference exceptions in case an order is null.
  6. private void GetOrders(out Order buy, out Order sell, out Order target, out Order reverse)
    • This is a private method that appears to retrieve specific orders by their IDs and store them in out parameters.
  7. Inside the GetOrders method:
    • It retrieves four specific orders using their IDs (likely order identifiers): buy_stop, sell_stop, target_order, and reverse_order.
    • The orders are obtained using the Core.Instance.GetOrderById(...) method.
Overall, this code seems to handle the closing of positions (flattening) and the cancellation of open orders in a trading application. It also has a method for retrieving specific orders by their IDs. The exact behavior and purpose of this code would depend on the broader context of your trading application and how these variables and methods fit into your trading strategy.



Seems about right. I'll try it out unless someone can bring up issues with this logic
 
So I went back to the original code which din't have the unnecessary settings I asked the dev to add later. And settled on this change to handle open orders/positions that may be left after target is hit:

upload_2023-9-13_21-53-53.png


I still need to figure out how to handle situation if an order is placed out of sequence like what happend on 9/12. But since that happened on the latest version, I'll just put that on backburner for now. I'll keep a detailed log going forward if more things happen with this "classic" version, to share with future dev (or current dev whenever the hell he shows up).
 
Back
Top