Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Tracking the EMA 8 period color changes?

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

    Tracking the EMA 8 period color changes?

    I have an 8 period EMA shown as a indicator in a lower panel than the price chart, in which I need to find the change in color of the band to help select a trade entry and exit. I'm using EM8_Dn_Up with integer values of -1 = Down Enter Short position , 0 = Neutral Exit Long or Short, 1 = Up Enter Long. I have 4 set conditions (1 for short, 1 for long, 1 for exit short, 1 for exit long) to find out where the change in direction occurs, but I don't get the results in the when doing a Strategy test. I have several other indicators that I built that go along with this one, but am only trying to get this as the initial one to work.

    I'm using Heikin-Ashi bars in the chart currently. When running this for backtesting I'm not able to get the switching of changes in the color indicator with the strategy builder to work out like I wanted so far.


    private int EMA8_Dn_Up;


    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "AutoTrade";
    Calculate = Calculate.OnBarClose;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.AllEntries;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 0;
    StartBehavior = StartBehavior.ImmediatelySubmitSynchronizeAccount;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = false;
    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 20;


    // Disable this property for performance gains in Strategy Analyzer optimizations
    // See the Help Guide for additional information
    IsInstantiatedOnEachOptimizationIteration = true;
    Contracts = 1;
    EMA8_Dn_Up = 0;
    }
    else if (State == State.Configure)
    {
    AddDataSeries("MNQ 03-22", Data.BarsPeriodType.Tick, 1, Data.MarketDataType.Last);
    }
    }

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 1)
    return;

    // Set 1
    if (EMA8_Dn_Up != -1)
    {
    EnterShort(Convert.ToInt32(DefaultQuantity), @"");
    EMA8_Dn_Up = -1;
    }

    // Set 2
    if (EMA8_Dn_Up != 1)
    {
    EnterLong(Convert.ToInt32(DefaultQuantity), @"");
    EMA8_Dn_Up = 1;
    }

    // Set 3
    if ((EMA8_Dn_Up != 0)
    && (EMA8_Dn_Up == -1))
    {
    ExitShort(Convert.ToInt32(DefaultQuantity), "", "");
    EMA8_Dn_Up = 0;
    }

    // Set 4
    if ((EMA8_Dn_Up != 0)
    && (EMA8_Dn_Up == 1))
    {
    EnterLong(Convert.ToInt32(DefaultQuantity), @"");
    EMA8_Dn_Up = 0;
    }

    }

    #2
    Hello Tonofit,

    To understand why the script is behaving as it is, such as placing orders or not placing orders or drawing objects when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

    In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar.

    Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

    I am happy to assist you with analyzing the output from the output window.

    Run or backtest the script and when the output from the output window appears save this by right-clicking the output window and selecting Save As... -> give the output file a name and save -> then attach the output from both computers to your reply.

    Below is a link to a forum post that demonstrates using prints to understand behavior and includes a link to a video recorded using the Strategy Builder to add prints.

    https://ninjatrader.com/support/foru...121#post791121

    Please let me know if I may further assist with analyzing the output or if you need any assistance creating a print.
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Today, 05:17 AM
    0 responses
    52 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    130 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    70 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    44 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    48 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X