NexusFi: Find Your Edge


Home Menu

 





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 25,993 views
    2. thumb_up 33 thanks given
    3. group 3 followers
    1. forum 68 posts
    2. attach_file 16 attachments




 
Search this Thread

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

  #61 (permalink)
 
Nicolas11's Avatar
 Nicolas11 
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
Posts: 1,071 since Aug 2011
Thanks Given: 2,232
Thanks Received: 1,769

@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 NexusFi Trade Journal Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Better Renko Gaps
The Elite Circle
About a successful futures trader who didnt know anythin …
Psychology and Money Management
Trade idea based off three indicators.
Traders Hideout
 
  #62 (permalink)
 KhaosTrader 
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
Posts: 107 since Jan 2012
Thanks Given: 40
Thanks Received: 21

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
  #63 (permalink)
 KhaosTrader 
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
Posts: 107 since Jan 2012
Thanks Given: 40
Thanks Received: 21


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
  #64 (permalink)
 
Nicolas11's Avatar
 Nicolas11 
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
Posts: 1,071 since Aug 2011
Thanks Given: 2,232
Thanks Received: 1,769

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 NexusFi Trade Journal Reply With Quote
Thanked by:
  #65 (permalink)
 KhaosTrader 
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
Posts: 107 since Jan 2012
Thanks Given: 40
Thanks Received: 21

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
  #66 (permalink)
 
Nicolas11's Avatar
 Nicolas11 
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
Posts: 1,071 since Aug 2011
Thanks Given: 2,232
Thanks Received: 1,769

@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 NexusFi Trade Journal Reply With Quote
Thanked by:
  #67 (permalink)
 KhaosTrader 
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
Posts: 107 since Jan 2012
Thanks Given: 40
Thanks Received: 21

I think its working

I will test it more...

How did you discover the intrabarpersist ?

Thanks Nicolas!

Started this thread Reply With Quote
  #68 (permalink)
 
Nicolas11's Avatar
 Nicolas11 
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
Posts: 1,071 since Aug 2011
Thanks Given: 2,232
Thanks Received: 1,769

I'm happy it seems to work.

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

Nicolas

Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #69 (permalink)
 KhaosTrader 
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
Posts: 107 since Jan 2012
Thanks Given: 40
Thanks Received: 21

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

Thanks

Started this thread Reply With Quote
Thanked by:




Last Updated on August 22, 2012


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
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.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts