NexusFi: Find Your Edge


Home Menu

 





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 3,334 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 7 posts
    2. attach_file 1 attachments




 
Search this Thread

simple go long or go short strategy

  #1 (permalink)
 
stephenszpak's Avatar
 stephenszpak 
Massachusetts (USA)
 
Experience: None
Platform: NinjaTrader
Trading: YM
Posts: 750 since Jun 2009
Thanks Given: 144
Thanks Received: 356

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:	273
Size:	293.1 KB
ID:	17153  
Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
ZombieSqueeze
Platforms and Indicators
How to apply profiles
Traders Hideout
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Better Renko Gaps
The Elite Circle
NexusFi Journal Challenge - May 2024
Feedback and Announcements
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
34 thanks
Just another trading journal: PA, Wyckoff & Trends
30 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
23 thanks
GFIs1 1 DAX trade per day journal
21 thanks
  #3 (permalink)
 
stephenszpak's Avatar
 stephenszpak 
Massachusetts (USA)
 
Experience: None
Platform: NinjaTrader
Trading: YM
Posts: 750 since Jun 2009
Thanks Given: 144
Thanks Received: 356


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
  #4 (permalink)
 zeller4 
Orlando Florida
 
Experience: Intermediate
Platform: NT8
Trading: CL, NQ, ES, RTY
Posts: 477 since Jun 2009
Thanks Given: 1,416
Thanks Received: 404

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)
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 800


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
Thanked by:
  #6 (permalink)
 
stephenszpak's Avatar
 stephenszpak 
Massachusetts (USA)
 
Experience: None
Platform: NinjaTrader
Trading: YM
Posts: 750 since Jun 2009
Thanks Given: 144
Thanks Received: 356

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
  #7 (permalink)
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 800

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)
 
stephenszpak's Avatar
 stephenszpak 
Massachusetts (USA)
 
Experience: None
Platform: NinjaTrader
Trading: YM
Posts: 750 since Jun 2009
Thanks Given: 144
Thanks Received: 356


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




Last Updated on July 21, 2010


© 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