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)
In Multicharts, I'm having a problem getting a limit order to "stick" for more than one tick after sending, with IOG on/true. This is the same problem I've read about in a couple of other threads where the limit order is sent, cancelled, sent, cancelled, etc. after each tick. I have tried the suggestions but with no success.
I'm using a 1minute bar chart and trying to accomplish the following:
A. Evaluate OPEN tick of 1minute bar for buy or sell condition
i. Look back at the previous tick (closing tick of previous 1min bar) and compare to a variable to determine if buy or sell condition is TRUE
ii. If buy or sell condition = TRUE, then set buy or sell price to the calculatedprice variable
iii. Set "trade" variable to trigger a buy or sell in the trade execution routine.
B. Evaluate value of "trade" variable to determine if a buy or sell should be executed
i.Execute a buy or sell limit at buyprice or sellprice
I'm using the (barstatus(1)=0) code is so that the buyprice or sellprice, and the determination of whether to buy or sell, is set/made only once within the 1min bar and the condition will hold until next 1min bar open tick. This should prevent the constant submitting and cancelling of my limit order until executed. The problem is that even though the trade price is set and the trigger variable is set to buy or sell on the open tick of the 1min bar, the trade trigger variable still resets to zero on the next ticks outside of this "barstatus" routine. I'm not sure why this is happening since this part of the code should only be executed once in each 1min bar.
It seems like there is a simple explanation for this. Can anyone help with this? Example code follows:
if (barstatus(1) = 0) then begin // evaluate opening tick of 1min bar
If close[1] > pricevar[1] then begin //compare closing tick of previous bar to variable
buyprice=calculateprice; //set buyprice variable to calculated price variable
print("O bar # is", maxbarsback+currentbar," ",close[1]," ",buyprice); //for debugging
trade = 1; //set a trade trigger variable for a buy
end else
If close[1] < pricevar[1] then begin //compare closing tick of previous bar to variable
sellprice=calculatedprice; //set sellprice variable to calculated price variable
print("O bar # is", maxbarsback+currentbar," ",close[1]," ",sellprice); //for debugging
trade = -1; //set a trade trigger variable for a sell
end else
If close[1] = calculatedprice[1] then begin //set a trade trigger variable to neutral - no trade
trade=0;
end;
end;
//Following code is to execute a buy,sell, or no trade based on value of "trade" variable. The price for the limit order
//has been calculated in the previous code and the trade trigger variable has been set in previous code.
//My assumption here is that neither variable should change until the opening tick of next 1min bar, however
//when I look at the output window the "trade" variable is 1 or -1 on the first tick after 1min bar opening tick, and for
//all other ticks it goes to zero/0. See following code.
if trade=1 then begin //buy next tick if trade variable=1
buy ("B1")next bar at buyprice limit;
print(time,"trade=",trade," ",buyprice); //for debugging
end else
if trade = -1 then begin //sell next tick if trade variable=-1
sellshort ("S1") next bar at sellprice limit;
print(time,"trade=",trade," ",sellprice); //for debugging
end;
Can you help answer these questions from other members on NexusFi?
variables should be of type intrabarpersist when they can change their value during the bar. It could simply be that they are not holding the values correctly in your code and therefore the code assumes you changed an entry condition and cancels or re-sends orders.
If this doesn't work, I would suggest getting rid of the barstatus = 0 and keep track of a new bar in the code yourself.
I really don't understand why this works yet, but it works. I need to study up on the why though.
I used a dummy code to test this and the variable that I am using to trigger the trade now holds it's value every tick until reset at the open of the next bar, which is what I've been trying to accomplish. I have more work to do but it's a big relief to have made some progress and you've saved me a lot of time.
For future reference for anyone who runs into the same problem, my solution was basically the following: