Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

12,21,50 only entering when all three cross over PS newb here

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

    12,21,50 only entering when all three cross over PS newb here

    hello,

    apologies i am new to this. i have just created my first "strategy"

    i have created a hyperscaleper on the 1 second that is proving to be very succefull, however it keeps trying to take long positions on the 1 minute downtrend, i only want it to take long positions on the 1 minute uptrend. i have...deduced..that the 50 ema works well. im trying to get the script to only enter if its above the 50 ema and then when the 12,21 cross over, unfortunately its only entering when all 3 have crossed over at the same time. see script. PS i also have no idea what im doing and completely winging it.

    FastMA = 12;
    SlowMA = 21;
    LongMA = 50;
    AddPlot(Brushes.Pink, "FastMA"); // stored as Plots[0] and Values[0]
    AddPlot(Brushes.Blue, "SlowMA"); // stored as Plots[1] and Values[1]
    AddPlot(Brushes.Blue, "LongMA"); // stored as Plots[2] and Values[2]

    }
    else if (State == State.Configure)
    {
    }
    }

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;
    //Add your custom strategy logic here.

    // Check if RTH
    bool market_open = ToTime(Time[0]) >= 150000 && ToTime(Time[0]) <= 210000;

    // Moving Average
    bool cross_above = CrossAbove(EMA(FastMA), EMA(SlowMA), 1);
    bool cross_below = CrossBelow(EMA(FastMA), EMA(SlowMA), 1);
    bool crossabove= CrossAbove(EMA(SlowMA), EMA(LongMA), 1);



    Values[0][0] = EMA(FastMA)[0];
    Values[1][0] = EMA(SlowMA)[0];
    Values[2][0] = EMA(LongMA)[0];



    //Etner Positions
    if (market_open)
    {
    if (cross_above)
    if (crossabove)
    {
    EnterLong(Convert.ToInt32(DefaultQuantity), "");
    SetStopLoss("", CalculationMode.Ticks, 20, false);
    SetProfitTarget("", CalculationMode.Ticks, 10);


    }

    // Exit Postitions
    if (!market_open)
    {
    ExitLong();

    }
    }

    #2
    Hello csksbot,

    Welcome the NinjaTrader forums and congrats on getting started with your first NinjaScript Strategy!

    "i have created a hyperscaleper on the 1 second that is proving to be very succefull, however it keeps trying to take long positions on the 1 minute downtrend"

    To confirm, is the chart a 1 second chart? (Or is this a 1 minute chart?)

    " i only want it to take long positions on the 1 minute uptrend. i have...deduced..that the 50 ema works well. im trying to get the script to only enter if its above the 50 ema and then when the 12,21 cross over"

    So both must be true, is this correct? The market price (Close[0]) must be above the EMA 50 at the same time EMA 12 is crossing above the EMA 21?

    if (Close[0] > EMA(50)[0] && CrossAbove(EMA(12), EMA(21))

    It would also be recommend to use prints if the behavior is not as you expect.

    Print(string.Format("{0} | Close[0]: {1} > EMA(50)[0]: {2} && EMA(12)[1]: {3} < EMA(21)[1]: {4} && EMA(12)[0]: {5} > EMA(21)[0]: {6}", Time[0], Close[0], EMA(50)[0], EMA(12)[1], EMA(21)[1], EMA(12)[0], EMA(21)[0]));

    Below is a link to a support article on using prints to understand behavior.


    Last, it is advised to call Set methods before calling an entry method.

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hello csksbot,

      Welcome the NinjaTrader forums and congrats on getting started with your first NinjaScript Strategy!

      "i have created a hyperscaleper on the 1 second that is proving to be very succefull, however it keeps trying to take long positions on the 1 minute downtrend"

      To confirm, is the chart a 1 second chart? (Or is this a 1 minute chart?)

      " i only want it to take long positions on the 1 minute uptrend. i have...deduced..that the 50 ema works well. im trying to get the script to only enter if its above the 50 ema and then when the 12,21 cross over"

      So both must be true, is this correct? The market price (Close[0]) must be above the EMA 50 at the same time EMA 12 is crossing above the EMA 21?

      if (Close[0] > EMA(50)[0] && CrossAbove(EMA(12), EMA(21))

      It would also be recommend to use prints if the behavior is not as you expect.

      Print(string.Format("{0} | Close[0]: {1} > EMA(50)[0]: {2} && EMA(12)[1]: {3} < EMA(21)[1]: {4} && EMA(12)[0]: {5} > EMA(21)[0]: {6}", Time[0], Close[0], EMA(50)[0], EMA(12)[1], EMA(21)[1], EMA(12)[0], EMA(21)[0]));

      Below is a link to a support article on using prints to understand behavior.


      Last, it is advised to call Set methods before calling an entry method.



      hi thanks for reply yes its a 1 second scalper but uses the 1 minute trend as a guide for when not or to take a trade. thanks for reply. i actually made some amendments so that it works now FYI see below.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by futurenow, 12-06-2021, 05:49 PM
      18 responses
      878 views
      0 likes
      Last Post dj0ntz
      by dj0ntz
       
      Started by nailz420, 05-14-2025, 09:14 AM
      1 response
      116 views
      0 likes
      Last Post NinjaTrader_ChristopherJ  
      Started by NinjaTrader_Brett, 05-12-2025, 03:19 PM
      0 responses
      520 views
      1 like
      Last Post NinjaTrader_Brett  
      Started by domjabs, 05-12-2025, 01:55 PM
      2 responses
      83 views
      0 likes
      Last Post domjabs
      by domjabs
       
      Started by Morning Cup Of Trades, 05-12-2025, 11:50 AM
      1 response
      121 views
      0 likes
      Last Post NinjaTrader_ChristopherJ  
      Working...
      X