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,884 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?

  #41 (permalink)
 KhaosTrader 
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
Posts: 107 since Jan 2012
Thanks Given: 40
Thanks Received: 21

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

Can you help answer these questions
from other members on NexusFi?
NexusFi Journal Challenge - May 2024
Feedback and Announcements
REcommedations for programming help
Sierra Chart
Better Renko Gaps
The Elite Circle
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
Trade idea based off three indicators.
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
48 thanks
Just another trading journal: PA, Wyckoff & Trends
34 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
24 thanks
GFIs1 1 DAX trade per day journal
22 thanks
  #42 (permalink)
 KhaosTrader 
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
Posts: 107 since Jan 2012
Thanks Given: 40
Thanks Received: 21

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
  #43 (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,

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

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 NexusFi Trade Journal Reply With Quote
  #45 (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

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

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
  #47 (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,

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

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
  #49 (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

"9am to 10am Highest high was 505.20"

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

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


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




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