sell shares at current bar vs next bar

Questions about MultiCharts and user contributed studies.
KhaosTrader
Posts: 186
Joined: 10 May 2012
Has thanked: 14 times
Been thanked: 11 times

sell shares at current bar vs next bar

Postby KhaosTrader » 18 Aug 2012

Hi,

I have this code

Code: Select all

Sell("Exit L200-CS200 Target") 100 Shares Next Bar at (EntryPrice + t2) Limit;
but i dont want to have to wait until the next bar to execute the sale, if it hits the target on the current bar, i would like to sell it then.. how do I change the code properly?

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: sell shares at current bar vs next bar

Postby TJ » 18 Aug 2012

Hi,

I have this code

Code: Select all

Sell("Exit L200-CS200 Target") 100 Shares Next Bar at (EntryPrice + t2) Limit;
but i dont want to have to wait until the next bar to execute the sale, if it hits the target on the current bar, i would like to sell it then.. how do I change the code properly?
look up

intrabarordergeneration


https://www.multicharts.com/trading-sof ... /Main_Page

KhaosTrader
Posts: 186
Joined: 10 May 2012
Has thanked: 14 times
Been thanked: 11 times

Re: sell shares at current bar vs next bar

Postby KhaosTrader » 18 Aug 2012

ok thanks the information, but i still have an issue to make it work.

When I enter I want the next bar, but when exiting it can be the current bar (since current bar is the bar where I entered.

Here is some example code, I tried to use barstatus...

Code: Select all

if MarketPosition = 0 and time>1000 and (time <1600) then begin

If Low > Low[1] and High > High[1] then begin
if barstatus(1) = 2 then Buy ("Enter Long") 300 Shares Next Bar At (High+buypoint) stop;

end;

....
....
....

if CurrentShares = 100 then begin
Sell("Exit L300-CS100 Target") 100 Shares next Bar at (EntryPrice + t3) Limit;
Sell("Exit L300-CS100 Stop") 100 Shares next Bar at st3 Stop;
end;

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: sell shares at current bar vs next bar

Postby TJ » 18 Aug 2012

ok thanks the information, but i still have an issue to make it work.

When I enter I want the next bar, but when exiting it can be the current bar (since current bar is the bar where I entered.

Here is some example code, I tried to use barstatus...

Code: Select all

if MarketPosition = 0 and time>1000 and (time <1600) then begin

If Low > Low[1] and High > High[1] then begin
if barstatus(1) = 2 then Buy ("Enter Long") 300 Shares Next Bar At (High+buypoint) stop;

end;

....
....
....

if CurrentShares = 100 then begin
Sell("Exit L300-CS100 Target") 100 Shares next Bar at (EntryPrice + t3) Limit;
Sell("Exit L300-CS100 Stop") 100 Shares next Bar at st3 Stop;
end;
You are on the right track...

set IOG [intrabarordergeneration = true]
enter on barstatus = 2
exit on market


It will take a bit experimentation to get everything to fall in the right place.

KhaosTrader
Posts: 186
Joined: 10 May 2012
Has thanked: 14 times
Been thanked: 11 times

Re: sell shares at current bar vs next bar

Postby KhaosTrader » 19 Aug 2012

Ok I ran into a roadblock, so.. I want to enter using next bar, but possibly exit this bar (since this bar is the next bar). So I changed the code, and noticed that buy 100 shares next bar at the high of the current bar wont trigger a buy ever....

Here is the code

Code: Select all

[intrabarordergeneration = true]

If Low > Low[1] and High > High[1] then begin
if barstatus(1) = 2 then Buy ("Enter Long") 300 Shares Next Bar At (High) stop;

end;

....
....
....

if CurrentShares = 100 then begin
Sell("Exit L300-CS100 Target") 100 Shares next Bar at (EntryPrice) Limit;
Sell("Exit L300-CS100 Stop") 100 Shares next Bar at st3 Stop;
end;

KhaosTrader
Posts: 186
Joined: 10 May 2012
Has thanked: 14 times
Been thanked: 11 times

Re: sell shares at current bar vs next bar

Postby KhaosTrader » 19 Aug 2012

oops, sorry after running the code, here is the problem..

It seems that it can enter on the next bar, but then it only exits 100 shares max per bar, i am not sure why...

example code:


Code: Select all

[IntrabarOrderGeneration = true]
if MarketPosition = 0 and barstatus(1) = 2 and Low > Low[1] and High > High[1] then begin

Print("This is the closing tick of the bar.");
print ("this is buyTrigger = "+ NumToStr(buyTrigger ,0));
print ("timea = " + NumToStr(Time,0));


Buy ("Enter Long") 300 Shares Next Bar At high stop;


end;





// manage open orders

if MarketPosition = 1 then begin


st1 = EntryPrice - (stopsize * TickSize);
st2 = iff(BE2 = 1, EntryPrice, EntryPrice-(stopsize * TickSize));
st3 = iff(BE3 = 1, EntryPrice, EntryPrice-(stopsize * TickSize));

print ("this is ticksize = "+ NumToStr(ticksize ,2));
print ("this is enter = "+ NumToStr(entryprice ,2));
print ("this is stop = "+ NumToStr(st1 ,2));
print ("this is stopsize = "+ NumToStr(stopsize ,2));

if CurrentShares = 100 then begin
Sell("Exit L300-CS100 Target") 100 Shares next Bar at (EntryPrice + t3) Limit;
Sell("Exit L300-CS100 Stop") 100 Shares next Bar at st3 Stop;
end;


if CurrentShares = 200 then begin
Sell("Exit L200-CS200 Target") 100 Shares Next Bar at (EntryPrice + t2) Limit;
Sell("Exit L200-CS200 Stop") 100 Shares Next Bar at st2 Stop;
Sell("Exit L300-CS200 Target") 100 Shares Next Bar at (EntryPrice + t3) Limit;
Sell("Exit L300-CS200 Stop") 100 Shares Next Bar at st3 Stop;
end;

if CurrentShares = 300 then begin
Sell("Exit L100-CS300 Target") 100 Shares Next Bar at (EntryPrice + t1) Limit;
Sell("Exit L100-CS300 Stop") 100 Shares Next Bar at st1 Stop;
Sell("Exit L200-CS300 Target") 100 Shares Next Bar at (EntryPrice + t2) Limit;
Sell("Exit L200-CS300 Stop") 100 Shares Next Bar at st2 Stop;
Sell("Exit L300-CS300 Target") 100 Shares Next Bar at (EntryPrice + t3) Limit;
Sell("Exit L300-CS300 Stop") 100 Shares Next Bar at st3 Stop;
end;

end;

KhaosTrader
Posts: 186
Joined: 10 May 2012
Has thanked: 14 times
Been thanked: 11 times

Re: sell shares at current bar vs next bar

Postby KhaosTrader » 19 Aug 2012

Here is the problem, it should have exited all 300 shares on the bar that it opened the position...

BarStatusProblem.png

KhaosTrader
Posts: 186
Joined: 10 May 2012
Has thanked: 14 times
Been thanked: 11 times

Re: sell shares at current bar vs next bar

Postby KhaosTrader » 19 Aug 2012

BarStatusProblem.png
(38.06 KiB) Downloaded 1059 times
Here is a chart of the trades..


Here are inputs and vars, of the code, so u can see how i get t1, t2, t3

Code: Select all

inputs:

target1 (10),
target2(20),
target3(30),
stopsize(200),
buyCushion (.20),
BE2(0) , // 0=false, 1 = true
BE3(0); // 0=false, 1 = true

vars:
TickSize (MinMove/PriceScale),
smav (0),
emav (0),
hmav(0),
t1 (target1*TickSize),
t2 (target2*TickSize),
t3 (target3*TickSize),
st1 (0),
st2 (0),
st3 (0),
buyTrigger(0);

KhaosTrader
Posts: 186
Joined: 10 May 2012
Has thanked: 14 times
Been thanked: 11 times

Re: sell shares at current bar vs next bar

Postby KhaosTrader » 19 Aug 2012

Found the solution i have to check "Allow unlimited entries and exits per bar"

is there a way to make this default? or a command I can put in the script to make it checked?


Thanks in advance

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 559 times

Re: sell shares at current bar vs next bar

Postby Andrew MultiCharts » 20 Aug 2012

Found the solution i have to check "Allow unlimited entries and exits per bar"

is there a way to make this default? or a command I can put in the script to make it checked?


Thanks in advance
Unfortunately there is no way this box can be checked by default when IOG is on.

PD Quig
Posts: 191
Joined: 27 Apr 2010
Location: San Jose
Has thanked: 67 times
Been thanked: 10 times

Re: sell shares at current bar vs next bar

Postby PD Quig » 02 Feb 2013

What causes this radio button ("Allow unlimited entries and exits per bar") to reset to the default ("Limit this signal to one entry and one exit per bar")?

I have been testing some IOG strategies the last few days that require unlimited exits. Every now and then I will find that this setting has reverted unexpectedly to the middle radio button selection. It does not appear to be based on running the compiler. What is the behavior per the design?

Is there any thought to enabling the setting of this parameter in the strategy itself?

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 559 times

Re: sell shares at current bar vs next bar

Postby Andrew MultiCharts » 06 Feb 2013

Technically it would be possible to add another parameter to set IOG mode from EL/PL scripts:

Code: Select all

[IntrabarOrderGeneration=true]
[IntrabarOrderGenerationMode=1]
Please leave us the feature request. Once it has enough votes we will consider it for implementation in future version and the status of the request will be updated respectively.


Return to “MultiCharts”