NexusFi: Find Your Edge


Home Menu

 





NinjaTrader ATM in EasyLanguage


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one Arich with 16 posts (1 thanks)
    2. looks_two Bimi with 9 posts (3 thanks)
    3. looks_3 Nicolas11 with 4 posts (5 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
      Best Posters
    1. looks_one Nicolas11 with 1.3 thanks per post
    2. looks_two cbritton with 1 thanks per post
    3. looks_3 Bimi with 0.3 thanks per post
    4. looks_4 Arich with 0.1 thanks per post
    1. trending_up 10,414 views
    2. thumb_up 10 thanks given
    3. group 4 followers
    1. forum 32 posts
    2. attach_file 0 attachments




 
Search this Thread
  #11 (permalink)
 Arich 
Springfield, Missouri
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Interactive Brokers
Trading: EUR/USD
Posts: 28 since Sep 2012
Thanks Given: 29
Thanks Received: 5


Bimi View Post
did you restrict the fill to one order per direction?

If I did, how would I change it back...?

Started this thread Reply With Quote
  #12 (permalink)
Bimi
London
 
Posts: 118 since Mar 2010
Thanks Given: 42
Thanks Received: 58


Arich View Post
If I did, how would I change it back...?

Format Signal > Property

Reply With Quote
  #13 (permalink)
 Arich 
Springfield, Missouri
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Interactive Brokers
Trading: EUR/USD
Posts: 28 since Sep 2012
Thanks Given: 29
Thanks Received: 5


Bimi View Post
Format Signal > Property

It works now! All three lots execute! But the positions never close.... All suggestions welcome!

Started this thread Reply With Quote
  #14 (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

Hi,

Your above code is still not a SSCCE: it does not compile. I have reconstructed something by adding the first lines (inputs, variables, indicators calculation) of your initial code.

It is normal that your first trade never close, since the exit conditions are within a "if CurrentContract = 1", whereas, when in position, CurrentContract is equal to 300000.

Nicolas

Visit my NexusFi Trade Journal Reply With Quote
  #15 (permalink)
 Arich 
Springfield, Missouri
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Interactive Brokers
Trading: EUR/USD
Posts: 28 since Sep 2012
Thanks Given: 29
Thanks Received: 5


Nicolas11 View Post
Hi,

Your above code is still not a SSCCE: it does not compile. I have reconstructed something by adding the first lines (inputs, variables, indicators calculation) of your initial code.

It is normal that your first trade never close, since the exit conditions are within a "if CurrentContract = 1", whereas, when in position, CurrentContract is equal to 300000.

Nicolas

Darn it! I apologize. :-/

Oh! That makes sense. Thanks!

Started this thread Reply With Quote
  #16 (permalink)
 Arich 
Springfield, Missouri
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Interactive Brokers
Trading: EUR/USD
Posts: 28 since Sep 2012
Thanks Given: 29
Thanks Received: 5


Nicolas11 View Post
Hi,

Your above code is still not a SSCCE: it does not compile. I have reconstructed something by adding the first lines (inputs, variables, indicators calculation) of your initial code.

It is normal that your first trade never close, since the exit conditions are within a "if CurrentContract = 1", whereas, when in position, CurrentContract is equal to 300000.

Nicolas

Hi,

So I tried your suggestion and changed the "if CurrentContract = 1" to "if CurrentContract =100000" but it still doesn't work. Here is my code (it should compile just fine now):


inputs:
SlowLength (26),
FastLength (12),
MACDLength (3),
Target1 (10),
StopSize (15);

vars:
ticksize (MinMove/PriceScale),
MyMACD (0),
MACDAvg (0),
MACDDiff (0),
t1 (Target1 * ticksize),
st1 (0);

MyMACD = MACD(Close, FastLength, SlowLength);
MACDAvg = XAverage(MyMACD, MACDLength);
MACDDiff = MyMACD - MACDAvg;

// Open new Positions

if MarketPosition = 0 then begin

if MyMACD > MACDAvg and MyMACD <= 0 and MACDAvg <= 0 then begin
Buy ("Enter Long1") 100000 contract next bar at market;
end;
end;

// Manage open orders

if MarketPosition = 100000 then begin

st1 = EntryPrice - (StopSize * TickSize);

if CurrentContracts = 100000 then begin
Sell ("Exit l1-c1 Target") 100000 contracts Next Bar at (EntryPrice + t1) Limit;
Sell ("Exit l1-c1 Stop") 100000 contracts Next Bar at st1 Stop;
end;
end;

I am so confused! The exit should be with the targets, right? Suggestions are very welcome... :-/

Started this thread Reply With Quote
  #17 (permalink)
Bimi
London
 
Posts: 118 since Mar 2010
Thanks Given: 42
Thanks Received: 58

I am confused too; who can read your code ??? You have to learn how to use the code tag.

Reply With Quote
  #18 (permalink)
 Arich 
Springfield, Missouri
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Interactive Brokers
Trading: EUR/USD
Posts: 28 since Sep 2012
Thanks Given: 29
Thanks Received: 5


Bimi View Post
I am confused too; who can read your code ??? You have to learn how to use the code tag.

I don't know what you're talking about...? This is in the EasyLanguage Programming section of this forum, so those who can read the code are those who have platforms that use EL... What is this "code tag" that you're referring to?

Started this thread Reply With Quote
  #19 (permalink)
 
cbritton's Avatar
 cbritton 
Atlanta, Georgia
 
Experience: Intermediate
Platform: NT
Broker: DDT
Trading: ZN, ZB
Posts: 230 since Mar 2010
Thanks Given: 152
Thanks Received: 256


Arich View Post
if MarketPosition = 100000 then begin


I am so confused! The exit should be with the targets, right? Suggestions are very welcome... :-/

MarketPosition can be 0 (flat), 1 (long) or -1 (short). Not sure why you have 100000 here.

-Regards,
C

“Strategy without tactics is the slowest route to victory. Tactics without strategy is the noise before defeat.” - Sun Tzu
Reply With Quote
Thanked by:
  #20 (permalink)
 Arich 
Springfield, Missouri
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Interactive Brokers
Trading: EUR/USD
Posts: 28 since Sep 2012
Thanks Given: 29
Thanks Received: 5

Ok,

I've been working on getting this strategy coded in my spare time. This last weekend I was finally able to code it so that my "buys" were entered/exited, but I couldn't get my "sells" to enter or exit. I figured out why the sells were failing to execute, but now I'm getting the syntax error
Quoting 
unexpected 'end of file', expecting 'End'

I've searched high and low on the internet for solutions (or even descriptions of why it's doing this), but I have had no luck. It seems like an easy issue to fix. Can someone help, please? Here is my code:

 
Code
inputs: 
	SlowLength (26),
	FastLength (12),
	MACDLength (3),
	Target1 (10),
	Target2 (0),
	Target3 (0),
	StopSize (15),
	BE2 (0), // 0=false 1=true
	BE3 (0); // 0=false 1=true
	
