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 9,673 views
    2. thumb_up 10 thanks given
    3. group 4 followers
    1. forum 32 posts
    2. attach_file 0 attachments




 
Search this Thread

NinjaTrader ATM in EasyLanguage

  #21 (permalink)
Bimi
London
 
Posts: 118 since Mar 2010
Thanks Given: 42
Thanks Received: 58

Do yourself this favor: when you code a block, align the BEGIN and the END on the same tab, so that you can visually match a BEGIN with an End.

here's an example:
 
Code
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;
	END;
		
	if MyMACD crosses below MACDAvg and MyMACD >= 0 and MACDAvg >= 0 then 
	BEGIN
		Sell ("Enter Short1") 1 contract next bar at market;
	END;

END;

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
Futures True Range Report
The Elite Circle
Exit Strategy
NinjaTrader
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
NexusFi Journal Challenge - April 2024
Feedback and Announcements
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
61 thanks
Funded Trader platforms
39 thanks
Battlestations: Show us your trading desks!
26 thanks
NexusFi site changelog and issues/problem reporting
26 thanks
The Program
18 thanks
  #22 (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
Do yourself this favor: when you code a block, align the BEGIN and the END on the same tab, so that you can visually match a BEGIN with an End.

here's an example:
 
Code
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;
	END;
		
	if MyMACD crosses below MACDAvg and MyMACD >= 0 and MACDAvg >= 0 then 
	BEGIN
		Sell ("Enter Short1") 1 contract next bar at market;
	END;

END;

I will give this a try when I get home tonight. Thanks!

Arich

Started this thread Reply With Quote
  #23 (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 I found the issue and got the code to work, so thank you!

Now I'm trying to figure out how to get the breakeven to work. I have watched the Advanced MC Strategy Video Tutorial that @Big Mike posted and I have used his breakeven code, but it doesn't seem to be reacting like it should. For instance, my second and third lots will get stopped out within two-three pips of my entry price (like they should if my first target has been hit), but they get stopped out before my first target is hit, even in the same bar sometimes.

I've not been able to find any answers to this online or on futures.io (formerly BMT). I'm not opposed to coding it differently than BigMike, I just figured he coded it in the most efficient way.

Also, how difficult do you think it would be to have stops 2 and 3 move to breakeven after target 1 is filled, and then have the last stop change to a trailing stop after target 2 is filled? That is my ultimate goal, but if I need to learn other concepts first I'm definitely willing to do so.

The breakeven to trailing stop switch is where NT fell short in its capabilities for me (due to my limited knowledge of NinjaScript).

If you'd like to see for yourself how it's acting, here is my code:

 
Code
inputs: 
	SlowLength (26),
	FastLength (12),
	MACDLength (9),
	Target1 (10),
	Target2 (10),
	Target3 (10),
	StopSize (10),
	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 Long") 300000 contracts next bar at market;
	end;
	
	if MyMACD crosses below MACDAvg and MyMACD >= 0 and MACDAvg >= 0 then begin
		SellShort ("Enter Short1") 300000 contracts next bar at market;
		
	end;
		
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 CurrentContracts = 100000 then begin
		Sell ("Exit l3-c1 Target") 100000 Contract Next Bar at (EntryPrice + t3) Limit;
		Sell ("Exit l3-c1 Stop") 100000 Contract Next Bar at st3 Stop;
	end;
	
	if CurrentContracts = 200000 then begin
		Sell ("Exit l2-c2 Target") 100000 Contract Next Bar at (EntryPrice + t2) Limit;
		Sell ("Exit l2-c2 Stop") 100000 Contract Next Bar at st2 Stop;
		Sell ("Exit l3-c2 Target") 100000 Contract Next Bar at (EntryPrice + t3) Limit;
		Sell ("Exit l3-c2 Stop") 100000 Contract Next Bar at st3 Stop;
	end;
	
	if CurrentContracts = 300000 then begin
		Sell ("Exit l1-c3 Target") 100000 Contract Next Bar at (EntryPrice + t1) Limit;
		Sell ("Exit l1-c3 Stop") 100000 Contract Next Bar at st1 Stop;
		Sell ("Exit l2-c3 Target") 100000 Contract Next Bar at (EntryPrice + t2) Limit;
		Sell ("Exit l2-c3 Stop") 100000 Contract Next Bar at st2 Stop;
		Sell ("Exit l3-c3 Target") 100000 Contract Next Bar at (EntryPrice + t3) Limit;
		Sell ("Exit l3-c3 Stop") 100000 Contract 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 CurrentContracts = 100000 then begin
		BuyToCover ("Exit s3-c1 Target") 100000 Contract Next Bar at (EntryPrice - t3) Limit;
		BuyToCover ("Exit s3-c1 Stop") 100000 Contract Next Bar at st3 Stop;
	end;
	
	if CurrentContracts = 200000 then begin
		BuyToCover ("Exit s2-c2 Target") 100000 Contract Next Bar at (EntryPrice - t2) Limit;
		BuyToCover ("Exit s2-c2 Stop") 100000 Contract Next Bar at st2 Stop;
		BuyToCover ("Exit s3-c2 Target") 100000 Contract Next Bar at (EntryPrice - t3) Limit;
		BuyToCover ("Exit s3-c2 Stop") 100000 Contract Next Bar at st3 Stop;
	end;
	
	if CurrentContracts = 300000 then begin
		BuyToCover ("Exit s1-c3 Target") 100000 Contract Next Bar at (EntryPrice - t1) Limit;
		BuyToCover ("Exit s1-c3 Stop") 100000 Contract Next Bar at st1 Stop;
		BuyToCover ("Exit s2-c3 Target") 100000 Contract Next Bar at (EntryPrice - t2) Limit;
		BuyToCover ("Exit s2-c3 Stop") 100000 Contract Next Bar at st2 Stop;
		BuyToCover ("Exit s3-c3 Target") 100000 Contract Next Bar at (EntryPrice - t3) Limit;
		BuyToCover ("Exit s3-c3 Stop") 100000 Contract Next Bar at st3 Stop;	
	end;
