futures io



Need help on NinjaTrader 8 Strategy issue with HalfTrend indicator


Discussion in NinjaTrader

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




Welcome to futures io: the largest futures trading community on the planet, with well over 150,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

Need help on NinjaTrader 8 Strategy issue with HalfTrend indicator

(login for full post details)
  #1 (permalink)
 mohelsheikh 
Mississauga, Canada
 
Experience: None
Platform: NinjaTrader
Trading: Futures
 
Posts: 7 since Apr 2023
Thanks: 0 given, 2 received

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 futures io?
About Automated Trading from Watch List
MultiCharts
Rival systems and Exegy
Platforms and Indicators
New subforum for Generative AI and LLM
Elite Generative AI / LLM Trading
What is Your Experience with TradeStations API?
TradeStation
Mt5 Tradestation Integration
TradeStation
 
Best Threads (Most Thanked)
in the last 7 days on futures io
Big Mike in Ecuador
42 thanks
top trading courses
13 thanks
futures io site changelog and issues/problem reporting
11 thanks
Trader Sentiment Tool for our community
11 thanks
Hedge your losers to turn them into winners
10 thanks

 
(login for full post details)
  #2 (permalink)
 BERN Algos 
bologna italy
 
Experience: Advanced
Platform: nt8
Broker: NinaTrader
Trading: futures
 
Posts: 39 since Jun 2022
Thanks: 10 given, 34 received


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
 
(login for full post details)
  #3 (permalink)
jonesy73
London, Canada
 
 
Posts: 7 since Apr 2023
Thanks: 3 given, 1 received


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
 
(login for full post details)
  #4 (permalink)
 mohelsheikh 
Mississauga, Canada
 
Experience: None
Platform: NinjaTrader
Trading: Futures
 
Posts: 7 since Apr 2023
Thanks: 0 given, 2 received


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
 
(login for full post details)
  #5 (permalink)
 trendisyourfriend 
Legendary Market Wizard
Quebec Canada
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG
Trading: ES, NQ, YM
 
trendisyourfriend's Avatar
 
Posts: 4,367 since Oct 2009
Thanks: 4,050 given, 5,769 received

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
The following 2 users say Thank You to trendisyourfriend for this post:
 
(login for full post details)
  #6 (permalink)
jonesy73
London, Canada
 
 
Posts: 7 since Apr 2023
Thanks: 3 given, 1 received

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
 
(login for full post details)
  #7 (permalink)
jonesy73
London, Canada
 
 
Posts: 7 since Apr 2023
Thanks: 3 given, 1 received

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
 
(login for full post details)
  #8 (permalink)
 trendisyourfriend 
Legendary Market Wizard
Quebec Canada
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG
Trading: ES, NQ, YM
 
trendisyourfriend's Avatar
 
Posts: 4,367 since Oct 2009
Thanks: 4,050 given, 5,769 received


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
 
(login for full post details)
  #9 (permalink)
 mohelsheikh 
Mississauga, Canada
 
Experience: None
Platform: NinjaTrader
Trading: Futures
 
Posts: 7 since Apr 2023
Thanks: 0 given, 2 received


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
The following user says Thank You to mohelsheikh for this post:


futures io Trading Community Platforms and Indicators NinjaTrader > Need help on NinjaTrader 8 Strategy issue with HalfTrend indicator


Last Updated on May 24, 2023



Copyright © 2023 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada), info@futures.io
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.
no new posts