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)
Some easy language functions say: "This function can only be used in the evaluation of strategies." So I'm wondering how this functions can be replaced when the system start to work in a demo or in real money, specially the function marketposition.
Thanks.
Can you help answer these questions from other members on NexusFi?
what i found is the following:
say you have a position oped today and you want to close it next day at the open (use daily bars), then in a backtest i used the following line to do so:
if marketposition <> 0 then begin
buy next bar open;
sell next bar open;
end;
In live trading for some reason, this does not work and close of the position is not executed (even order are not created). May be i am doing smth wrong, not sure.
I think what you are seeing is normal behavior for backtest. Take a look at the two examples below.
In the first one, when the code runs on July 5 at bar close, the strategy thinks marketposition=0. So, on the open of the 6th, it does not try to exit the position opened at close of the 5th. But it does close position on open of 7th. That is correct behavior.
In the second one, when the code runs on July 5 at bar close, the strategy thinks marketposition=0. It does not recognize a position until it evaluates the bar on the 6th at close, at which point it sees the open position that was opened at the open on the 6th. So it does close position on open of 7th. Again, it seems to be correct.
Live trading should fire off orders the same way as shown in backtest.
Hopefully this makes sense.
If you experience something different, please post full code and chart showing what you think is odd/wrong. One thing you can do is put print(marketposition); statements in code and see when the marketposition is actually changing.
Kevin, i fully agree with the logic in your examples.
Somehow, your example 2 does not work in my case. I enter the position with the stop and then marketposition should be checked at the bar close and then it should be 1 and thus it should be closed next bar open, but it does not. I have no idea why it works in a backtest and does not work live. it might be related to order settings somehow. I will post the results when i figure this out.
Are you saying you run the exact code in backtest example 2, but get different results than what I show? Or are you saying it works the same as mine in backtest, but did not work live?
Yes.
and it is definitely smth wrong with the order placement rather than the startegy logic, since the strategy closes the position, but in live the order does not follow through somehow.