Issue stop intrabar using IOG

Questions about MultiCharts and user contributed studies.
waveslider
Posts: 222
Joined: 16 Oct 2011
Has thanked: 66 times
Been thanked: 20 times

Issue stop intrabar using IOG

Postby waveslider » 11 Apr 2013

Hello-
using the following test code I am trying to have a stop issued as soon as the order is filled. The stop is not issued until the bar is closed. Please advise.

Code: Select all

var:mp(0),dntarg(0),uptarg(0);
var:opencontracts(0);

if time>=630+barinterval and barstatus(1)=2 then begin
uptarg=h+.25;
dntarg=l-.25;
end;

[IntrabarOrderGeneration=true]
mp=marketposition;
opencontracts=(GetPositionQuantity( getsymbolname,getaccountid)) ;

if time>=630+barinterval
then begin

if mp <> -1
then begin
sellshort ("Sht") the next bar at uptarg limit;

end;

if mp <> 1
then begin
buy ("Lng") the next bar at dntarg limit;
end;


if mp=1 then Sell ("stoplong") from entry ("Lng") next bar entryprice-(1) stop;

if mp=-1 then Buy to cover ("stopshort") from entry ("Sht") next bar entryprice+(1) stop;

end;

[IntrabarOrderGeneration=false]
setexitonclose;

SUPER
Posts: 646
Joined: 03 Mar 2007
Has thanked: 106 times
Been thanked: 84 times

Re: Issue stop intrabar using IOG

Postby SUPER » 11 Apr 2013

remove [IntrabarOrderGeneration=false] from your code

waveslider
Posts: 222
Joined: 16 Oct 2011
Has thanked: 66 times
Been thanked: 20 times

Re: Issue stop intrabar using IOG

Postby waveslider » 11 Apr 2013

Thanks. I am new to IOG -
Is it possible to have only certain parts of the code IOG and the rest not? I would like to bracket off a portion to execute intrabar and the rest at the end of the bar.

User avatar
MAtricks
Posts: 789
Joined: 09 Apr 2012
Has thanked: 286 times
Been thanked: 288 times

Re: Issue stop intrabar using IOG

Postby MAtricks » 11 Apr 2013

Currently all of your orders are resting or intrabar Stop Market or Limit orders. Your code is built for this. All you need to do is change the wording around a little bit in whichever lines you'd like to be executed at the close of a bar. Which orders do you want intrabar and which do you want at the close?

waveslider
Posts: 222
Joined: 16 Oct 2011
Has thanked: 66 times
Been thanked: 20 times

Re: Issue stop intrabar using IOG

Postby waveslider » 11 Apr 2013

For these orders I would like them all to be intrabar, but if you wouldn't mind discussing how to make some orders at the close that would be awesome. I thought I could do that by just turning off IOG, but it looks like that is incorrect.
thnks

waveslider
Posts: 222
Joined: 16 Oct 2011
Has thanked: 66 times
Been thanked: 20 times

Re: Issue stop intrabar using IOG

Postby waveslider » 11 Apr 2013

Also -
How would this strategy be affected by a partial fill? Does the order quantity need to be adjusted on every tick (or contract filled) or will this be done automatically until the full order is filled? In this case there is a reversal of position, so I am wondering if there needs to be some position checking to make sure that the strategy is in line with the actual account.

User avatar
MAtricks
Posts: 789
Joined: 09 Apr 2012
Has thanked: 286 times
Been thanked: 288 times

Re: Issue stop intrabar using IOG

Postby MAtricks » 11 Apr 2013

First let's get your intrabar code correct. You don't need to specify this within the code. Use the strategy properties and select which intrabar feature you'd like through that. I've cleaned up your code:

Code: Select all


variables:
mp(0),
dntarg(0),
uptarg(0),
opencontracts(0);

opencontracts=(GetPositionQuantity( getsymbolname,getaccountid)) ;
mp=marketposition;

if time>=630+barinterval and barstatus(1)=2 then begin
uptarg=h+.25;
dntarg=l-.25;
end ;

if time>=630+barinterval then begin
if mp <= 0 then
sellshort ("Sht") next bar at uptarg limit;
if mp >= 0 then
buy ("Lng") next bar at dntarg limit;

if mp > 0 then
Sell ("stoplong") entry ("Lng") next bar entryprice-(1) stop;

if mp < 0 then
Buytocover ("stopshort") entry ("Sht") next bar entryprice+(1) stop;
end;

//instead of using setexitonclose use this:
if mp <> 0 then begin
sell this bar on close ;
buytocover this bar on close ;
end ;
Okay now we can talk about code at the bar's close. Intrabar orders are not created by adding [IntrabarOrderGeneration=true] to your code. it's how your execution is built. Read the execution lines out to yourself and think about what they're doing. See the lines that I replaced your Setexitonclose with? That's how you create a bar's closing order.

Is this all of the code or just a piece of it because converting the execution type will might need the rest if there's more.
Last edited by MAtricks on 12 Apr 2013, edited 3 times in total.

waveslider
Posts: 222
Joined: 16 Oct 2011
Has thanked: 66 times
Been thanked: 20 times

Re: Issue stop intrabar using IOG

Postby waveslider » 11 Apr 2013

Matricks-
This is just a small piece of code that is a representative of what I am doing in a strategy. Aside from the execution aspect, every calculation operates at the end of the bar. That is why I was hoping to just turn on IOG for the execution aspect.
I can't post the code, but do appreciate your advice.
Would I be looking at assigning intrabarpersist to all of my variables if I converted the whole code to IOG?

User avatar
MAtricks
Posts: 789
Joined: 09 Apr 2012
Has thanked: 286 times
Been thanked: 288 times

Re: Issue stop intrabar using IOG

Postby MAtricks » 11 Apr 2013

Since it's a piece of a larger code, I edited it again to keep your accountid lines.

waveslider
Posts: 222
Joined: 16 Oct 2011
Has thanked: 66 times
Been thanked: 20 times

Re: Issue stop intrabar using IOG

Postby waveslider » 11 Apr 2013

I modified the code to have it do what I am attempting (reversing the position at the high/low of a bar +/- a tick).
At this point, after being filled, the strat issues the stop order immediately but is not issuing the reversing limit order until the bar closes.

Code: Select all

variables:
mp(0),
dntarg(0),
uptarg(0) ;

mp=marketposition;

if time>=630+barinterval and barstatus(1)=2 then begin
uptarg=h+.25;
dntarg=l-.25;
end ;

if time>=630+barinterval then begin
if mp > -1 then
sellshort ("Sht") next bar at uptarg limit;
if mp < 1 then
buy ("Lng") next bar at dntarg limit;

if mp > 0 then
Sell ("stoplong") entry ("Lng") next bar entryprice-(1) stop;

if mp < 0 then
Buy to cover ("stopshort") entry ("Sht") next bar entryprice+(1) stop;
end;
Thanks for helping me understand

User avatar
MAtricks
Posts: 789
Joined: 09 Apr 2012
Has thanked: 286 times
Been thanked: 288 times

Re: Issue stop intrabar using IOG

Postby MAtricks » 11 Apr 2013

Test with stop markets instead of limits. After you have a working strat, convert it to limits if you want.

waveslider
Posts: 222
Joined: 16 Oct 2011
Has thanked: 66 times
Been thanked: 20 times

Re: Issue stop intrabar using IOG

Postby waveslider » 11 Apr 2013

In this case I am trying to learn about limit orders and IOG. Using stops is not appropriate. Do you know why a limit exit order would not be issued immediately after an order is filled, yet a stop order is issued immediately?

escamillo
Posts: 203
Joined: 25 Mar 2011
Has thanked: 23 times
Been thanked: 56 times

Re: Issue stop intrabar using IOG

Postby escamillo » 16 Apr 2013

.
Last edited by escamillo on 17 Nov 2014, edited 1 time in total.

waveslider
Posts: 222
Joined: 16 Oct 2011
Has thanked: 66 times
Been thanked: 20 times

Re: Issue stop intrabar using IOG

Postby waveslider » 16 Apr 2013

Thanks Escamillo-
When you say you keep them in separate documents - do you mean that you have one study that calculates whether a signal is activated, and then somehow send the green light to the execution study?

escamillo
Posts: 203
Joined: 25 Mar 2011
Has thanked: 23 times
Been thanked: 56 times

Re: Issue stop intrabar using IOG

Postby escamillo » 16 Apr 2013

,
Last edited by escamillo on 17 Apr 2013, edited 1 time in total.

waveslider
Posts: 222
Joined: 16 Oct 2011
Has thanked: 66 times
Been thanked: 20 times

Re: Issue stop intrabar using IOG

Postby waveslider » 16 Apr 2013

Would you mind posting any part that you can of the EODexit code that you have? It might greatly assist. Thanks


Return to “MultiCharts”