sell this bar, not next bar, is that possible? - futures io
futures io futures trading



sell this bar, not next bar, is that possible?


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one KhaosTrader with 40 posts (4 thanks)
    2. looks_two Nicolas11 with 27 posts (24 thanks)
    3. looks_3 Bimi with 2 posts (2 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
      Best Posters
    1. looks_one Jura with 3 thanks per post
    2. looks_two Bimi with 1 thanks per post
    3. looks_3 Nicolas11 with 0.9 thanks per post
    4. looks_4 KhaosTrader with 0.1 thanks per post
    1. trending_up 17,238 views
    2. thumb_up 33 thanks given
    3. group 3 followers
    1. forum 68 posts
    2. attach_file 16 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • 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 and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

sell this bar, not next bar, is that possible?

(login for full post details)
  #1 (permalink)
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
 
Posts: 107 since Jan 2012
Thanks: 40 given, 21 received

Hi,

In Mikes Easylanguage video, he shows the following code:

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;

But the problem is, that it cant execute the sales on the current bar. So how can I make it so it uses "this bar" instead of "next bar"?

Thanks in advance.

Started this thread Reply With Quote

Can you help answer these questions
from other members on futures io?
Which kind of Blockvolume is visible? - order processing
Emini and Emicro Index
What blockvolume is visible? - order processing
NinjaTrader
Second Entry Indicator (Looking for testers/feedback)
NinjaTrader
SimplerOptions
Trading Reviews and Vendors
MACD line not plotting after change of plot order
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on futures io
Selling Options on Futures?
109 thanks
Battlestations: Show us your trading desks!
108 thanks
Rank your Futures vs Stocks trading priority
55 thanks
Want your NinjaTrader indicator created, free?
27 thanks
Whats this confusion with margins?
21 thanks
 
(login for full post details)
  #3 (permalink)
London
 
 
Posts: 118 since Mar 2010
Thanks: 42 given, 58 received



KhaosTrader View Post
Hi,

In Mikes Easylanguage video, he shows the following code:

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;

But the problem is, that it cant execute the sales on the current bar. So how can I make it so it uses "this bar" instead of "next bar"?

Thanks in advance.

you have to declare [intrabarordergeneration = true] at the beginning of your code

Reply With Quote
 
(login for full post details)
  #4 (permalink)
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
 
Nicolas11's Avatar
 
Posts: 1,071 since Aug 2011
Thanks: 2,232 given, 1,751 received

It is obvious for @Bimi, but I prefer to add this comment for the OP.

With the above instruction, the trade will be triggered the first time the condition is met within the bar. Possibly in the middle of the bar or even at the first tick.

It is not a "buy at close".

Nicolas

Envoyé depuis mon GT-I9100 avec Tapatalk

Visit my futures io Trade Journal Reply With Quote
The following 2 users say Thank You to Nicolas11 for this post:
 
(login for full post details)
  #5 (permalink)
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
 
Posts: 107 since Jan 2012
Thanks: 40 given, 21 received

Ok I did that, but i still have a problem, I want to enter using next bar, but possibly exit this 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

[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;

Started this thread Reply With Quote
 
(login for full post details)
  #6 (permalink)
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
 
Posts: 107 since Jan 2012
Thanks: 40 given, 21 received

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:



[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;

Started this thread Reply With Quote
 
(login for full post details)
  #7 (permalink)
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
 
Nicolas11's Avatar
 
Posts: 1,071 since Aug 2011
Thanks: 2,232 given, 1,751 received

In your the code posted above, we cannot see how t1, t2 and t3 are calculated. Are they inputs or calculated one way or another?

Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #8 (permalink)
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
 
Posts: 107 since Jan 2012
Thanks: 40 given, 21 received

Here are the trades on the chart...




// here is how t1,t2, and t3 is calculated...

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);

Started this thread Reply With Quote
 
(login for full post details)
  #9 (permalink)
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
 
Posts: 107 since Jan 2012
Thanks: 40 given, 21 received

Here is the code, in its entirety. I commented out shorting because I am wanting to get the long to work first...

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);


[IntrabarOrderGeneration = true]


// open new positions


if MarketPosition = 0 and barstatus(1) = 2 and Low > Low[1] and High > High[1] then begin
//and time>1000 and (time <1600)
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;

//SellShort("Enter Short") 300 Shares Next Bar at (Low-buypoint) 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));


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

print ("*********barstatus at exit commands = " + NumToStr(barstatus(1),0));

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 + t1) Limit;
Sell("Exit L200-CS300 Stop") 100 Shares Next Bar at st2 Stop;
Sell("Exit L300-CS300 Target") 100 Shares Next Bar at (EntryPrice + t1) Limit;
Sell("Exit L300-CS300 Stop") 100 Shares Next Bar at st3 Stop;
end;

end;

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));

if CurrentShares = 100 then begin
BuyToCover("Exit S300-CS100 Target") 100 Shares Next Bar at (EntryPrice - t3) Limit;
BuyToCover("Exit S300-CS100 Stop") 100 Shares Next Bar at st3 Stop;
end;


if CurrentShares = 200 then begin
BuyToCover("Exit S200-CS200 Target") 100 Shares Next Bar at (EntryPrice - t2) Limit;
BuyToCover("Exit S200-CS200 Stop") 100 Shares Next Bar at st2 Stop;
BuyToCover("Exit S300-CS200 Target") 100 Shares Next Bar at (EntryPrice - t3) Limit;
BuyToCover("Exit S300-CS200 Stop") 100 Shares Next Bar at st3 Stop;
end;

if CurrentShares = 300 then begin
BuyToCover("Exit S100-CS300 Target") 100 Shares Next Bar at (EntryPrice - t1) Limit;
BuyToCover("Exit S100-CS300 Stop") 100 Shares Next Bar at st1 Stop;
BuyToCover("Exit S200-CS300 Target") 100 Shares Next Bar at (EntryPrice - t2) Limit;
BuyToCover("Exit S200-CS300 Stop") 100 Shares Next Bar at st2 Stop;
BuyToCover("Exit S300-CS300 Target") 100 Shares Next Bar at (EntryPrice - t3) Limit;
BuyToCover("Exit S300-CS300 Stop") 100 Shares Next Bar at st3 Stop;
end;


end;

Started this thread Reply With Quote
 
(login for full post details)
  #10 (permalink)
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
 
Nicolas11's Avatar
 
Posts: 1,071 since Aug 2011
Thanks: 2,232 given, 1,751 received


Could you check the parameters below in the "Format" of your signal?


Visit my futures io Trade Journal Reply With Quote
The following 2 users say Thank You to Nicolas11 for this post:
 
(login for full post details)
  #11 (permalink)
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
 
Posts: 107 since Jan 2012
Thanks: 40 given, 21 received

