NexusFi: Find Your Edge


Home Menu

 





Need help on NinjaTrader 8 Strategy issue with HalfTrend indicator


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one jonesy73 with 3 posts (0 thanks)
    2. looks_two mohelsheikh with 3 posts (1 thanks)
    3. looks_3 trendisyourfriend with 2 posts (2 thanks)
    4. looks_4 BERN Algos with 1 posts (0 thanks)
    1. trending_up 678 views
    2. thumb_up 3 thanks given
    3. group 4 followers
    1. forum 8 posts
    2. attach_file 1 attachments




 
Search this Thread

Need help on NinjaTrader 8 Strategy issue with HalfTrend indicator

  #1 (permalink)
 mohelsheikh 
Mississauga, Canada
 
Experience: None
Platform: NinjaTrader
Trading: Futures
Posts: 8 since Apr 2023
Thanks Given: 0
Thanks Received: 2

Hello,
i am creating a strategy for NinjaTrader 8 that receives a signal from HalfTrind indicator to buy or sell
when i receive a signal, i check if there is any other position is open, then i close it and open the new one.

currently, when i try to open a new order, i got this error message:

Buy stop or buy stop limit orders can't be placed below the market. affected order: BuyToCover 1 stopMarket @1234.00

another message:
Strategy submitted an order that generated the following error 'Order rejected'. Strategy has sent cancel requests, attempted to close the position and terminated itself.

i debug the code, and this was the value when i get the erro
Short High[0]: 4138.25 currentATR: 3.0280371924987 newStop: 4141.2780371925 _stop: 4141.2780371925

 
Code
                                if (Position.MarketPosition == MarketPosition.Flat)
                                {
                                    EnterShort("ShortOrder");
                                    var newStop = High[0] + currentATR;
                                    _shortStop = _shortStop == 0 ? newStop : _shortStop;
                                    _shortStop = Math.Min(_shortStop, newStop);
                                    Print("3 " + ShortOrder + " High[0]: " + High[0] + "  currentATR: " + currentATR + "   newStop: " + newStop + "   _stop: " + _shortStop);
                                    ExitShortStopMarket(_shortStop, "Trail Short", ShortOrder);
                                    //SetStopLoss(CalculationMode.Price, _shortStop);
                                }
                                else if (Position.MarketPosition == MarketPosition.Long)
                                {
                                    ExitLong("LongOrder");
                                    if (Low[0] < Position.AveragePrice)
                                    {
                                        EnterShort("ShortOrder");
                                        var newStop = High[0] + currentATR;
                                        _shortStop = _shortStop == 0 ? newStop : _shortStop;
                                        _shortStop = Math.Min(_shortStop, newStop);
                                        Print("4 " + ShortOrder + " High[0]: " + High[0] + "  currentATR: " + currentATR + "   newStop: " + newStop + "   _stop: " + _shortStop);
                                        ExitShortStopMarket(_shortStop, "Trail Short", ShortOrder);
                                        //SetStopLoss(CalculationMode.Price, _shortStop);
                                    }
                                }​

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Exit Strategy
NinjaTrader
MC PL editor upgrade
MultiCharts
ZombieSqueeze
Platforms and Indicators
Trade idea based off three indicators.
Traders Hideout
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
27 thanks
Tao te Trade: way of the WLD
24 thanks
Diary of a simple price action trader
22 thanks
My NQ Trading Journal
14 thanks
GFIs1 1 DAX trade per day journal
9 thanks
  #2 (permalink)
 BERN Algos 
Bologna Italy
 
Experience: Advanced
Platform: nt8
Broker: NinjaTrader
Trading: futures
Posts: 42 since Jun 2022
Thanks Given: 11
Thanks Received: 38


mohelsheikh View Post
Hello,
My problem is, I'm getting an error message when I try to make a long request, a short request
The strategy sent cancellation requests and attempted to close the position and terminate itself.
Sell Stop or Sell Stop orders cannot be placed above the market. Affected order: Sell 1 StopMarket @ 4133.5

It could help if you may post your strategy or, at least, the order placing section

Reply With Quote
  #3 (permalink)
jonesy73
London, Canada
 
Posts: 7 since Apr 2023
Thanks Given: 3
Thanks Received: 1


I am getting the exact same errors as you with a different strategy than yours. It executes the buy, target and stop perfectly when the market (es, nq) is moving slowly(eth) but during regular trading hours, when the market moves quickly, I get the same error "Sell stop or sell stop orders cannot be placed above the market"(or Below the Market) This disables my strategy and leaves my live order hanging in the market without a stop or takeprofit. This could be because the market moved quickly past the stop and won't execute at that level anymore. I'm wondering if there's any error proofing someone could post that would ensure that the stop or target executes at whatever price the market is currently at, even if its a few ticks past my stop or target. I'm using rithmic data feed with NT8 version 8.1.1.6
Cheers, Derek.


