Buy Next Bar at Price Limit

Questions about MultiCharts and user contributed studies.
Urzhumtr
Posts: 2
Joined: 04 Oct 2023

Buy Next Bar at Price Limit

Postby Urzhumtr » 04 Oct 2023

Hello,
I probably have a stupid question but I cant figure out how to keep buy limit order active over multiple bars in my code.
I have a basic set of conditions (i.e. condition1 = (Low - High[2])>=FVG_Size; condition2= (Time > StartTime) and (Time <= EndTime);
which when are true allow me to assign low price of the current bar (i.e. Low[0]) to a VARIABLE.
This variable is the limit price at which I would like the code to buy. The issue is, when I use ' if condition1 and condition2 then buy next bar at VARIABLE limit;' the code only shows fills if the next bar hits the limit NOT any other subsequent bars. If for example the limit price is not reached by the next bar but instead is hit 2 bars after, then there is no entry.
So I guess, I am trying to understand how to write a line/piece of code that would submit buy at limit order that is active until the limit is reached (even after 10 bars for example).

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

Re: Buy Next Bar at Price Limit

Postby TJ » 04 Oct 2023

You need to transfer the "TRUE" condition over to multiple bars.
To do that, you can create a new additional condition called BUY_OK.

eg.

Code: Select all

Var: BUY_OK (false); BUY_OK = condition1 and condition2; if BUY_OK then BUY . . .

Urzhumtr
Posts: 2
Joined: 04 Oct 2023

Re: Buy Next Bar at Price Limit

Postby Urzhumtr » 04 Oct 2023

Thank TJ, but in my code I already have an explicit statement with conditions such as:

if time >= StartTime and (EntriesToday(date) < dailytradeslimit) and condition1 and condition2 and First_Bullish_FVG_Occured=1 then buy next bar at FVG_High1 limit;

The conditions and FVG_High are written as below:

// Conditions for Bullish FVG
condition1 = (Low - High[2])>=FVG_Size;
condition2= (Time > StartTime) and (Time <= EndTime);

if condition1 and condition2 then begin
FVG_High=low[0];
First_Candle_Low=low[2];
First_Bullish_FVG_Occured = First_Bullish_FVG_Occured+1;
end;

So my issue is that when all of the above conditions are met, the code only shows entry on the next bar.... not if price hits the level after 3 bars for instance. Below are examples. Yellow crosses indicate when conditions are met

https://ibb.co/KWN0BJB
https://ibb.co/JxjXWQs

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

Re: Buy Next Bar at Price Limit

Postby TJ » 04 Oct 2023

How to post codes
see posts #1 & #2
viewtopic.php?t=11713

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

Re: Buy Next Bar at Price Limit

Postby TJ » 05 Oct 2023



Return to “MultiCharts”