NinjaTrader ATM in EasyLanguage - EasyLanguage Programming | futures io social day trading
futures io futures trading


NinjaTrader ATM in EasyLanguage
Updated: Views / Replies:4,055 / 32
Created: by Arich Attachments:0

Welcome to futures io.

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

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

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

Reply
 
Thread Tools Search this Thread
 

NinjaTrader ATM in EasyLanguage

  #21 (permalink)
Trading for Fun
London
 
Futures Experience: None
Platform: mc, TS, ninja
Favorite Futures: es
 
Bimi's Avatar
 
Posts: 118 since Mar 2010
Thanks: 42 given, 58 received

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;


Last edited by Bimi; October 2nd, 2012 at 10:46 AM.
Reply With Quote
The following user says Thank You to Bimi for this post:
 
  #22 (permalink)
Elite Member
Springfield, Missouri
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: Interactive Brokers
Favorite Futures: EUR/USD
 
Posts: 28 since Sep 2012
Thanks: 29 given, 5 received


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

Reply With Quote
 
  #23 (permalink)
Elite Member
Springfield, Missouri
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: Interactive Brokers
Favorite Futures: EUR/USD
 
Posts: 28 since Sep 2012
Thanks: 29 given, 5 received

Stoploss to Breakeven to Trailing stop Issues


@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!


Last edited by Arich; October 3rd, 2012 at 02:24 AM. Reason: Typo
Reply With Quote
 
  #24 (permalink)
Trading for Fun
London
 
Futures Experience: None
Platform: mc, TS, ninja
Favorite Futures: es
 
Bimi's Avatar
 
Posts: 118 since Mar 2010
Thanks: 42 given, 58 received


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.


Last edited by Bimi; October 3rd, 2012 at 10:05 AM.
Reply With Quote
 
  #25 (permalink)
Trading for Fun
London
 
Futures Experience: None
Platform: mc, TS, ninja
Favorite Futures: es
 
Bimi's Avatar
 
Posts: 118 since Mar 2010
Thanks: 42 given, 58 received


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)
Elite Member
Springfield, Missouri
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: Interactive Brokers
Favorite Futures: EUR/USD
 
Posts: 28 since Sep 2012
Thanks: 29 given, 5 received


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...

Reply With Quote
 
  #27 (permalink)
Trading for Fun
London
 
Futures Experience: None
Platform: mc, TS, ninja
Favorite Futures: es
 
Bimi's Avatar
 
Posts: 118 since Mar 2010
Thanks: 42 given, 58 received


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
The following user says Thank You to Bimi for this post:
 
  #28 (permalink)
Elite Member
Springfield, Missouri
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: Interactive Brokers
Favorite Futures: EUR/USD
 
Posts: 28 since Sep 2012
Thanks: 29 given, 5 received


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!

Reply With Quote
The following user says Thank You to Arich for this post:
 
  #29 (permalink)
Elite Member
Springfield, Missouri
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: Interactive Brokers
Favorite Futures: EUR/USD
 
Posts: 28 since Sep 2012
Thanks: 29 given, 5 received

Entry Orders

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?

Reply With Quote
 
  #30 (permalink)
Trading for Fun
London
 
Futures Experience: None
Platform: mc, TS, ninja
Favorite Futures: es
 
Bimi's Avatar
 
Posts: 118 since Mar 2010
Thanks: 42 given, 58 received


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

Reply With Quote

Reply



futures io > > > > > NinjaTrader ATM in EasyLanguage

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
ATM Template? dsraider NinjaTrader Programming 12 May 23rd, 2012 05:52 PM
Stable ATM Strategies? Baseheadz NinjaTrader Programming 1 August 21st, 2011 04:30 PM
ATM Strategy for Ninjatrader keepdchange NinjaTrader 6 October 6th, 2010 04:57 AM
ATM and Limit Orders spinnybobo NinjaTrader Programming 6 June 12th, 2010 09:06 PM
ATM Strategies - NinjaTrader zeller4 NinjaTrader 1 June 19th, 2009 06:10 PM


All times are GMT -4. The time now is 09:23 AM.

Copyright © 2017 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
Page generated 2017-12-16 in 0.17 seconds with 19 queries on phoenix via your IP 54.83.122.227