Login Page - Create Account

Support Board


Date/Time: Wed, 27 Nov 2024 08:44:18 +0000



[Programming Help] - Is there a way to programmatically disable auto-trading?

View Count: 523

[2023-08-28 17:16:54]
TriStar Trading - Posts: 142
I have been looking for a way to disable auto trading from within ACSIL but have so far struck out. Something akin to being able to set the trading locked state on/off. Is anyone aware of such a beast? The problem to overcome is when I flatten a trade, if the criteria for an auto-trade is still valid I get put into a new trade as soon the flatten completes. Except for the trade entry, the stop order comes from the attached orders of the trade window. Any thoughts would be appreciated. Thanks, Mike
[2023-08-28 20:49:13]
ForgivingComputers.com - Posts: 960
Are you manually flattening, or is the study doing the flattening?

If manual, it is harder to tell why you are flat. You want a way for your study to know you mean Flatten and "Sit on Hands". By controlling the flattening with the study, using a Control Bar Button, or Chart Menu Shortcut, you can manage whether or not re-entry is allowed.
[2023-08-28 21:18:52]
TriStar Trading - Posts: 142
You are correct sir and thank you. I flatten using the "Flatten | Cancel" provided toolbar button. I will likely end up writing my own flatten cancel button. I think what will work is to flatten, cancel, and lock trading using the set trade lock state statement. It should work just with one extra step to unlock trading again. Mike
Date Time Of Last Edit: 2023-08-28 21:19:31
[2023-08-28 21:57:28]
ondafringe - Posts: 286
IMO, that is not a good way of going about things. Your study will still continue to place orders and you will get a lot of "order rejected" messages.

Better to rework your code to prevent unwanted orders from being submitted.
[2023-08-28 22:33:08]
TriStar Trading - Posts: 142
Correct ondafringe. I haven't found a way to programmatically turn off auto trading. Do you know of way? How would you rework the code? Thanks, Mike
[2023-08-28 23:55:54]
ForgivingComputers.com - Posts: 960
I think the point is your code should detect the conditions under which it is ok to trade, and when it is not. The Trade Lock will prevent trades, but it will also generate errors if your study keeps firing a signal. Hard to rework something I cannot see, but if you are not checking various things before submitting an entry, you will get unwanted trades or errors.
[2023-08-29 00:13:35]
TriStar Trading - Posts: 142
The code is pretty straight-a-way. So, if I manually flatten while these conditions are still true, the code will re-enter. I read committed order flow so I don't want to give up the target decision. But sometimes I do flatten and before I can turn auto trade off the conditions redevelop. Or I forget. :) Would be great to shut off auto trade when trapping the Result code. Any thoughts? Thanks in advance. Mike

    if (PositionData.PositionQuantity == 0 &&
Condition1[sc.Index] > 0 &&
     Condition2[sc.Index] > 0 &&
     Condition3[sc.Index] > 0 &&
     Condition3[sc.Index] > 0)
    {
     Result = static_cast<int>(sc.BuyEntry(NewOrder));  //Buy Entry
     if (Result > 0)
     sc.AddMessageToLog("Buy",1);
    }
Date Time Of Last Edit: 2023-08-29 00:28:54
[2023-08-29 00:29:32]
ondafringe - Posts: 286
Off the top: That could be as simple as adding a flag to your other conditions, then turning it off when you make the trade, and then turning it back on when a *separate* condition is met in order to allow another trade.

There are other ways to skin a cat, but you are the only one who knows what cat you're trying to skin.

Brad may throw some other ideas at you, as well.
Date Time Of Last Edit: 2023-08-29 00:37:09
[2023-08-29 00:44:23]
TriStar Trading - Posts: 142
So something like a persistent "in trade" flag set to true when entering a trade and adding that flag being false to my conditions to enter a trade. Then test for flag == true and position quantity = 0 to turn the flag to false. Thoughts? Thanks in advance. Mike

Thought about it more. That wouldn't do it.
Date Time Of Last Edit: 2023-08-29 01:12:27
[2023-08-29 01:10:18]
ondafringe - Posts: 286
Either use a global, or a persistent private, variable, most likely a bool.

Whether you check the flag for true or false in order to make a trade depends on whether you use positive or negative logic.

Then determine the *separate* condition where you will reset the flag to allow another trade. That condition could be as simple as setting up a hot key to manually reset the flag.
Date Time Of Last Edit: 2023-08-29 01:50:26
[2023-08-29 12:55:04]
TriStar Trading - Posts: 142
Went with a toolbar button to reset a flag allowing trades to be entered or not. Works fine. Thanks for your help. Mike

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account