mohelsheikh View Post
Hello,
I am creating a NinjaTrader 8 strategy, and this strategy reads the HalfTrend indicator to determine entry points. When the strategy receives an UpSignal[0] from indicatoe, it will automaticly place a market order. If it is short, it will exit any current long position first and then enter a long position. I keep long open until I receive SnSignal[0], check MarketPosition, if fLong, exit long then enter sell, and so on.
My problem is, I'm getting an error message when I try to make a long request, a short request
The strategy sent cancellation requests and attempted to close the position and terminate itself.
Sell Stop or Sell Stop orders cannot be placed above the market. Affected order: Sell 1 StopMarket @ 4133.5


Reply With Quote
  #4 (permalink)
 mohelsheikh 
Mississauga, Canada
 
Experience: None
Platform: NinjaTrader
Trading: Futures
Posts: 8 since Apr 2023
Thanks Given: 0
Thanks Received: 2


BERN Algos View Post
It could help if you may post your strategy or, at least, the order placing section

Thank you,
I did, it is in the post

Started this thread Reply With Quote
  #5 (permalink)
 
trendisyourfriend's Avatar
 trendisyourfriend 
Quebec Canada
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG
Trading: ES, NQ, YM
Frequency: Daily
Duration: Minutes
Posts: 4,527 since Oct 2009
Thanks Given: 4,174
Thanks Received: 6,019

When using stop orders you need to make sure your not trying to place it behond the current bid or ask:

Use this before sending your order:
https://ninjatrader.com/support/helpGuides/nt8/getcurrentask.htm
https://ninjatrader.com/support/helpGuides/nt8/getcurrentbid.htm

Just make sure when you cover your buy or sell position you can do it safely using these methods.

Here is a screen capture of a code snippet i use for placing a buy stop or sell stop safely:


Reply With Quote
Thanked by:
  #6 (permalink)
jonesy73
London, Canada
 
Posts: 7 since Apr 2023
Thanks Given: 3
Thanks Received: 1

Thank you very much for your reply. It looks like getting the current ask/bid should work in my situation. I'll try it as soon as the market opens and let you know how I make out. Enjoy your weekend! Derek.


trendisyourfriend View Post
When using stop orders you need to make sure your not trying to place it behond the current bid or ask:

Use this before sending your order:
https://ninjatrader.com/support/helpGuides/nt8/getcurrentask.htm
https://ninjatrader.com/support/helpGuides/nt8/getcurrentbid.htm

Just make sure when you cover your buy or sell position you can do it safely using these methods.

Here is a screen capture of a code snippet i use for placing a buy stop or sell stop safely:



Reply With Quote
  #7 (permalink)
jonesy73
London, Canada
 
Posts: 7 since Apr 2023
Thanks Given: 3
Thanks Received: 1

So, in the code below, in OnBarUpdate(), the support price I'm using is based on the indicator sr. How would I use GetCurrentAsk() ?

var support = _sr.SupportPrice[0];

if (Low[0] <= support && Close[0] >= support)
{
if (_lastLevel.ApproxCompare(support) != 0)
{
_lastBar = CurrentBar;
_lastLevel = support;
SetProfitTarget(CalculationMode.Ticks, TakeProfit);
var ticks = (Close[0] - Low[0]) / TickSize;
if (ticks < 4) ticks = 4;
ticks += ExtraSLTicks;
SetStopLoss(CalculationMode.Ticks, ticks);
EnterLong(1, 1, "buy");
return;
}
}





trendisyourfriend View Post
When using stop orders you need to make sure your not trying to place it behond the current bid or ask:

Use this before sending your order:
https://ninjatrader.com/support/helpGuides/nt8/getcurrentask.htm
https://ninjatrader.com/support/helpGuides/nt8/getcurrentbid.htm

Just make sure when you cover your buy or sell position you can do it safely using these methods.

Here is a screen capture of a code snippet i use for placing a buy stop or sell stop safely:



Reply With Quote
  #8 (permalink)
 
trendisyourfriend's Avatar
 trendisyourfriend 
Quebec Canada
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG
Trading: ES, NQ, YM
Frequency: Daily
Duration: Minutes
Posts: 4,527 since Oct 2009
Thanks Given: 4,174
Thanks Received: 6,019


Quoting 
Entry() methods will reverse the position automatically. For example if you are in a 1 contract long position and now call EnterShort() -> you will see 2 executions, one to close the prior long position and the other to get you into the desired 1 contract short position.

Take the time to read the Help section and ask your questions on the Ninjatrader forum. There seems to be a minority of people using Ninjatrader on Futures.io these days.
https://ninjatrader.com/support/helpGuides/nt8/managed_approach.htm

Reply With Quote
  #9 (permalink)
 mohelsheikh 
Mississauga, Canada
 
Experience: None
Platform: NinjaTrader
Trading: Futures
Posts: 8 since Apr 2023
Thanks Given: 0
Thanks Received: 2


trendisyourfriend View Post
When using stop orders you need to make sure your not trying to place it behond the current bid or ask:

Use this before sending your order:
https://ninjatrader.com/support/helpGuides/nt8/getcurrentask.htm
https://ninjatrader.com/support/helpGuides/nt8/getcurrentbid.htm

Just make sure when you cover your buy or sell position you can do it safely using these methods.

Here is a screen capture of a code snippet i use for placing a buy stop or sell stop safely:



thank you so much for your help
amazing

Mohamed

Started this thread Reply With Quote
Thanked by:




Last Updated on May 24, 2023


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts