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

Why doesn't this compile?

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

    Why doesn't this compile?

    I keep getting compile errors on line 154 (the enter short line near the bottom) and the profit target and stop loss do not work. Can anyone help me figure out why?

    protected override void Initialize()
    {
    if (_htfPeriod > 0)
    {
    _usesHigherTimeFrame = true;
    switch (_htfType)
    {
    case 1: Add(PeriodType.Second, _htfPeriod); break;
    case 2: Add(PeriodType.Minute, _htfPeriod); break;
    case 3: Add(PeriodType.Day, _htfPeriod); break;
    case 4: Add(PeriodType.Week, _htfPeriod); break;
    case 5: Add(PeriodType.Month, _htfPeriod); break;
    case 6: Add(PeriodType.Year, _htfPeriod); break;
    case 7: Add(PeriodType.Tick, _htfPeriod); break;
    case 8: Add(PeriodType.Range, _htfPeriod); break;
    case 9: Add(PeriodType.Volume, _htfPeriod); break;
    default: _usesHigherTimeFrame = false; break;
    }
    }
    _ema = EMA(13);
    _macd = MACD(12,26,9);
    SetProfitTarget("", CalculationMode.Ticks, 7);
    SetStopLoss("", CalculationMode.Ticks, 10, false);

    Add(_ema);
    Add(_macd);


    CalculateOnBarClose = true;
    }

    private void MyInitialize()
    {
    if (_usesHigherTimeFrame)
    {
    _htfMacd = MACD(BarsArray[1],12,26,9);
    _htfEma = EMA(BarsArray[1],26);
    }
    _initialized = true;
    }

    protected override void OnBarUpdate()
    {
    if (!_initialized) MyInitialize();

    if (TimeToTrade)
    {
    DoPlots();

    if (!InPosition)
    LookForTrade();

    if (InPosition)
    ManagePosition();
    }
    else if (InPosition)
    FlattenPosition();

    }

    private void DoPlots()
    {
    if (BarsInProgress == 0 && _usesHigherTimeFrame)
    {
    if (_htfTrend == TREND_UP)
    BackColor = Color.FromArgb(100, Color.LightGreen);
    else if (_htfTrend == TREND_DOWN)
    BackColor = Color.FromArgb(100, Color.LightPink);
    else
    BackColor = Color.FromArgb(100, Color.LightYellow);
    }
    }

    private void LookForTrade()
    {
    if (_usesHigherTimeFrame)
    {
    if (BarsInProgress == 1)
    {
    if (_htfEma[0] > _htfEma[1] && _htfMacd.Diff[0] > _htfMacd.Diff[1])
    _htfTrend = TREND_UP;
    else if (_htfEma[0] < _htfEma[1] && _htfMacd.Diff[0] < _htfMacd.Diff[1])
    _htfTrend = TREND_DOWN;
    else
    _htfTrend = TREND_NONE;

    PrintDebug("HTF trend is " + _htfTrend);
    }
    }
    if (BarsInProgress == 0)
    {
    if (_ema[0] > _ema[1] && _macd.Diff[0] > _macd.Diff[1])
    {
    bool buy = true;
    if (_usesHigherTimeFrame &&_htfTrend != TREND_UP)
    buy = false;

    if (buy)
    EnterLongLimit(1, GetCurrentAsk() , "");
    }

    if (_ema[0] < _ema[1] && _macd.Diff[0] < _macd.Diff[1])
    {
    bool sell = true;
    if (_usesHigherTimeFrame &&_htfTrend != TREND_DOWN)
    sell = false;

    if (sell)
    EnterShort(1, GetCurrentAsk() , "");
    }
    }
    }

    #2
    Hi Jmoran,

    Thank you for your post.

    What is the error message you are receiving?

    From the provided script it appears that you are trying to assign a price value to the EnterShort() is this correct?
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      If you enter long limit at the current ask, you should enter short limit at the current bid. However, you simply enter short at the current ask without using the appropriate script command EnterShortLimit().

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Segwin, 05-07-2018, 02:15 PM
      10 responses
      1,769 views
      0 likes
      Last Post Leafcutter  
      Started by Rapine Heihei, 04-23-2024, 07:51 PM
      2 responses
      30 views
      0 likes
      Last Post Max238
      by Max238
       
      Started by Shansen, 08-30-2019, 10:18 PM
      24 responses
      943 views
      0 likes
      Last Post spwizard  
      Started by Max238, Today, 01:28 AM
      0 responses
      10 views
      0 likes
      Last Post Max238
      by Max238
       
      Started by rocketman7, Today, 01:00 AM
      0 responses
      7 views
      0 likes
      Last Post rocketman7  
      Working...
      X