NexusFi: Find Your Edge


Home Menu

 





New at Programming, stuck with a crossover strat


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one DeadCatBounced with 7 posts (0 thanks)
    2. looks_two gregid with 3 posts (4 thanks)
    3. looks_3 Zondor with 1 posts (1 thanks)
    4. looks_4 Tasker_182 with 1 posts (1 thanks)
      Best Posters
    1. looks_one gregid with 1.3 thanks per post
    2. looks_two shodson with 1 thanks per post
    3. looks_3 Zondor with 1 thanks per post
    4. looks_4 Tasker_182 with 1 thanks per post
    1. trending_up 4,138 views
    2. thumb_up 7 thanks given
    3. group 5 followers
    1. forum 13 posts
    2. attach_file 0 attachments




 
Search this Thread

New at Programming, stuck with a crossover strat

  #11 (permalink)
 
DeadCatBounced's Avatar
 DeadCatBounced 
Baltimore MD US
 
Experience: Intermediate
Platform: NinjaTrader
Trading: ES, NQ
Posts: 293 since Apr 2013
Thanks Given: 1,514
Thanks Received: 736

Thanks for your reply Tasker_182!

Yeah I have been working my way through the help file. It is a ton of information to wrap my head around but I am trying!

I have added print statements to my code so it looks like this:

 
Code
        {
            if (CrossAbove((GetCurrentAsk() + (Offset * TickSize)), SMA(SMAlookback), 1))
			{
				Print("LongCurrentAsk: "+GetCurrentAsk()+" (Offset+Tick): "+(Offset * TickSize)+" SMA: "+SMA(SMAlookback)[0]);
				Print("Calculated value: "+(GetCurrentAsk() + (Offset * TickSize)));
                EnterShort();
			}
            else if (CrossBelow((GetCurrentAsk() + (Offsetneg * TickSize)), SMA(SMAlookback), 1))
			{
				Print("ShortCurrentAsk: "+GetCurrentAsk()+" (Offsetneg+Tick): "+(Offsetneg * TickSize)+" SMA: "+SMA(SMAlookback)[0]);
				Print("Calculated value: "+(GetCurrentAsk() + (Offsetneg * TickSize)));
                EnterLong();
			}
        }
When I look at the output window as the code works I get this:

 
Code
ShortCurrentAsk: 92.94 (Offsetneg+Tick): -0.05 SMA: 92.8932
Calculated value: 92.89
2013-06-04 3:37:38 AM Entered internal PlaceOrder() method at 2013-06-04 3:37:38 AM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
ShortCurrentAsk: 92.94 (Offsetneg+Tick): -0.05 SMA: 92.8932
Calculated value: 92.89
2013-06-04 3:37:39 AM Entered internal PlaceOrder() method at 2013-06-04 3:37:39 AM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
2013-06-04 3:37:39 AM Ignored PlaceOrder() method at 2013-06-04 3:37:39 AM: Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Buy' FromEntrySignal='' Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'
ShortCurrentAsk: 92.94 (Offsetneg+Tick): -0.05 SMA: 92.8932
Calculated value: 92.89
2013-06-04 3:37:39 AM Entered internal PlaceOrder() method at 2013-06-04 3:37:39 AM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
2013-06-04 3:37:39 AM Ignored PlaceOrder() method at 2013-06-04 3:37:39 AM: Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Buy' FromEntrySignal='' Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'
ShortCurrentAsk: 92.94 (Offsetneg+Tick): -0.05 SMA: 92.8932
So in that instance the price was above the SMA, at 5 ticks above it went long(which is good!) the output window keeps coming up with this over and over again

 
Code
2013-06-04 3:37:39 AM Entered internal PlaceOrder() method at 2013-06-04 3:37:39 AM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
2013-06-04 3:37:39 AM Ignored PlaceOrder() method at 2013-06-04 3:37:39 AM: Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Buy' FromEntrySignal='' Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'

Which would mean to me that it keeps getting an order spammed at it that it cannot fill. When in reality all I would like is for it to do nothing until the price moved to 5 ticks below the moving average and have it reverse and go short then.

So basically right now it will do the first entry correctly but it will not reverse for me! :/

Anyways I will keep at it. seems like its a fairly decent sized learning curve but hopefully worth it once I figure it out!

Visit my NexusFi Trade Journal Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Exit Strategy
NinjaTrader
Better Renko Gaps
The Elite Circle
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Futures True Range Report
The Elite Circle
 
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
38 thanks
NexusFi site changelog and issues/problem reporting
26 thanks
GFIs1 1 DAX trade per day journal
19 thanks
The Program
18 thanks
  #12 (permalink)
 
gregid's Avatar
 gregid 
Wrocław, Poland
 
Experience: Intermediate
Platform: NinjaTrader, Racket
Trading: Ockham's razor
Posts: 650 since Aug 2009
Thanks Given: 320
Thanks Received: 623


Trader Chris View Post
 
Code
Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'


Check what are the values for these properties of your strategy in the property grid.

You can change these values in your code as well (in Initialize() ):

 
Code
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;

Reply With Quote
Thanked by:
  #13 (permalink)
 
DeadCatBounced's Avatar
 DeadCatBounced 
Baltimore MD US
 
Experience: Intermediate
Platform: NinjaTrader
Trading: ES, NQ
Posts: 293 since Apr 2013
Thanks Given: 1,514
Thanks Received: 736


I havent changed the entries per direction from the default setting which from the webinars I have seen I believe the default value is 1.

I didn't want to change that because at this time I only want can do the one contract at a time! :P

So because I never played with that variable I do not even see it at all in the initialized() area

Visit my NexusFi Trade Journal Started this thread Reply With Quote
  #14 (permalink)
 
shodson's Avatar
 shodson 
OC, California, USA
Quantoholic
 
Experience: Advanced
Platform: IB/TWS, NinjaTrader, ToS
Broker: IB, ToS, Kinetick
Trading: stocks, options, futures, VIX
Posts: 1,976 since Jun 2009
Thanks Given: 533
Thanks Received: 3,709

First of all, you are using CrossAbove() and CrossBelow() incorrectly. If you look at CrossAbove() for example...

CrossAbove()

You will see that the first parameter needs to be a DataSeries object, not a double. The expression

 
Code
GetCurrentAsk() + (Offset * TickSize)
evaluates to a double, not a DataSeries. I'm surprised your code even compiles! NT's syntactical leniency is the cause of your headaches.

Personally, I've had problems getting these cross methods to work for me sometimes, maybe I was using them incorrectly, but a long time ago I decided to never use them. Now I do something like "if x > y and x wasn't > y in the last bar" logic to determine crosses above.

So if I was to use the Close instead of the ask (not sure why you're using the asking price) it could be

 
Code
SMA sma = SMA(Lookback);
double smaNow = sma[0];
double smaLastBar = sma[1];
double priceNow = Close[0];
double priceLastBar = Close[1];

if (priceNow + (Offset * TickSize) > smaNow && priceLastBar + (Offset * TickSize) <= smaLastBar)
...then we have a cross above scenario

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:




Last Updated on June 12, 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