Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
I am frustrated when unfilled limit or stop entry orders carry on to the next bar. It does not happen to often, but is quite troublesome when it does.
Therefore, I shall be very appreciative for programming help to ensure via strategy code so any unfilled entry position stop order / limit order is cancelled at the end of day, or bar, and does not carry to the next session.
Below are two entry instructions examples:
sellshort next bar at open next bar + .05 Limit;
if condition1 = true then buy next bar at currentbid limit;
Thank you in advance.
Tiforp
Can you help answer these questions from other members on NexusFi?
Multicharts will keep an order alive as along as the condition that triggered the order is valid. You can use this by adding a condition to your order that you set to false X bars after you set it to true. You could for example store the bar number when you want to issue the order in a variable (let's call it "longOrderBar"). Then check for the current bar being equal to this variable before you issue your order - this wouldn't require resetting the condition,
as it becomes false on subsequent bars.
After you kind reply I did try to write a working code, but obviously have missed certain key elements because it complies but does not execute any trades. Most probably I have missed out correctly completing the “CurrentBar” and “longOrderBar”:
It appears simple enough, but I cannot seem to make any progress!
My full code is included. Any help once again shall be greatly appreciate.
Thank you.
Inputs:
MyContracts (1 { Indicate number of contracts to trade}),
StartTime (900 { Designate valid intraday start-trading time}),
NumBarsP (5 { Number of bars since entry});
Variables:
longOrderBar (0 { To ensure any unfilled entry order is not carried to the next bar });
If ( Time = StartTime )and CurrentBar[0] = longOrderBar Then
Begin
SellShort("") MyContracts Contracts next bar at CurrentAsk Limit;
End;
{ --- Exit at N bars since entry --- }
If ( NumBarsP > 0 ) Then
Begin
If marketposition = -1 and BarsSinceEntry >= NumBarsP Then Buytocover("Stop") MyContracts contracts next bar at Market;
End;
you can use the print reserved word, to check the values of the variables in your code on every bar.
As I wrote above "You could for example store the bar number when you want to issue the order in a variable (let's call it "longOrderBar")." Your code doesn't store the bar number when you want to issue the order. That's what you will have to do first, before checking for CurrentBar = longOrderBar. Otherwise longOrderBar will have a value of 0. CurrentBar on the other hand will always be greater than 0 and in turn your condition will never be true and you would see no trade entries.
From looking at your code and under the condition that you are on time based intraday charts, checking for "( Time = StartTime )" should be true only once per day. Which would already limit the order to one bar.