end;
Thank you for your help! I would still be where I was two weeks ago without your help!

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


Arich View Post
@Bimi I found the issue and got the code to work, so thank you!

Now I'm trying to figure out how to get the ...

Slow down... one problem at a time.

What was the problem? Aren't you going to share? This is a community, not your private tech support. Many people read these threads to learn together. The synergy makes us grow faster.

Please click the [Thanks] button.

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


Arich View Post
@Bimi I found the issue and got the code to work, so thank you!
...


Also, how difficult do you think it would be to have stops 2 and 3 move to breakeven after target 1 is filled, and then have the last stop change to a trailing stop after target 2 is filled? That is my ultimate goal, but if I need to learn other concepts first I'm definitely willing to do so.
...

You are talking about advanced level EL programming.

It is not difficult, if you have proper programming habits.
You will need to be more careful with the details.

For complex strategies, you must start with a flowchart. There is no short cut.

Reply With Quote
  #26 (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
Slow down... one problem at a time.

What was the problem? Aren't you going to share? This is a community, not your private tech support. Many people read these threads to learn together. The synergy makes us grow faster.

There is no "hidden" problem that I was hiding from the forum. I *am* sharing all of my issues because I know that my biggest contribution to this forum is creating discussions where others can learn from my mistakes and from answers to my questions. That's also why I search through the current threads before I ask a question.

I asked about those two issues at the same time because they are related. I wasn't sure if they needed to be coded a certain way to work well with each other (the breakeven and trailing stop). I apologize for the misunderstandings.


Bimi View Post
You are talking about advanced level EL programming.

It is not difficult, if you have proper programming habits.
You will need to be more careful with the details.

For complex strategies, you must start with a flowchart. There is no short cut.

Ok, can you teach me then? You obviously know what you're doing when it comes to coding. I am more than willing to learn, I just need someone to teach me... I have already learned quite a bit I think. I'm not looking for a shortcut.

Perhaps there needs to be a thread that is a tutorial for the basics of EL programming? I have looked for something like that and haven't found it...

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


Arich View Post
@Bimi I found the issue and got the code to work, so thank you!
...


Bimi View Post
Slow down... one problem at a time.

What was the problem? Aren't you going to share? This is a community, not your private tech support. Many people read these threads to learn together. The synergy makes us grow faster.

Please click the [Thanks] button.


Arich View Post
There is no "hidden" problem that I was hiding from the forum. I *am* sharing all of my issues because I know that my biggest contribution to this forum is creating discussions where others can learn from my mistakes and from answers to my questions. That's also why I search through the current threads before I ask a question.
...

I meant... what was the issue that you found on the previous problem.

Reply With Quote
  #28 (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 meant... what was the issue that you found on the previous problem.

Gotcha, there was a missing "end;" that was causing the error. I had copy and pasted some of the code when I was trying to isolate the previous problem of the code not exiting the positions correctly and forgot to replace the "end;" in between my buy and sell conditions.

I will try to update this thread every time I fix an issue and how I used (your's or any other's) advice. Thanks!

Started this thread Reply With Quote
Thanked by:
  #29 (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, so I wanted to explain a difference that I noticed between NT and MC when coding entries.

In NT, when you code an entry (in my experience, which is limited) you have to code each lot if your goal is to have multiple targets. For example, if you want to enter a buy and have three targets:

In NT it would look like this:

//Conditions for entry would be here, then:

EnterLong (100000, "Long1");
EnterLong (100000, "Long2");
EnterLong (100000, "Long3");

In MC the same entry for three targets looks like this:

//Conditions for entry are here, then:

Buy ("Enter Long") 300000 contracts next bar at Market;

From what I can see, the difference is that NT creates three separate orders which are then tied to three separate exits, while MC groups all the orders together and uses the exits to manage how much is exited at a time.

That's a beginner's interpretation of what is happening. Can anyone confirm or improve my findings?

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


bigmike has a tutorial and sample code to do scalings. I would copy his code and modify it for your purpose.

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