Thanks, that made the entries all occur on 1 bar, but.... lol, its so funny, now ALL entries are on the bar, even if i put my target 3 to a huge amount and my stop to a huge amount, it should have some exits on other bars.....

I am really appreciative of your help...

Started this thread Reply With Quote
 
(login for full post details)
  #12 (permalink)
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
 
Nicolas11's Avatar
 
Posts: 1,071 since Aug 2011
Thanks: 2,232 given, 1,751 received

"now ALL entries are on the bar"

You mean: all exits?
Is it still the same code as above?
Could you post a chart showing the problem?

Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #13 (permalink)
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
 
Posts: 107 since Jan 2012
Thanks: 40 given, 21 received

Yes, ok here is the code, and below is the chart...



inputs:
target1 (50),
target2(100),
target3(500),
stopsize(120),
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);


[IntrabarOrderGeneration = true]


// open new positions


if MarketPosition = 0 and barstatus(1) = 2 and Low > Low[1] and High > High[1] then begin
//and time>1000 and (time <1600)
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+buypoint) stop;
Buy ("Enter Long") 300 Shares Next Bar At high stop;

//SellShort("Enter Short") 300 Shares Next Bar at (Low-buypoint) 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

print ("*********barstatus at exit commands = " + NumToStr(barstatus(1),0));

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 + t1) Limit;
Sell("Exit L200-CS300 Stop") 100 Shares Next Bar at st2 Stop;
Sell("Exit L300-CS300 Target") 100 Shares Next Bar at (EntryPrice + t1) Limit;
Sell("Exit L300-CS300 Stop") 100 Shares Next Bar at st3 Stop;
end;

end;

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));

if CurrentShares = 100 then begin
BuyToCover("Exit S300-CS100 Target") 100 Shares Next Bar at (EntryPrice - t3) Limit;
BuyToCover("Exit S300-CS100 Stop") 100 Shares Next Bar at st3 Stop;
end;


if CurrentShares = 200 then begin
BuyToCover("Exit S200-CS200 Target") 100 Shares Next Bar at (EntryPrice - t2) Limit;
BuyToCover("Exit S200-CS200 Stop") 100 Shares Next Bar at st2 Stop;
BuyToCover("Exit S300-CS200 Target") 100 Shares Next Bar at (EntryPrice - t3) Limit;
BuyToCover("Exit S300-CS200 Stop") 100 Shares Next Bar at st3 Stop;
end;

if CurrentShares = 300 then begin
BuyToCover("Exit S100-CS300 Target") 100 Shares Next Bar at (EntryPrice - t1) Limit;
BuyToCover("Exit S100-CS300 Stop") 100 Shares Next Bar at st1 Stop;
BuyToCover("Exit S200-CS300 Target") 100 Shares Next Bar at (EntryPrice - t2) Limit;
BuyToCover("Exit S200-CS300 Stop") 100 Shares Next Bar at st2 Stop;
BuyToCover("Exit S300-CS300 Target") 100 Shares Next Bar at (EntryPrice - t3) Limit;
BuyToCover("Exit S300-CS300 Stop") 100 Shares Next Bar at st3 Stop;
end;


end;

Started this thread Reply With Quote
 
(login for full post details)
  #14 (permalink)
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
 
Nicolas11's Avatar
 
Posts: 1,071 since Aug 2011
Thanks: 2,232 given, 1,751 received

I have the feeling that the code does exactly what you ask it to do.

 
Code
if CurrentShares = 300 then begin

print ("*********barstatus at exit commands = " + NumToStr(barstatus(1),0));

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 + t1) Limit;
Sell("Exit L200-CS300 Stop") 100 Shares Next Bar at st2 Stop;
Sell("Exit L300-CS300 Target") 100 Shares Next Bar at (EntryPrice + t1) Limit;
Sell("Exit L300-CS300 Stop") 100 Shares Next Bar at st3 Stop;
end;
Nicolas

Visit my futures io Trade Journal Reply With Quote
The following 2 users say Thank You to Nicolas11 for this post:
 
(login for full post details)
  #15 (permalink)
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
 
Posts: 107 since Jan 2012
Thanks: 40 given, 21 received

LOL, ooops... Sorry .. Yep that was the problem.

How do I make allow unlimited entries and exits per bar as default? is there a script command for that?

Thanks so much Nicholas!

Started this thread Reply With Quote
 
(login for full post details)
  #16 (permalink)
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
 
Nicolas11's Avatar
 
Posts: 1,071 since Aug 2011
Thanks: 2,232 given, 1,751 received

Without having checked, I would say that it is not possible to change the default setting, and that you have to check each time you add a strategy. But I may be wrong.

Nicolas

Visit my futures io Trade Journal Reply With Quote
The following user says Thank You to Nicolas11 for this post:
 
(login for full post details)
  #17 (permalink)
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
 
Posts: 107 since Jan 2012
Thanks: 40 given, 21 received

Ok. I will set it manually...

I am backtesting and am seeing sometimes it doesnt enter when it should here is the chart and the (sorta fixed) code




inputs:
target1 (50),
target2(100),
target3(300),
stopsize(75),
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);


[IntrabarOrderGeneration = true]


// open new positions


if MarketPosition = 0 and barstatus(1) = 2 and Low > Low[1] and High > High[1] then begin
//and time>1000 and (time <1600)
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+buypoint) stop;
Buy ("Enter Long") 300 Shares Next Bar At high stop;

//SellShort("Enter Short") 300 Shares Next Bar at (Low-buypoint) 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

print ("*********barstatus at exit commands = " + NumToStr(barstatus(1),0));

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;

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));

if CurrentShares = 100 then begin
BuyToCover("Exit S300-CS100 Target") 100 Shares Next Bar at (EntryPrice - t3) Limit;
BuyToCover("Exit S300-CS100 Stop") 100 Shares Next Bar at st3 Stop;
end;


if CurrentShares = 200 then begin
BuyToCover("Exit S200-CS200 Target") 100 Shares Next Bar at (EntryPrice - t2) Limit;
BuyToCover("Exit S200-CS200 Stop") 100 Shares Next Bar at st2 Stop;
BuyToCover("Exit S300-CS200 Target") 100 Shares Next Bar at (EntryPrice - t3) Limit;
BuyToCover("Exit S300-CS200 Stop") 100 Shares Next Bar at st3 Stop;
end;

if CurrentShares = 300 then begin
BuyToCover("Exit S100-CS300 Target") 100 Shares Next Bar at (EntryPrice - t1) Limit;
BuyToCover("Exit S100-CS300 Stop") 100 Shares Next Bar at st1 Stop;
BuyToCover("Exit S200-CS300 Target") 100 Shares Next Bar at (EntryPrice - t2) Limit;
BuyToCover("Exit S200-CS300 Stop") 100 Shares Next Bar at st2 Stop;
BuyToCover("Exit S300-CS300 Target") 100 Shares Next Bar at (EntryPrice - t3) Limit;
BuyToCover("Exit S300-CS300 Stop") 100 Shares Next Bar at st3 Stop;
end;


end;

Started this thread Reply With Quote
 
(login for full post details)
  #18 (permalink)
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
 
Nicolas11's Avatar
 
Posts: 1,071 since Aug 2011
Thanks: 2,232 given, 1,751 received

I think that the previous trade is not closed.
You are still long 100 contracts.

Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #19 (permalink)
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
 
Posts: 107 since Jan 2012
Thanks: 40 given, 21 received

your right, but i dont get it , i should have been stopped out... stop is 75 cents below entry or b/e

Started this thread Reply With Quote
 
(login for full post details)
  #20 (permalink)
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
 
Nicolas11's Avatar
 
Posts: 1,071 since Aug 2011
Thanks: 2,232 given, 1,751 received

When you ask the code to print TickSize, which value of TickSize does it print?

Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #21 (permalink)
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
 
Posts: 107 since Jan 2012
Thanks: 40 given, 21 received

Ok, I put the command : print ("ticksize = " + numtoStr(TickSize,2));

gives me:
ticksize = 0.01

Started this thread Reply With Quote
 
(login for full post details)
  #22 (permalink)
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
 
Nicolas11's Avatar
 
Posts: 1,071 since Aug 2011
Thanks: 2,232 given, 1,751 received

OK.
And what is the value of StopSize?
Not the one in your code.
But the one in the inputs of the strategy in MultiCharts "Format Signal".

Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #23 (permalink)
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
 
Posts: 107 since Jan 2012
Thanks: 40 given, 21 received

Here are the values

Started this thread Reply With Quote
 
(login for full post details)
  #24 (permalink)
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
 
Nicolas11's Avatar
 
Posts: 1,071 since Aug 2011
Thanks: 2,232 given, 1,751 received

Looks OK.
I cannot reproduce your problem on my computer, so it is difficult for me to help you.
I suggest that you replace all "at st1", "at st2" and "at st3" by "at EntryPrice-0.75" for long and "at EntryPrice+0.75" for long.
If it works, try to put again your current code, but step by step:
Begin with "at EntryPrice-75*TickSize"
Then more and more sophisticated until you understand at which step the problem appear.

Visit my futures io Trade Journal Reply With Quote
The following 2 users say Thank You to Nicolas11 for this post:
 
(login for full post details)
  #25 (permalink)
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
 
Posts: 107 since Jan 2012
Thanks: 40 given, 21 received

ok i will do what you are suggesting, thanks again for your great help Nicolas

Started this thread Reply With Quote
The following 2 users say Thank You to KhaosTrader for this post:
 
(login for full post details)
  #26 (permalink)
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
 
Posts: 107 since Jan 2012
Thanks: 40 given, 21 received

it looks like the stop is not getting triggered, check this out... if i expand the chart..

Started this thread Reply With Quote
 
(login for full post details)
  #27 (permalink)
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
 
Nicolas11's Avatar
 
Posts: 1,071 since Aug 2011
Thanks: 2,232 given, 1,751 received

Please post the code. Otherwise, how could we analyze?

Visit my futures io Trade Journal Reply With Quote
The following user says Thank You to Nicolas11 for this post:
 
(login for full post details)
  #28 (permalink)
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
 
Posts: 107 since Jan 2012
Thanks: 40 given, 21 received

ok i hardcoded stops, and here is the code, and it should have entered in the circle area but it didnt




code:


inputs:
target1 (50),
target2(100),
target3(300),
stopsize(75),
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 (1),
st2 (1),
st3 (1),
buyTrigger(0);


[IntrabarOrderGeneration = true]


// open new positions


if MarketPosition = 0 and barstatus(1) = 2 and Low >= Low[1] and High >= High[1] then begin
//and time>1000 and (time <1600)
//Print("This is the closing tick of the bar.");
// print ("this is buyTrigger = "+ NumToStr(buyTrigger ,0));
// print ("timea = " + NumToStr(Time,0));

print ("ticksize = " + numtoStr(TickSize,2));

//Buy ("Enter Long") 300 Shares Next Bar At (High+buypoint) stop;
Buy ("Enter Long") 300 Shares Next Bar At high stop;

//SellShort("Enter Short") 300 Shares Next Bar at (Low-buypoint) 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 (EntryPrice-1) 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 (EntryPrice-1) Stop;
Sell("Exit L300-CS200 Target") 100 Shares Next Bar at (EntryPrice + t3) Limit;
Sell("Exit L300-CS200 Stop") 100 Shares Next Bar at (EntryPrice-1) Stop;
end;

if CurrentShares = 300 then begin

print ("*********barstatus at exit commands = " + NumToStr(barstatus(1),0));

Sell("Exit L100-CS300 Target") 100 Shares Next Bar at (EntryPrice + t1) Limit;
Sell("Exit L100-CS300 Stop") 100 Shares Next Bar at (EntryPrice-1) Stop;
Sell("Exit L200-CS300 Target") 100 Shares Next Bar at (EntryPrice + t2) Limit;
Sell("Exit L200-CS300 Stop") 100 Shares Next Bar at (EntryPrice-1) Stop;
Sell("Exit L300-CS300 Target") 100 Shares Next Bar at (EntryPrice + t3) Limit;
Sell("Exit L300-CS300 Stop") 100 Shares Next Bar at (EntryPrice-1) Stop;
end;

end;

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));

if CurrentShares = 100 then begin
BuyToCover("Exit S300-CS100 Target") 100 Shares Next Bar at (EntryPrice - t3) Limit;
BuyToCover("Exit S300-CS100 Stop") 100 Shares Next Bar at st3 Stop;
end;


if CurrentShares = 200 then begin
BuyToCover("Exit S200-CS200 Target") 100 Shares Next Bar at (EntryPrice - t2) Limit;
BuyToCover("Exit S200-CS200 Stop") 100 Shares Next Bar at st2 Stop;
BuyToCover("Exit S300-CS200 Target") 100 Shares Next Bar at (EntryPrice - t3) Limit;
BuyToCover("Exit S300-CS200 Stop") 100 Shares Next Bar at st3 Stop;
end;

if CurrentShares = 300 then begin
BuyToCover("Exit S100-CS300 Target") 100 Shares Next Bar at (EntryPrice - t1) Limit;
BuyToCover("Exit S100-CS300 Stop") 100 Shares Next Bar at st1 Stop;
BuyToCover("Exit S200-CS300 Target") 100 Shares Next Bar at (EntryPrice - t2) Limit;
BuyToCover("Exit S200-CS300 Stop") 100 Shares Next Bar at st2 Stop;
BuyToCover("Exit S300-CS300 Target") 100 Shares Next Bar at (EntryPrice - t3) Limit;
BuyToCover("Exit S300-CS300 Stop") 100 Shares Next Bar at st3 Stop;
end;


end;

Started this thread Reply With Quote
 