vars:
	ticksize (MinMove/PriceScale),
	MyMACD (0),
	MACDAvg (0),
	MACDDiff (0),
	t1 (Target1 * ticksize),
	t2 (Target1 + Target2 *ticksize),
	t3 (Target1 + Target2 + Target3 * ticksize),
	st1 (0),
	st2 (0),
	st3 (0);

MyMACD = MACD(Close, FastLength, SlowLength);
MACDAvg = XAverage(MyMACD, MACDLength);
MACDDiff = MyMACD - MACDAvg;

// Open new Positions

if MarketPosition = 0 then begin

	if MyMACD crosses above MACDAvg and MyMACD <= 0 and MACDAvg <= 0 then begin
		Buy ("Enter Long1") 1 contract next bar at market;
		
	if MyMACD crosses below MACDAvg and MyMACD >= 0 and MACDAvg >= 0 then begin
		Sell ("Enter Short1") 1 contract next bar at market;
	end;		
end; 

// Manage open orders

if MarketPosition = 1 then begin

	st1 = EntryPrice - (StopSize * ticksize);
	
	if CurrentContracts = 1 then begin
		Sell ("Exit l1-c1 Target") 1 contracts Next Bar at (EntryPrice + t1) Limit;
		Sell ("Exit l1-c1 Stop") 1 contracts Next Bar at st1 Stop;
	end;
	
end;

if MarketPosition = -1 then begin

	st1 = EntryPrice - (StopSize * ticksize);
	
	if CurrentContracts = 1 then begin
		buytocover ("Exit s1-c1 Target") 1 contract Next Bar at (EntryPrice - t1) Limit;
		buytocover ("Exit s1-c1 Stop") 1 contract next bar at st1 Stop;
	end;
end;
Any suggestions will be very appreciated! I've been staring at this code for a couple of hours now...

Started this thread Reply With Quote




Last Updated on February 28, 2013


© 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