simple go long or go short strategy - NinjaTrader Programming | futures io social day trading
futures io futures trading


simple go long or go short strategy
Updated: Views / Replies:2,009 / 7
Created: by stephenszpak Attachments:1

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
 

simple go long or go short strategy

  #1 (permalink)
Elite Member
Massachusetts (USA)
 
Futures Experience: None
Platform: NinjaTrader
Favorite Futures: YM
 
stephenszpak's Avatar
 
Posts: 778 since Jun 2009
Thanks: 144 given, 358 received

simple go long or go short strategy

Hi

I've altered the code from BigMike's video to experiment with Optimizer.

Changed to not be involved in the optimization:

private int target1 = 1000;
private int target2 = 1000;
private int target3 = 1000;

private int stop = 1000;


Changed to create a simple go long or go short strategy (using range bars):

ManageOrders();

if (Position.MarketPosition != MarketPosition.Flat) return;

if ( Close[0]>Close[1] && Median[0]>Median[1])
GoLong();
else
if (Close[0]<Close[1] && Median[0]<Median[1])
GoShort();


At 8:27 I was looking for a short trade to be taken. The close was lower and the median was lower.
A tad before 10:00 I was looking for a long trade to be taken and it was not. Etc. Etc.


Attached Thumbnails
simple go long or go short strategy-graph-showing-lack-trades-taken.jpg  
Reply With Quote
 
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

 
  #3 (permalink)
Elite Member
Massachusetts (USA)
 
Futures Experience: None
Platform: NinjaTrader
Favorite Futures: YM
 
stephenszpak's Avatar
 
Posts: 778 since Jun 2009
Thanks: 144 given, 358 received


I've spent some time on my code. I have changed it as can be seen below.
If anyone has any comments that's fine. I'm not really sure if what I've done is correct, or
just an improvement. Thanks.



protected override void OnBarUpdate()
{
EntryHandling = EntryHandling.UniqueEntries;


ManageOrders();


if ( Close[0]>Close[1] && Median[0]>Median[1]&& Position.MarketPosition == MarketPosition.Short ||Position.MarketPosition == MarketPosition.Flat)
GoLong();
else
if (Close[0]<Close[1] && Median[0]<Median[1]&&Position.MarketPosition == MarketPosition.Long ||Position.MarketPosition == MarketPosition.Flat)
GoShort();

}

Reply With Quote
 
  #4 (permalink)
Elite Member
Florida
 
Futures Experience: Intermediate
Platform: NT7
Favorite Futures: CL, NQ, NG
 
Posts: 456 since Jun 2009
Thanks: 1,359 given, 383 received

when I have problems like that, I comment out the else statement and give it a run

don't know if that'll work in your situation but it's' worth a shot

the reason I have problems with else is that in some conditions, it's actually 3 or more possible scenarios

if A) do something (go long)

else
if B) do something different (go short)

else : do another thing (go look for some new long or short setups)

kz

Reply With Quote
 
  #5 (permalink)
Elite Member
Asia
 
Futures Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 786 received


stephenszpak View Post
I've spent some time on my code. I have changed it as can be seen below.
If anyone has any comments that's fine. I'm not really sure if what I've done is correct, or
just an improvement. Thanks.



protected override void OnBarUpdate()
{
EntryHandling = EntryHandling.UniqueEntries;


ManageOrders();


if ( Close[0]>Close[1] && Median[0]>Median[1]&& Position.MarketPosition == MarketPosition.Short ||Position.MarketPosition == MarketPosition.Flat)
GoLong();
else
if (Close[0]<Close[1] && Median[0]<Median[1]&&Position.MarketPosition == MarketPosition.Long ||Position.MarketPosition == MarketPosition.Flat)
GoShort();

}

I'm a crap coder, but here you go:

This should probably be in Initialize():
EntryHandling = EntryHandling.UniqueEntries;

and

if (( Close[0]>Close[1] && Median[0]>Median[1])&& (Position.MarketPosition == MarketPosition.Short ||Position.MarketPosition == MarketPosition.Flat))

Note the added ( ) around your entry logic and your position logic. Using print statements helps, and I'm a big fan of using bools so I can print out all the true/false conditions to see where I messed up.

For example:

private bool longOK = false;
if (Position.MarketPosition == MarketPosition.Short ||Position.MarketPosition == MarketPosition.Flat) longOK = true;

if (longOK) Print(DateTime.Now + " LongOK= " + longOK);

Reply With Quote
The following user says Thank You to MXASJ for this post:
 
  #6 (permalink)
Elite Member
Massachusetts (USA)
 
Futures Experience: None
Platform: NinjaTrader
Favorite Futures: YM
 
stephenszpak's Avatar
 
Posts: 778 since Jun 2009
Thanks: 144 given, 358 received

Thanks zeller4 & MXASJ

I was wondering if there was anything that looked terribly off. My new code (shown above already) really
SEEMED to do what I wanted.

zeller4, the trouble originally was that it did not do anything besides take a long or short. The else
statement was not seen apparently, which I thought was very odd.


MXASJ, why are the extra ( ) helpful in your opinion?


I have never " I'm a big fan of using bools so I can print out all the true/false conditions" done this.
But it is an idea.

Thanks to you both. I've got to go for today. Sorry if I missed a point either of you tried to make to me.

P.S. I have a question regarding optimization. It was mentioned in the video, but maybe there is a more
active thread you both might know about. (Don't wan't to start a tread for nothing.)

- Stephen


Reply With Quote
 
  #7 (permalink)
Elite Member
Asia
 
Futures Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 786 received

You can chuck a bool across anything.

if (Historical) return;

in OnBarUpdate will stop any processing of historical data, for example.

While you are coding something that is giving you issues, one way to check your logic is to print stuff out to the output window to see whats going on in your logic.

If you trade logic is, for example, buy if its going up. You can add a print statement. Instead of:

if (Close[0]>Close[1]) EnterLong();

You can do

if (Close[0]>Close[1])
{
EnterLong();
Print(DateTime.Now + " Long signal generated");
}

If you previously declared a variable bool goingUp = false;

You could add:


if (Close[0]>Close[1])
{
EnterLong();
goingUp = true;
Print(DateTime.Now + " Are we GoingUp= " + goingUp);
}

So you can check your logic conditions.

In a situation where you have multiple true/false conditions for enter/exit/do nothing, there is some creative stuff you can do.

But again I'm crap at this so have a play and see what works for you. Happy trading!

Reply With Quote
 
  #8 (permalink)
Elite Member
Massachusetts (USA)
 
Futures Experience: None
Platform: NinjaTrader
Favorite Futures: YM
 
stephenszpak's Avatar
 
Posts: 778 since Jun 2009
Thanks: 144 given, 358 received


MXASJ

You wrote: But again I'm crap at this...

No one is dimmer than me regarding NinjaScript.

It looks, at the moment anyway, that what I have works. I'm hoping to do more over the
weekend. You don't have to comment of course, but one thing I heard a while back is to
just backtest your system without stoploss orders, to see what the natural risk was. Maybe
natural risk isn't the exactly phrasing??

So after that the plan would be to add a stoploss, and
then a breakeven stop. The video has all this already, I just have to make it work in my strategy.

I think I may need a BarsSinceExit in there somewhere as well.

( It'd be nice if all that stuff we read about 'simple is best' actually worked for a change.)

Maybe day after tomorrow I'll have to ask a couple questions in a new thread on optimization.

So, thanks, and I'm all set for now unless you really feel it's important to reply.

- Stephen


Reply With Quote

Reply



futures io > > > > > simple go long or go short strategy

Thread Tools Search this Thread
Search this Thread:

Advanced Search



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

Linda Bradford Raschke: Reading The Tape

Elite only

Adam Grimes: TBA

Elite only

NinjaTrader: TBA

January

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple RSI Strategy frostengine NinjaTrader Programming 2 October 30th, 2011 01:12 PM
Help wanted! Long/short strategy with cancel order and trail stop mrticks NinjaTrader Programming 9 October 26th, 2010 05:15 PM
Simple strategy vast NinjaTrader Programming 19 August 5th, 2010 06:39 PM
Is there a big difference between trading long and trading short ? kittyan Traders Hideout 16 July 30th, 2010 07:19 AM
Looking for a simple MACD strategy. MACD Xover LONG, go LONG roshareid NinjaTrader Programming 2 April 11th, 2010 09:05 PM


All times are GMT -4. The time now is 10:15 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-12 in 0.12 seconds with 20 queries on phoenix via your IP 54.90.92.204