(login for full post details)
  #29 (permalink)
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
 
Nicolas11's Avatar
 
Posts: 1,071 since Aug 2011
Thanks: 2,232 given, 1,751 received

Please use the [ CODE] tags around your code next time.

I still cannot reproduce the problem on my side.

And the problem seems to evolve on your side.
On your last screenshot, the problem does not seem linked to stops, since the last trade was correctly stopped. And you were flat afterwards.
This time, the issue seems that the strategy does not enter trade whereas it is supposed to.

Could you:
1. print the time and the value of CurrentShares at each candle in order to check that you are flat when you are supposed to be flat?
 
Code
print(Date:8:0," ", Time:4:0, " --> CurrentShares = ", CurrentShares);
2. delete "and BarStatus(1) = 2"

Any improvement?

Nicolas

Visit my futures io Trade Journal Reply With Quote
The following user says Thank You to Nicolas11 for this post:
 
(login for full post details)
  #30 (permalink)
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
 
Posts: 107 since Jan 2012
Thanks: 40 given, 21 received

Nicolas,

I need the " BarStatus(1) = 2" because I want to enter on the next bar on the break of the prior bar high...

I entered the
print(Date:8:0," ", Time:4:0, " --> CurrentShares = ", CurrentShares);

But I cant decipher the time, is it possible to put the # of shares held Below the bar itself?

Another approach to this whole thing would be to use a 1 minute chart, then what I would do is somehow get the high and the low of the rounded last hour bar... Then if it breaks above that in the next hour it would be a long. That would be the best way.

So that way, I would do the following: I would need a function that would get me the highest high and lowest low of the stock during the rounded hour timeframe: 10:00am to 10:59am , 11:00am to 11:59 am. then I can enter on next bar, and do a lot more elegant stop strategies... Do you know how i can write such a function that can do that?

Thanks,

Jeff

Started this thread Reply With Quote
 
(login for full post details)
  #31 (permalink)
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
 
Posts: 107 since Jan 2012
Thanks: 40 given, 21 received

What it would do is create a high and a low horizontal trendline for the next hour... and it would keep doing that moving forward

so each prior rounder prior hour would have a high and a low price, and then it would create a trend line for the next hour's worth of bars so u can see if it is breaking the high or the low of the prior hour.. That way I would have the power of using hour bars to determine entry prices and i can use 1 minute bars to determine exit strategy.

Started this thread Reply With Quote
 
(login for full post details)
  #32 (permalink)
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
 
Nicolas11's Avatar
 
Posts: 1,071 since Aug 2011
Thanks: 2,232 given, 1,751 received

@KhaosTrader,

1. The 1-min workaround is another story. I think that we first need to solve what happens with the 1-hour bar.

2. "I cant decipher the time". I do not understand. Could you show me an example of what is printed?
On my side, it is rather clear:

Quoting 
At 1120817 1600 CurrentShares = 300.00

3. "Is it possible to put the # of shares held Below the bar itself?"
Yes.
 
Code
Value1 = Text_New(Date, Time, Low-TickSize, NumToStr(CurrentShares, 0));
EDIT: This works for MultiCharts. I do not know for TradeStation.

4. "I need the " BarStatus(1) = 2" because I want to enter on the next bar on the break of the prior bar high..."
I am lost.
In the first message, I have the feeling that you wanted exactly the contrary: enter within a bar.
If you want to enter right at the opening of the next bar when a condition is met, you shall not use [intrabarordergeneration = true]
Please clarify.

Nicolas

Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #33 (permalink)
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
 
Posts: 107 since Jan 2012
Thanks: 40 given, 21 received

1) ok I understand

2) 1120817 , how is this translated into time?

3) ok i put that in the code, and i have enclosed screenshot

4) i want to enter in the next bar, once it breaks the high of the prior bar , but I want to be able to exit if my target is met on the same bar that I entered....


Started this thread Reply With Quote
 
(login for full post details)
  #34 (permalink)
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
 
Posts: 107 since Jan 2012
Thanks: 40 given, 21 received

ah the date format i get now.. 1120817 1600 , 1600 is the hour, and the other part is the date, got it

Started this thread Reply With Quote
 
(login for full post details)
  #35 (permalink)
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
 
Nicolas11's Avatar
 
Posts: 1,071 since Aug 2011
Thanks: 2,232 given, 1,751 received

For the date, do not forget that 112 means 2012 in Easy Language (add 1900).

The text printing on the chart is OK. We see the "0". When the trade lasts on several bars, you should see 300, 200, 100. If you want to change the color or the size:
 
Code
Value1 = Text_New(Date, Time, Low-TickSize, NumToStr(CurrentShares, 0));
Text_SetColor(Value1, blue);
Text_SetSize(Value1, 14);
I have to make a break. I will come back later.

Visit my futures io Trade Journal Reply With Quote
The following user says Thank You to Nicolas11 for this post:
 
(login for full post details)
  #36 (permalink)
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
 
Posts: 107 since Jan 2012
Thanks: 40 given, 21 received

Ok thanks Nicolas, I am here whenever you are ready .

Thanks again for your help

Started this thread Reply With Quote
 
(login for full post details)
  #37 (permalink)
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
 
Nicolas11's Avatar
 
Posts: 1,071 since Aug 2011
Thanks: 2,232 given, 1,751 received

@KhaosTrader,

Could you confirm your condition to enter long ? Is it what follows?

If "Low >= Low[1] and High >= High[1]" then enter at any moment within the next bar when the price reaches the High of the current bar.

Nicolas

Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #38 (permalink)
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
 
Nicolas11's Avatar
 
Posts: 1,071 since Aug 2011
Thanks: 2,232 given, 1,751 received

@KhaosTrader,

If I have correctly understood what you are trying to do, this is not straight-forward.
I have myself struggled with it for a long time.
So thanks for your question, since it allows me clarifying things in my mind.
But the negative side is... I may be wrong!

You want the exits (stop-loss or profit target) to possibly occur on the same bar as the entry.
I think this requires [intrabarordergeneration = true].

But [IntrabarOrderGeneration = true] has a negative side effect: the condition for the entry is checked at any moment within the current bar. But you want the condition to be checked only at bar close. So there is your BarStatus = 2.

So... I'm OK with your code.

It remains that you have some problem.

I advise that you simplify your code to the simplest. For me, the simplest form is 10 lines:
 
Code
Variables:
	TickSize	( MinMove / PriceScale );

[IntrabarOrderGeneration = true]

if MarketPosition = 0 and BarStatus = 2 and Low >= Low[1] and High >= High[1] then begin
	Buy ("Enter Long") 300 Shares Next Bar At high stop;
end;

if MarketPosition = 1 then begin
	Sell("Profit Target") 300 Shares next Bar at (EntryPrice + 0.0003) Limit;
	Sell("Stop Loss") 300 Shares next Bar at (EntryPrice - 0.0003) Stop;
end;
Does it work? If yes, add the sophistications one by one until the problem appears.

Nicolas

Visit my futures io Trade Journal Reply With Quote
The following user says Thank You to Nicolas11 for this post:
 
(login for full post details)
  #39 (permalink)
The Netherlands
 
Experience: None
Platform: MultiCharts, TradingView
Trading: ...
 
Jura's Avatar
 
Posts: 774 since Apr 2010
Thanks: 2,347 given, 688 received


Nicolas11 View Post
If I have correctly understood what you are trying to do, this is not straight-forward.
I have myself struggled with it for a long time.
So thanks for your question, since it allows me clarifying things in my mind.
But the negative side is... I may be wrong!

You want the exits (stop-loss or profit target) to possibly occur on the same bar as the entry.
I think this requires [intrabarordergeneration = true].

But [IntrabarOrderGeneration = true] has a negative side effect: the condition for the entry is checked at any moment within the current bar. But you want the condition to be checked only at bar close. So there is your BarStatus = 2.

I think you're right.

If one uses BarStatus = 2 with 'buy next bar', the order will be executed on the first tick of the next bar (assuming it's a market order, otherwise it will be cancelled). With IntrabarOrderGeneration set on, the stop-loss for the same bar can be send on the second tick of the bar.

I can't say I understand the whole thread, but if I understand it correctly the enter stop orders need to be submitted for the whole duration of the next bar? If so, you'll need to use a true/false value to keep continue submitting the stop order for the next bar.

Because with IntrabarOrderGeneration next bar actually means next tick, the enter stop needs to be resubmitted. Otherwise, if the enter stop conditions aren't triggered on the first tick of the next bar, the order is cancelled.

Such a thing could look like:

 
Code
[intrabarordergeneration = true]

// On bar close
if (BarStatus(1) = 2) then begin 

	// Calculate long/short entries
	enterLong = ... 
	enterShort = ...
	
	// Calculate stop here (if needed)
	stop1 = ...
	
end;


// On every tick, submit entry stop
if (MarketPosition = 0) then begin

	if (enterLong = true) then
		// submit order for next bar (= next tick)
			
	if (enterShort = true) then 
		// submit order for next bar
	
end;
	
// Manage stop-losses
if (MarketPosition = 1) then begin

	// Submit Long stop here

end

else if (MarketPosition = -1) then begin 

	// Submit Short stop here

end;

Reply With Quote
The following 3 users say Thank You to Jura for this post:
 
(login for full post details)
  #40 (permalink)
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
 
Posts: 107 since Jan 2012
Thanks: 40 given, 21 received

Ok,

I implemented the code you are suggesting.. I agree its a good idea to make it as simple as possible to figure out the problem.

Here is the chart with circled red where it should have entered on the bars with red underlines in the circle, code is below also...

I am showing with 5 min bar charts and 60 Min bar chart

5 MIN BARS




60 MIN BARS





I used 1 dollar hardcoded for entrypice and exit price, since i am trading aapl.





variables:
TickSize (MinMove/PriceScale);



[IntrabarOrderGeneration = true]


// open new positions


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



Value1 = Text_New(Date, Time, Low-TickSize, NumToStr(CurrentShares, 0));

// manage open orders

if MarketPosition = 1 then begin
Sell("Profit Target") 300 Shares Next Bar at (EntryPrice + 1) Limit;
Sell("Stop Loss") 300 Shares Next Bar at (EntryPrice-1) Stop;
end;

Started this thread Reply With Quote
 
(login for full post details)
  #41 (permalink)
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
 
Posts: 107 since Jan 2012
Thanks: 40 given, 21 received

sorry... the phrase "I used 1 dollar hardcoded for entrypice and exit price, since i am trading aapl."

should be " i used 1 dollar hardcoded from entry price for both stop and target since i am trading aapl"

Started this thread Reply With Quote
 
(login for full post details)
  #42 (permalink)
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
 
Posts: 107 since Jan 2012
Thanks: 40 given, 21 received

Here is a 1 minute chart that shows the problem.

Also I fixed up the print share size logic so it looks nicer on the chart, I also divided the share size by 3 so it shows it as one numeric digit...




 
Code
  variables:
  	TickSize (MinMove/PriceScale);
	
  	

  [IntrabarOrderGeneration = true]
  	
  	
 // open new positions


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

 
 Value1 = Text_New(Date, Time, Low-(5*TickSize), NumToStr(CurrentShares/100, 0));
 Text_SetColor(Value1, Blue);
Text_SetSize(Value1, 9);
 
 // manage open orders
 
 if MarketPosition = 1 then begin
   		Sell("Profit Target") 300 Shares Next Bar at (EntryPrice + 1) Limit;
   		Sell("Stop Loss") 300  Shares Next Bar at (EntryPrice-1) Stop;	
   	end;



Started this thread Reply With Quote
 
(login for full post details)
  #43 (permalink)
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
 
Nicolas11's Avatar
 
Posts: 1,071 since Aug 2011
Thanks: 2,232 given, 1,751 received

@KhaosTrader,

First, I managed to reproduce your problem, on the same chart (AAPL 1min July 26th, 2012).

From @Jura's post above, I understand that, when [IntrabarOrderGeneration = true], "at next bar" means "at next tick".
So the strategy was entering "at next bar" (in the common sense) only if the first tick of the next bar was above the High of the current one.
But you want to enter at any tick within "next bar" provided that this tick is above the High of the current one.

So you have to use @Jura's idea.
I have integrated it into our small code. See below. It seems to work. See picture.

I have learnt something. Thanks @Jura !

Nicolas

 
Code
Variables:
	TickSize	( MinMove / PriceScale ),
	enterlong	( false );

[IntrabarOrderGeneration = true]

if ( BarStatus(1) = 2 ) then begin 
	enterLong = ( Low >= Low[1] and High >= High[1] );
end;

if MarketPosition = 0 and enterlong then begin
	Buy ("Enter Long") 300 Shares Next Bar At high stop;
end;

if MarketPosition = 1 then begin
	Sell("Profit Target") 300 Shares next Bar at (EntryPrice + 1) Limit;
	Sell("Stop Loss") 300 Shares next Bar at (EntryPrice - 1) Stop;
end;

Visit my futures io Trade Journal Reply With Quote
The following user says Thank You to Nicolas11 for this post:
 
(login for full post details)
  #44 (permalink)
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
 
Nicolas11's Avatar
 
Posts: 1,071 since Aug 2011
Thanks: 2,232 given, 1,751 received

Actually, there is still something to be fixed in "at High stop". Should be "High or High[1]".

EDIT: in the below picture, the entry circled in blue shoud not exist.


More on this in the next message.

Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #45 (permalink)
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
 
Nicolas11's Avatar
 
Posts: 1,071 since Aug 2011
Thanks: 2,232 given, 1,751 received

In the last code, we have:
 
Code
if MarketPosition = 0 and enterlong then begin
	Buy ("Enter Long") 300 Shares Next Bar at High stop;
end;
"at High stop" is correct when the above 3-line block of code is read on the last tick of the current bar.
But if these lines are read at a tick within the next bar (supposed to be the entry bar), should be "at High[1] stop".

I think that it could be corrected as follows:
 
Code
Variables:
	TickSize	( MinMove / PriceScale ),
	EnterLong	( false ),
	PriceForEntry ( 0 );

[IntrabarOrderGeneration = true]

if ( BarStatus(1) = 2 ) then begin 
	EnterLong = ( Low >= Low[1] and High >= High[1] );
	PriceForEntry = High;
end;

if MarketPosition = 0 and EnterLong then begin
	Buy ("Enter Long") 300 Shares next Bar at PriceForEntry stop;
end;

if MarketPosition = 1 then begin
	Sell("Profit Target") 300 Shares next Bar at (EntryPrice + 1) Limit;
	Sell("Stop Loss") 300 Shares next Bar at (EntryPrice - 1) Stop;
end;

Visit my futures io Trade Journal Reply With Quote
The following 2 users say Thank You to Nicolas11 for this post:
 
(login for full post details)
  #46 (permalink)
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
 
Posts: 107 since Jan 2012
Thanks: 40 given, 21 received

Nicolas,

Yes that is correct. It works now... You are correct that we need to store the PriceForEntry in a variable.... Thanks so much!


Because I would like to make sophisticated stops, it would be good to use a lower time frame chart, but use a higher time frame data for entries.

Yesterday I spoke of creating a high and a low for the complete hour and drawing a trendline on the chart for each next hour.. So if during 10am to 11am the highest tick was 610.20 and the lowest tick was 605.80 then we would have horizontal trendlines from 11am to 12am at 610.20 and 605.80. This would be a visual cue , but in fact the strategy would enter a trade long if it price broke above 610.20 and would enter short if it broke below 605.80. Then I can use the smaller time frame bars in the chart to manage the exit (do a trailing stop if i am in a long trade and it breaks the highest low of the last 2 bars or something).

Actually the existing strategy would look at the trendlines of the last 2 hours, to see if trendlines are higher high and lower low, and then if so , if the next hour breaks the high it enters long...

If you have time to code something like that, I would really appreciate it.

Started this thread Reply With Quote
 
(login for full post details)
  #47 (permalink)
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
 
Nicolas11's Avatar
 
Posts: 1,071 since Aug 2011
Thanks: 2,232 given, 1,751 received

@KhaosTrader,

1. You're welcome, but your thanks shall also be directed to @Jura: he solved the most difficult part.

2. Even if it is possible, I think that there is no need to use 2 timeframes to manage your strategy. With [intrabarordergeneration = true], you can manage what happens at all ticks in the bar.

3. "the strategy would enter a trade long if it price broke above 610.20 and would enter short if it broke below 605.80"
Do you mean that the strategy would enter long at any bar on a breakout (up) of last bar's High?
If yes, you can very easily adapt the above code. I do not see the problem.

4. Trendlines --> I first need to understand 3.

Nicolas

Visit my futures io Trade Journal Reply With Quote
The following user says Thank You to Nicolas11 for this post:
 
(login for full post details)
  #48 (permalink)
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
 
Posts: 107 since Jan 2012
Thanks: 40 given, 21 received

Nicolas,

Ok, lets do a walkthrough example:

9am to 10am Highest high was 505.20 Lowest Low was 502.30
10am to 11am Highest high was 506.20 Lowest Low was 503.50

Therefore, if we were in hourly chart we would see that the last bar offered a higher high and a higher low.

So if during the next hour, price rose above 503.20 we would enter long.

The reason why I would like to have lower time frame bars is because by looking at how bars are painted I can do more sophisticated stops. For example if i had 300 shares long, after it hit target 1, then i can implement an trailing stop where I would look at the last 3 five minute bars and if price fell below the lowest low of the last 3 bars then it would stop me out of the trade.

Therefore, I use the hourly highest high and lowest lows to determine if the trade is qualified to go long, and at what price, then I can use a lower time frame bar (for example, 5 minute bars) to implement a more agile and sophisticated stop strategy.

Started this thread Reply With Quote
 
(login for full post details)
  #49 (permalink)
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
 
Nicolas11's Avatar
 
Posts: 1,071 since Aug 2011
Thanks: 2,232 given, 1,751 received

"9am to 10am Highest high was 505.20"

What does "Highest High" mean?
The High of this 1-hour bar?

Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #50 (permalink)
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
 
Posts: 107 since Jan 2012
Thanks: 40 given, 21 received

Since we are using a 10 minute chart, it would look at the 6 bars from 9am to 10am and look for the highest and lowest price that the bars touched during that time.

9:10 Bar: High=500.10 Low = 500.00
9:20 Bar: High=500.50 Low = 498.10
9:30 Bar: High=502.10 Low = 500.10
9:40 Bar: High=501.10 Low = 499.22
9:50 Bar: High=505.20 Low = 500.20
10:00 Bar: High=505.20 Low = 501.20

The highest high = 505.20 and the Lowest low is 498.10 for the hour.

so then we would draw two horizontal trendlines (one at 505.20 and one at 498.10) that would span into the future from 10:10 to 11:00

Started this thread Reply With Quote
 
(login for full post details)
  #51 (permalink)
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
 
Posts: 107 since Jan 2012
Thanks: 40 given, 21 received

Thank you @Jura for your help on this! Much appreciated!

Started this thread Reply With Quote
The following user says Thank You to KhaosTrader for this post:
 
(login for full post details)
  #52 (permalink)
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
 
Nicolas11's Avatar
 
Posts: 1,071 since Aug 2011
Thanks: 2,232 given, 1,751 received

So...
Within all 10-min bars of a given hour (10:10-11:00), you want to see a trendline showing the High and Low of the previous hour (09:10-10:00).
Correct?

Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #53 (permalink)
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
 
Posts: 107 since Jan 2012
Thanks: 40 given, 21 received

Yes that is correct.

Started this thread Reply With Quote
 
(login for full post details)
  #54 (permalink)
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
 
Posts: 107 since Jan 2012
Thanks: 40 given, 21 received

The way I envision it is that the code will determine how many bars in the given time frame make up an hour, and then it will iterate through the bars to find the highest high and lowest low. That way the hourly code can work in different time scales, be it 1 min, 5 min, 10 min or 15 min...

Started this thread Reply With Quote
 
(login for full post details)
  #55 (permalink)
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
 
Nicolas11's Avatar
 
Posts: 1,071 since Aug 2011
Thanks: 2,232 given, 1,751 received

This is not related any more to the initial subject of this thread ("sell this bar").

So I suggest that you post this new request in the thread

I also suggest that, in the other thread, you use a brief description as your request. Not too far from:

Quoting 
Within all 10-min bars of a given hour (10:10-11:00), I would like to see a trendline showing the High and Low of the previous hour (09:10-10:00).

Nicolas

Visit my futures io Trade Journal Reply With Quote
The following user says Thank You to Nicolas11 for this post:
 
(login for full post details)
  #56 (permalink)
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
 
Posts: 107 since Jan 2012
Thanks: 40 given, 21 received

Ok sounds good. I will make the new post.

Started this thread Reply With Quote
 
(login for full post details)
  #57 (permalink)
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
 
Posts: 107 since Jan 2012
Thanks: 40 given, 21 received

Hi, I discovered a problem with the current implementation.

It is possible for there to be more than one entry in a given bar, that means that if in a given hourly bar, the code enters a trade and exits the trade at target, and its still moving up, it can enter the trade again. I would like the code to enter trades max 1 time per bar.

Should we add another condition to the if statement below in the code, where it can only execute an entry if price is within a certain range also?

 
Code
if MarketPosition = 0 and EnterLong then begin
	Buy ("Enter Long") 300 Shares next Bar at LongEntryPrice stop;
end;

Started this thread Reply With Quote
 
(login for full post details)
  #58 (permalink)
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
 
Posts: 107 since Jan 2012
Thanks: 40 given, 21 received

Another idea might be to identify the current bar time, and make sure it wont enter again on the same bar?

Started this thread Reply With Quote
 
(login for full post details)
  #59 (permalink)
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
 
Posts: 107 since Jan 2012
Thanks: 40 given, 21 received

Here is the chart where I point out the problem, and the code...



(I commented out the short entries because I want to make sure longs work first)

Code:

 
Code
Inputs:
	Target1 (50),
  	Target2(100),
  	Target3(200),
  	StopSize(75),
  	BuyGap(.20),
  	BE2(1) , // 0=false, 1 = true
  	BE3(1); // 0=false, 1 = true
  	
 Variables:
 	EnterLong	( false ),
	LongEntryPrice ( 0 ),
	ShortEntryPrice ( 0 ),
   	TickSize (MinMove/PriceScale),
  	t1 (target1*TickSize),
  	t2 (target2*TickSize),
  	t3 (target3*TickSize),
  	st1 (0),
  	st2 (0),
  	st3 (0);
 

[IntrabarOrderGeneration = true]

if ( BarStatus(1) = 2 ) then begin 
	EnterLong = ( Low >= Low[1] and High >= High[1] );
	LongEntryPrice = High;
	ShortEntryPrice = Low;
end;

if MarketPosition = 0 and EnterLong then begin
	Buy ("Enter Long") 300 Shares next Bar at LongEntryPrice stop;
	//SellShort("Enter Short") 300  Shares Next Bar at (ShortEntryPrice) stop;
end;


//Label # Shares below each bar
Value1 = Text_New(Date, Time, Low-(2), NumToStr(CurrentShares/100, 0));
Text_SetColor(Value1, Blue);
Text_SetSize(Value1, 9);


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));

	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;


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));

	if CurrentShares = 100 then begin
		BuyToCover("Exit S300-CS100 Target") 100 Shares next Bar at (EntryPrice - t3) Limit;
		BuyToCover("Exit S300-CS100 Stop") 100 Shares next Bar at st3 Stop;
	end;
	
	if CurrentShares = 200 then begin
   		BuyToCover("Exit S200-CS200 Target") 100 Shares Next Bar at (EntryPrice - t2) Limit;
   		BuyToCover("Exit S200-CS200 Stop") 100 Shares Next Bar at st2 Stop;	
   		BuyToCover("Exit S300-CS200 Target") 100 Shares Next Bar at (EntryPrice - t3) Limit;
   		BuyToCover("Exit S300-CS200 Stop") 100 Shares Next Bar at st3 Stop;	
   	end;
   	
   	if CurrentShares = 300 then begin
   		BuyToCover("Exit S100-CS300 Target") 100 Shares Next Bar at (EntryPrice - t1) Limit;
   		BuyToCover("Exit S100-CS300 Stop") 100 Shares Next Bar at st1 Stop;	
   		BuyToCover("Exit S200-CS300 Target") 100 Shares Next Bar at (EntryPrice - t2) Limit;
   		BuyToCover("Exit S200-CS300 Stop") 100 Shares Next Bar at st2 Stop;	
   		BuyToCover("Exit S300-CS300 Target") 100 Shares Next Bar at (EntryPrice - t3) Limit;
   		BuyToCover("Exit S300-CS300 Stop") 100 Shares Next Bar at st3 Stop;
   	end;
	
