Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Logic for distance between major emas greater then in ticks

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

  • tkaboris
    replied
    Can you please also loot at other similar challenge i have with calculating difference between EMA and Low/High
    HI, My calculation of distance between high of signal bar and slow ema 34(gold line) is not correct. In settings I placed 1 tick but it opens with distance of a lot more then just one tick. See Pic. Can you provide me with a suggestion on how to fix it? AboveBelowForType2 = 1; else if (TradeType2 && emaAngulation

    Leave a comment:


  • tkaboris
    replied
    Hi, Will I need to create a double for opposite to calculate for longs/shorts?
    double EmaDiff = Math.Abs(EMA600[0] - slowEMA[0]);

    Leave a comment:


  • bltdavid
    replied
    Originally posted by tkaboris View Post
    Hi in my strategy settings i have
    DistanceBEMAs = 20;

    and in logic I want to specify to open order only if distance between EMAs are greater in ticks . Is this the correct logic?

    slowEMA[0] > EMA600[0] + DistanceBEMAs * TickSize)
    Probably not.

    You should always take into account that the either of the EMAs
    could be higher or lower than the other.

    Try this,

    Add this code as a new Class variable:
    Code:
    // calculate constant value
    private double EmaDistance;
    Add this code inside State.Configure:
    Code:
    // one time calculation
    EmaDistance = DistanceBEMAs * TickSize;
    Add this code inside OnBarUpdate:
    Code:
    double EmaDiff = Math.Abs(slowEMA[0] - EMA600[0]);
    if (EmaDiff > EmaDistance)
        Print("Distance is good");
    else
        Print("Distance is no good");
    ​Make sense?

    Last edited by bltdavid; 02-01-2023, 11:04 PM.

    Leave a comment:


  • NinjaTrader_ChrisL
    replied
    Hello, thanks for writing in. The best way to verify your code is to use Print so you can see the data that your strategy is producing e.g.

    Code:
    if(slowEMA[0] > EMA600[0] + DistanceBEMAs * TickSize)
    {
       Print("EMA condition true " + Time[0] + " " + slowEMA[0] + " " + EMA600[0] + DistanceBEMAs * TickSize);
       //submit order
    }
    .
    This way you can see exactly the condition you have set up and make adjustments if necessary.

    Leave a comment:


  • Logic for distance between major emas greater then in ticks

    Hi in my strategy settings i have
    DistanceBEMAs = 20;

    and in logic I want to specify to open order only if distance between EMAs are greater in ticks . Is this the correct logic?

    slowEMA[0] > EMA600[0] + DistanceBEMAs * TickSize)

Latest Posts

Collapse

Topics Statistics Last Post
Started by rdtdale, Yesterday, 01:02 PM
2 responses
16 views
0 likes
Last Post rdtdale
by rdtdale
 
Started by TradeSaber, Today, 07:18 AM
0 responses
7 views
0 likes
Last Post TradeSaber  
Started by PaulMohn, Today, 05:00 AM
0 responses
10 views
0 likes
Last Post PaulMohn  
Started by ZenCortexAuCost, Today, 04:24 AM
0 responses
6 views
0 likes
Last Post ZenCortexAuCost  
Started by ZenCortexAuCost, Today, 04:22 AM
0 responses
3 views
0 likes
Last Post ZenCortexAuCost  
Working...
X