Conditional Order Executing Before Conditions are Met

Tomahawk6117

Member
Plus
Hi everyone, I have been working on improving the scripts for my conditional orders, however the conditional orders I have been working on have been filling at the market open (9:30 a.m.) using a market order, even if the customs studies I input have not executed yet. I have included images below of what I have been using for my conditional order, and I have included the script I have been trying to use as well. The intent of the script is to buy when the MACD Diff is greater than zero, and the KST is greater than the signal line. May you please help me with this? Thank you very much for your time and your help.

Code:
declare lower;

input rocLength1 = 10;
input rocLength2 = 15;
input rocLength3 = 20;
input rocLength4 = 30;

def sumRocLength = rocLength1+rocLength2+rocLength3+rocLength4;
input smaLength1 = 10;
input smaLength2 = 10;
input smaLength3 = 10;
input smaLength4 = 22;
input signal_length=9;
def ROC1 = RateOfChange(rocLength1, rocLength1, close);
def ROC2 = RateOfChange(rocLength2, rocLength2, close);
def ROC3 = RateOfChange(rocLength3, rocLength3, close);
def ROC4 = RateOfChange(rocLength4, rocLength4, close);

 
def RCMA1 =  Average(ROC1,smaLength1);
def RCMA2 =  Average(ROC2,smaLength2);
def RCMA3 =  Average(ROC3,smaLength3);
def RCMA4 =  Average(ROC4,smaLength4);

def KST = (RCMA1* 1) + (RCMA2* 2) + (RCMA3* 3) + (RCMA4 * 4);

def Signal_Line = Average(kst, signal_length);

def goodKST = KST > Signal_Line;

def d = MACDHistogram().diff;
def goodMACD = d > 0;

def sell1 = if goodKST and goodMACD then 1 else 0;

plot z1 = sell1;

ZWteaJE.png


29ux9cG.png


2EsOoIG.png


PadlGW5.png
 
Explain the four sell orders.
Hi @Joshua, thank you very much for your response. In the picture above with the four sell orders, that is just a sample photograph of what I would typically use as a part of a "1st tags Seq." I understand in the picture above I am selling more stock than I own, I should have changed the sell orders for the sake of the photograph. I have included a more realistic photograph below. My main concern is that my "buy" conditional order is executing as a market order at the market open, even if the condition has not been satisfied yet. Thank you again for your help Joshua.

z1PbzJU.png
 
Last edited:
Assuming this happened today (Monday) on SOBR, it looks like it might have just triggered properly.

The overall false result you're seeing is based on the repainted Close of the 9:30 bar.

At the open, KST was positive for sure, and D was dancing at the zero line. For comparison, D was positive for the two bars prior to 9:30, and the 9:30 bar's open and high were both in range of those two bars.

Here is a good question - What was the fill price?

wiSwOzN.png
 
Assuming this happened today (Monday) on SOBR, it looks like it might have just triggered properly.

The overall false result you're seeing is based on the repainted Close of the 9:30 bar.

At the open, KST was positive for sure, and D was dancing at the zero line. For comparison, D was positive for the two bars prior to 9:30, and the 9:30 bar's open and high were both in range of those two bars.

Here is a good question - What was the fill price?

wiSwOzN.png
Thank you very much for looking into this for me, I really appreciate it. Unfortunately, I tested the exact opposite condition and that executed at the market open as well, where in this custom script MACD Diff was negative and KST was below the signal line. I inserted the script below this paragraph. Right now I am just testing out the code with 1 or 2 shares until I am able to confirm that the script is working properly. The code I used on a different order is below:

Code:
declare lower;

input rocLength1 = 10;
input rocLength2 = 15;
input rocLength3 = 20;
input rocLength4 = 30;

def sumRocLength = rocLength1+rocLength2+rocLength3+rocLength4;
input smaLength1 = 10;
input smaLength2 = 10;
input smaLength3 = 10;
input smaLength4 = 22;
input signal_length=9;
def ROC1 = RateOfChange(rocLength1, rocLength1, close);
def ROC2 = RateOfChange(rocLength2, rocLength2, close);
def ROC3 = RateOfChange(rocLength3, rocLength3, close);
def ROC4 = RateOfChange(rocLength4, rocLength4, close);

 
def RCMA1 =  Average(ROC1,smaLength1);
def RCMA2 =  Average(ROC2,smaLength2);
def RCMA3 =  Average(ROC3,smaLength3);
def RCMA4 =  Average(ROC4,smaLength4);

def KST = (RCMA1* 1) + (RCMA2* 2) + (RCMA3* 3) + (RCMA4 * 4);

def Signal_Line = Average(kst, signal_length);

def goodKST = KST < Signal_Line;

def d = MACDHistogram().diff;
def goodMACD = d < 0;

def sell1 = if goodKST and goodMACD then 1 else 0;

plot z1 = sell1;

Thank you very much for all of your help.
 
Hi @useThinkScript thank you very much for your response. I believe my issue was that I was using a pre-set conditional order template. I started from scratch and the order filled. Thank you very much for your help @useThinkScript and @Joshua.
In case this is helpful for anyone else, I believe the issue I was encountering was that I needed to set a start time for the conditional order to take place. If I did not set a start time for the conditional order to take place, and if I placed the conditional order before the market opened, then the order would execute at the market open no matter if the conditions were met or not.
 
What happened that made you change your mind from your prior post?

My understanding is that it should still WAIT COND on the study condition regardless.

If you really want to get to the heart of it, do like a one share conditional order, completely from scratch, using this conditional setup:

JvyVMOL.png


There's no way for this to ever trigger legitimately. It should tell you, with absolute certainty, whether or not it's just triggering in error at the open.

Don't discount the possibility that conditional orders might be a little bit schwabbed up at the moment either. You might want to contact support and ask if there's been any issues lately.

Also, given that you mentioned pre-set orders in your prior post, I assume you mean a saved order template that you access from "Buy Custom" in the right-click menu? In that case, and this is just a wild guess, but it might have something to do with this:

fr8ey0a.png


Did you maybe click the checkbox a long time ago and forget that it works this way?

That's everything I can think of anyway, after this I am stumped.
Good luck.
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
512 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top