end;

Started this thread Reply With Quote
 
(login for full post details)
  #60 (permalink)
London
 
 
Posts: 118 since Mar 2010
Thanks: 42 given, 58 received

you need to create a time-line, and step your code through the time-line to make sure all the angles are covered.

Reply With Quote
 
(login for full post details)
  #61 (permalink)
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
 
Nicolas11's Avatar
 
Posts: 1,071 since Aug 2011
Thanks: 2,232 given, 1,751 received

@Bimi, could you kindly elaborate a little? Sounds interesting but I have not caught it.

@KhaosTrader, you can use a flag. For instance a boolean AlreadyTradedThisBar that you would set to false at each new bar (BarStatus).

Nicolas

Envoyé depuis mon GT-I9100 avec Tapatalk

Visit my futures io Trade Journal Reply With Quote
The following user says Thank You to Nicolas11 for this post:
 
(login for full post details)
  #62 (permalink)
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
 
Posts: 107 since Jan 2012
Thanks: 40 given, 21 received

Nicolas,

I implemented your suggestion by setting the flag, EnterTrade = false.. But now it wont enter all trades it should.. Here is the screenshot....



here is the code snippet..

 
Code
if ( BarStatus(1) = 2 ) then begin 
	EnterTrade = ( Low >= Low[1] and High >= High[1] );
	LongEntryPrice = High;
	ShortEntryPrice = Low;
