Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicators Crossing Price Bars

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Indicators Crossing Price Bars

    I have a strategy that enters a long market order when the 10 EMA crosses the price bar with the 20 below it and enters a short market order when there's a 10 cross with the 20 EMA above it.
    In backtesting (NT 7), the trade is not always consummated, although it of course always happens in the real world. I use GetCurrentBid as the bar price for buy orders and GetCurrentAsk as the sell price for sell orders. I don't care if the EMA crosses the Bid, the Ask, or the Last, as long as it crosses some part of the price bar. It would seem to me that using the bid price on a buy and the ask price on a sell would capture the cross no matter where in the bar it occurred.
    I was wondering if I'm coding this wrong or if my problem is a function of the backtest engine. This is being tested on an intraday range chart.
    Here is relevant code:
    if (EMA(10)[0] > EMA(20)[0]
    && GetCurrentBid()<= EMA(10)[0])
    {
    EnterLong(DefaultQuantity, "10Long");
    }
    Last edited by sgordet; 01-07-2011, 04:05 PM.

    #2
    Hello sgordet,

    Your description for what you're looking for does not match the code.

    enters a long market order when the 10 EMA crosses the price bar with the 20 below
    There's no CrossBelow statement there. You're only checking if one period ema is less than another, and if Close (GetCurrentBid() in a backtest) is less than or equal to 10 period ema.

    If you're looking for cross below conditions, use CrossBelow() method for this. You can also define these in the strategy wizard condition builder.

    You should also be aware of the debugging tools available. You'll want to use TraceOrders to track order submission for strategies, and print statement to track values of your variables. Help for using these debugging tools is available here:
    Ryan M.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by iceman2018, Today, 08:55 PM
    0 responses
    1 view
    0 likes
    Last Post iceman2018  
    Started by mrmccraig, 04-24-2025, 05:13 PM
    4 responses
    34 views
    0 likes
    Last Post mrmccraig  
    Started by anthonyruhuti, Today, 08:03 PM
    0 responses
    3 views
    0 likes
    Last Post anthonyruhuti  
    Started by michelz, 02-18-2025, 08:30 AM
    37 responses
    1,088 views
    0 likes
    Last Post rockmanx00  
    Started by ericashannon83, Today, 06:27 PM
    0 responses
    4 views
    0 likes
    Last Post ericashannon83  
    Working...
    X