I’m having issues with converting some of my stops to only engage at the close of a bar…. I converted the strategy, but it won’t trade. Here’s one of my stops that I rewrote to only use the close:
if marketposition = 1 then
sell ( "L-D" ) next bar at Longstop stop ;
if marketposition = -1 then
buytocover ( "S-D" ) next bar at shortstop stop ;
I changed that code to this:
if marketposition = 1 and close < Longstop then
sell ( "L-D" ) this bar on close ;
if marketposition = -1 and close > shortstop then
buytocover ( "S-D" ) this bar on close ;
Am I doing something wrong? It won’t exit a trade and these are the only changes I made.
Orders not generating from code
- Dave Masalov
- Posts: 1712
- Joined: 16 Apr 2010
- Has thanked: 51 times
- Been thanked: 489 times
Re: Orders not generating from code
Hello MAtricks,
Apparently the conditions are not met. Please use Print keyword for debugging.
I would recommend to try the following signal with Intra-Bar Order Generation on:
Apparently the conditions are not met. Please use Print keyword for debugging.
I would recommend to try the following signal with Intra-Bar Order Generation on:
Code: Select all
if marketposition = 1 and close < Longstop then
sell ( "L-D" ) next bar on close;
if marketposition = -1 and close > shortstop then
buytocover ( "S-D" ) next bar on close;
Re: Orders not generating from code
Thanks for the reply.
I didn't have intra-bar order generation set to true because the whole idea of this test is because I do not want intra-bar orders to happen.
The code is from a strategy that I use regularly. It generates orders perfectly. When I change the 4 lines of code to force it to only use the close of the bar, the strategy places no orders.
... I just thought I was somehow missing something
I didn't have intra-bar order generation set to true because the whole idea of this test is because I do not want intra-bar orders to happen.
The code is from a strategy that I use regularly. It generates orders perfectly. When I change the 4 lines of code to force it to only use the close of the bar, the strategy places no orders.
... I just thought I was somehow missing something
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: Orders not generating from code
If you're referring to real-time behaviour (instead of backtest), keep in mind the following:The code is from a strategy that I use regularly. It generates orders perfectly. When I change the 4 lines of code to force it to only use the close of the bar, the strategy places no orders.
Source & more info.this bar on Close: Market order on the close of this bar, generally used for historical backtesting purposes only. This will not generate a market on close order.
There's a feature request to change that behaviour here, but it would be simpler to just change your code to something like:
Code: Select all
if marketposition = 1 and close < Longstop then
sell ( "L-D" ) next bar at market;
if marketposition = -1 and close > shortstop then
buytocover ( "S-D" ) next bar at market;
Btw, if you don't want orders to trigger intrabar but still want to trigger stop-losses intrabar, use BarStatus to achieve more control over an IOG strategy.
Re: Orders not generating from code
JoshM,
Thank you for your suggestions. I appreciate any help.
The fix was longstop[1] and shortstop[1] because this was calculated at the close of the bar, we had to look at the last bar instead of this bar
Thank you for your suggestions. I appreciate any help.
The fix was longstop[1] and shortstop[1] because this was calculated at the close of the bar, we had to look at the last bar instead of this bar