end;

if MarketPosition = 0 and EnterTrade then begin
	Buy ("Enter Long") 300 Shares next Bar at LongEntryPrice stop;
	EnterTrade = false;
	//SellShort("Enter Short") 300  Shares Next Bar at (ShortEntryPrice) stop;
end;
Here is full code:

 
Code
Inputs:
	Target1 (50),
  	Target2(100),
  	Target3(200),
  	StopSize(75),
  	BuyGap(.20),
  	BE2(1) , // 0=false, 1 = true
  	BE3(1); // 0=false, 1 = true
  	
 Variables:
 	EnterTrade 	( false ),
	LongEntryPrice ( 0 ),
	ShortEntryPrice ( 0 ),
   	TickSize (MinMove/PriceScale),
  	t1 (target1*TickSize),
  	t2 (target2*TickSize),
  	t3 (target3*TickSize),
  	st1 (0),
  	st2 (0),
  	st3 (0);
 

[IntrabarOrderGeneration = true]

if ( BarStatus(1) = 2 ) then begin 
	EnterTrade = ( Low >= Low[1] and High >= High[1] );
	LongEntryPrice = High;
	ShortEntryPrice = Low;
end;

if MarketPosition = 0 and EnterTrade then begin
	Buy ("Enter Long") 300 Shares next Bar at LongEntryPrice stop;
	EnterTrade = false;
	//SellShort("Enter Short") 300  Shares Next Bar at (ShortEntryPrice) stop;
end;


//Label # Shares below each bar
Value1 = Text_New(Date, Time, Low-(2), NumToStr(CurrentShares/100, 0));
Text_SetColor(Value1, Blue);
Text_SetSize(Value1, 9);


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));

	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;


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));

	if CurrentShares = 100 then begin
		BuyToCover("Exit S300-CS100 Target") 100 Shares next Bar at (EntryPrice - t3) Limit;
		BuyToCover("Exit S300-CS100 Stop") 100 Shares next Bar at st3 Stop;
	end;
	
	if CurrentShares = 200 then begin
   		BuyToCover("Exit S200-CS200 Target") 100 Shares Next Bar at (EntryPrice - t2) Limit;
   		BuyToCover("Exit S200-CS200 Stop") 100 Shares Next Bar at st2 Stop;	
   		BuyToCover("Exit S300-CS200 Target") 100 Shares Next Bar at (EntryPrice - t3) Limit;
   		BuyToCover("Exit S300-CS200 Stop") 100 Shares Next Bar at st3 Stop;	
   	end;
   	
   	if CurrentShares = 300 then begin
   		BuyToCover("Exit S100-CS300 Target") 100 Shares Next Bar at (EntryPrice - t1) Limit;
   		BuyToCover("Exit S100-CS300 Stop") 100 Shares Next Bar at st1 Stop;	
   		BuyToCover("Exit S200-CS300 Target") 100 Shares Next Bar at (EntryPrice - t2) Limit;
   		BuyToCover("Exit S200-CS300 Stop") 100 Shares Next Bar at st2 Stop;	
   		BuyToCover("Exit S300-CS300 Target") 100 Shares Next Bar at (EntryPrice - t3) Limit;
   		BuyToCover("Exit S300-CS300 Stop") 100 Shares Next Bar at st3 Stop;
   	end;
	
end;

Started this thread Reply With Quote
 
(login for full post details)
  #63 (permalink)
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
 
Posts: 107 since Jan 2012
Thanks: 40 given, 21 received

Oh on the Strategy, I set the following:

* Allow unlimited entries per bar

* Backtesting Precision : Use Bar Magnifier [checked], Intraday=1 minutes, Skip ticks with identical prices [checked]

Started this thread Reply With Quote
 
(login for full post details)
  #64 (permalink)
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
 
Nicolas11's Avatar
 
Posts: 1,071 since Aug 2011
Thanks: 2,232 given, 1,751 received

Seems logical...

I copy your code:

Quoting 
if ( BarStatus(1) = 2 ) then begin
EnterTrade = ( Low >= Low[1] and High >= High[1] );
LongEntryPrice = High;
ShortEntryPrice = Low;
end;

if MarketPosition = 0 and EnterTrade then begin
Buy ("Enter Long") 300 Shares next Bar at LongEntryPrice stop;
EnterTrade = false;
//SellShort("Enter Short") 300 Shares Next Bar at (ShortEntryPrice) stop;
end;

Let's suppose that, at the last tick of the bar (BarStatus = 2), EnterTrade is set to true (first part of the code)
With the 2nd part of the code, you ask to buy at the next tick (first tick of the next bar) at a given price.
But you also set EnterTrade to false.
So, if the given price is not reached on the first tick of the next bar, the code will not enter trade later within the bar.

Nicolas

Visit my futures io Trade Journal Reply With Quote
The following user says Thank You to Nicolas11 for this post:
 
(login for full post details)
  #65 (permalink)
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
 
Posts: 107 since Jan 2012
Thanks: 40 given, 21 received

I see your point....

I then moved the "EnterTrade = false;" to the "if marketposition =1 then begin...

 
Code
if MarketPosition = 1 then begin
	EnterTrade = false;
 	st1 = EntryPrice - (stopsize * TickSize);
 	st2 = iff(BE2 = 1, EntryPrice, EntryPrice-(stopsize * TickSize));
 	st3 = iff(BE3 = 1, EntryPrice, EntryPrice-(stopsize * TickSize));

	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;
but now again, it enters multiple times each bar... So I am pretty much at a loss on what to do...

Started this thread Reply With Quote
 
(login for full post details)
  #66 (permalink)
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
 
Nicolas11's Avatar
 
Posts: 1,071 since Aug 2011
Thanks: 2,232 given, 1,751 received

@KhaosTrader,

Could you test the 2 following modifications?

(1) In the Variables declaration, add one intrabarpersist:
 
Code
intrabarpersist EnterLong	( false ),
(2) At the beginning of "if MarketPosition = 1", add one line:
 
Code
if MarketPosition = 1 then begin
   EnterLong = false;
   [...]

--> Seems OK on my side (one entry per bar).

If it "doesn't work" on your side, please post again the whole code and a snapshot showing the problem.

I have to be frank: due to time constraints, I am not sure I will be able to continue here.

Nicolas

Visit my futures io Trade Journal Reply With Quote
The following 2 users say Thank You to Nicolas11 for this post:
 
(login for full post details)
  #67 (permalink)
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
 
Posts: 107 since Jan 2012
Thanks: 40 given, 21 received

I think its working

I will test it more...

How did you discover the intrabarpersist ?

Thanks Nicolas!

Started this thread Reply With Quote
 
(login for full post details)
  #68 (permalink)
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
 
Nicolas11's Avatar
 
Posts: 1,071 since Aug 2011
Thanks: 2,232 given, 1,751 received

I'm happy it seems to work.

"How did you discover the intrabarpersist ?"
It is a secret.

Nicolas

Visit my futures io Trade Journal Reply With Quote
The following 2 users say Thank You to Nicolas11 for this post:
 
(login for full post details)
  #69 (permalink)
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
 
Posts: 107 since Jan 2012
Thanks: 40 given, 21 received

LOL well, you are really good at easylanguage, I doubt I would have found that.

Thanks

Started this thread Reply With Quote
The following user says Thank You to KhaosTrader for this post:


futures io Trading Community Platforms and Indicators EasyLanguage Programming > sell this bar, not next bar, is that possible?


Last Updated on August 22, 2012


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
 

Battlestations! Show us your trading desk - $1,500 in prizes!

March
 

Importance of Finding Your Own Way w/Adam Grimes

Elite only
 

Journal Challenge w/Jigsaw

April
     



Copyright © 2021 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts