cancel order if condition on this bar is true

Questions about MultiCharts and user contributed studies.
bluepillrobot
Posts: 4
Joined: 09 Mar 2018
Contact:

cancel order if condition on this bar is true

Postby bluepillrobot » 06 Jan 2020

Hey,

I am trying to set up the following simple idea, but it seems there is no way to set a condition on the current bar.

The idea is a breakout entry with a stop buy order conditional on that the current close does not break below a certain level.

More specifically, say I am working on 5 min chart and the breakout level is the previous high, but the price should not fall below the previous low.

The code would be:

Code: Select all

Buy ("Entry") 100 shares next bar High stop;
This code would submit the order immediately. But how do I integrate the condition "if the current price < previous low" then cancel the order?

Kind regards
Domenico

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: cancel order if condition on this bar is true

Postby TJ » 06 Jan 2020

First, there is no such thing as a "Simple" idea.

Your description is muddy.
You have a complex idea, with multiple conditions. (If-then-else).
You need to rewrite your logic in step-by-step instructions.
Because the computer can only do one thing at a time, and you need to write out your logic in a manner the computer can understand.

Do this:
Write one analysis/condition per line. Only ONE per line.
Start a new line on the next condition/logic.

If you can do this, you can see your strategy more clearly. And allow people to help you more easily.

bluepillrobot
Posts: 4
Joined: 09 Mar 2018
Contact:

Re: cancel order if condition on this bar is true

Postby bluepillrobot » 06 Jan 2020

Ideally the logic would be like this:

Code: Select all

condition1 = low next bar > low; // how does the computer knows what the next bar it would be??? if condition1 then Buy ("Entry") 100 shares next bar High stop;
I need some alternative, i.e.

Code: Select all

Buy ("Entry") 100 shares next bar High stop; if low < low[1] and <there are active orders> then <cancel active orders>; // I am looking for a statement like this

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: cancel order if condition on this bar is true

Postby TJ » 06 Jan 2020

Let's start with some logic basics:

Let's look at "Now".
We are at the current bar.
When performing an analysis, we can only be at the current bar.
When performing an analysis, we can only compare the current situation with what has happened in the past.
Anything in the future is not analysis, it is wishful thinking.

When you are saying
condition1 = low next bar > low

You need to shift your time orientation one bar forward to "Now".
What you actually want to do is
condition1 = if the current price is LOWER than the previous low . . . then do something.

User avatar
Anna MultiCharts
Posts: 560
Joined: 14 Jul 2017
Has thanked: 42 times
Been thanked: 141 times

Re: cancel order if condition on this bar is true

Postby Anna MultiCharts » 16 Mar 2020

Hello bluepillrobot,
But how do I integrate the condition "if the current price < previous low" then cancel the order?
There’re no special commands to cancel an order on the broker. An order gets cancelled by the strategy as soon the conditions for order generation stop being met.

You need to keep this in mind when creating a strategy.
For example, you need your order to be cancelled under the following condition:

Code: Select all

condition1 = if the current price is LOWER than the previous low . . . then do something ---- if close < low[1] then
You need to reverse the code so that is places an order in all other situations:

Code: Select all

if close >= low[1] then begin Buy ("Entry") Con shares next bar High stop; end;
So when this condition is not met, it will exactly the case when the order needs to be canceled:

Code: Select all

if close < low[1] then
And the order will be cancelled.


Return to “MultiCharts”