simple go long or go short strategy - futures io
futures io futures trading



simple go long or go short strategy


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one stephenszpak with 4 posts (0 thanks)
    2. looks_two MXASJ with 2 posts (1 thanks)
    3. looks_3 zeller4 with 1 posts (0 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 2,747 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 7 posts
    2. attach_file 1 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
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

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

 
Search this Thread
 

simple go long or go short strategy

(login for full post details)
  #1 (permalink)
Massachusetts (USA)
 
Experience: None
Platform: NinjaTrader
Trading: YM
 
stephenszpak's Avatar
 
Posts: 778 since Jun 2009
Thanks: 144 given, 356 received

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
Click image for larger version

Name:	graph showing lack of trades taken.jpg
Views:	157
Size:	293.1 KB
ID:	17153  
Started this thread Reply With Quote

Can you help answer these questions
from other members on futures io?
Short Interest Ratio indicator?
ThinkOrSwim
ZigZag with Depth and Backstep
EasyLanguage Programming
Webinar: Finding your own way in trading w/Adam Grimes
The Elite Circle
Automatic pattern research with NT
Elite Algorithmic NinjaTrader Trading
Help Needed: TOS Options Chain IV & IMPL MOVE Calcul …
ThinkOrSwim
 
 
(login for full post details)
  #3 (permalink)
Massachusetts (USA)
 
Experience: None
Platform: NinjaTrader
Trading: YM
 
stephenszpak's Avatar
 
Posts: 778 since Jun 2009
Thanks: 144 given, 356 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();

}

Started this thread Reply With Quote
 
(login for full post details)
  #4 (permalink)
Florida
 
Experience: Intermediate
Platform: NT7
Trading: CL, NQ, NG
 
Posts: 469 since Jun 2009
Thanks: 1,401 given, 402 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
 
(login for full post details)
  #5 (permalink)
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 799 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:
 
(login for full post details)
  #6 (permalink)
Massachusetts (USA)
 
Experience: None
Platform: NinjaTrader
Trading: YM
 
stephenszpak's Avatar
 
Posts: 778 since Jun 2009
Thanks: 144 given, 356 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


Started this thread Reply With Quote
 
(login for full post details)
  #7 (permalink)
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 799 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
 
(login for full post details)
  #8 (permalink)
Massachusetts (USA)
 
Experience: None
Platform: NinjaTrader
Trading: YM
 
stephenszpak's Avatar
 
Posts: 778 since Jun 2009
Thanks: 144 given, 356 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


Started this thread Reply With Quote


futures io Trading Community Platforms and Indicators NinjaTrader > simple go long or go short strategy


Last Updated on July 21, 2010


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
 

Battlestations! Show us your trading desk - $1,500 in prizes!

March
 

Importance of Finding Your Own Way w/Adam Grimes

Elite only
 

Journal Challenge w/Jigsaw

April
     



Copyright © 2021 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