Index futures automation

Discussion in 'Journals' started by hilmy83, Jul 3, 2022.

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

  1. YES!

    56 vote(s)
    66.7%
  2. Hell naw.

    15 vote(s)
    17.9%
  3. I don't know, I got my own trading to worry about.

    13 vote(s)
    15.5%
  1. ondafringe

    ondafringe

    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. :)
     
    #581     Sep 12, 2023
    Bad_Badness and hilmy83 like this.
  2. Bad_Badness

    Bad_Badness

    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: Sep 12, 2023
    #582     Sep 12, 2023
    ondafringe likes this.
  3. hilmy83

    hilmy83

    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.
     
    #583     Sep 12, 2023
  4. hilmy83

    hilmy83

    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
     
    #584     Sep 12, 2023
  5. hilmy83

    hilmy83

    SHit, nevermind

    upload_2023-9-12_22-45-51.png
     
    #585     Sep 12, 2023
  6. hilmy83

    hilmy83

    This edit works, and it ended flat..

    upload_2023-9-12_23-15-12.png

    upload_2023-9-12_23-15-49.png
     
    #586     Sep 13, 2023
  7. hilmy83

    hilmy83

    #587     Sep 13, 2023
  8. hilmy83

    hilmy83

    #588     Sep 13, 2023
  9. hilmy83

    hilmy83

    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).
     
    #589     Sep 13, 2023
  10. hilmy83

    hilmy83

    #590     Sep 14, 2023