NexusFi: Find Your Edge


Home Menu

 





Strategy Builder question


Discussion in NinjaTrader

Updated
    1. trending_up 1,037 views
    2. thumb_up 0 thanks given
    3. group 3 followers
    1. forum 5 posts
    2. attach_file 0 attachments




 
Search this Thread

Strategy Builder question

  #1 (permalink)
 Vegas3416 
Austin Tx
 
Experience: Beginner
Platform: NinjaTrader
Trading: CME
Posts: 7 since Nov 2020
Thanks Given: 0
Thanks Received: 0

Simple question

When setting a Boolean value in strategy builder NinjaScript
I enter a trade and set that Boolean value to true.

Then when I exit I have two variations of exits.

One is by an indicator another is if profit target is hit.

Issue is if profit target hits I don’t know where that gets hit to where I can set that Boolean value back to false because it gets triggered outside of the on bar update method.

This is when I use the SetProfitTarget();

Maybe I’m just having a brain fart but any help is appreciated

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Better Renko Gaps
The Elite Circle
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
MC PL editor upgrade
MultiCharts
Bigger Wins or Fewer Losses?
Traders Hideout
Trade idea based off three indicators.
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
33 thanks
Tao te Trade: way of the WLD
24 thanks
My NQ Trading Journal
14 thanks
HumbleTraders next chapter
11 thanks
GFIs1 1 DAX trade per day journal
11 thanks
  #2 (permalink)
 Bitnut 
Skive, Denmark
 
Experience: Intermediate
Platform: NinjaTrader, MetaTrader
Trading: ES, YM, NQ
Posts: 3 since May 2020
Thanks Given: 0
Thanks Received: 1

You have a few options.

If your boolean only tracks if you have a position or not, I would recommend just using MarketPosition instead of your boolean. If MarketPosition == MarketPosition.Flat then you don't have a position.

Otherwise, you can override one of the events that will get triggered when your order is filled:
- OnOrderUpdate (https://ninjatrader.com/support/helpGuides/nt8/?onorderupdate.htm)
- OnExecutionUpdate (https://ninjatrader.com/support/helpGuides/nt8/?onexecutionupdate.htm)
- OnPositionUpdate (https://ninjatrader.com/support/helpGuides/nt8/?onpositionupdate.htm)

I don't know which event would suit you best. Some of them will trigger on any order update, so you would have to check the parameters to only set your boolean when an order is filled and not on any update.
Use the first option if possible. It's the simplest

Reply With Quote
  #3 (permalink)
 Vegas3416 
Austin Tx
 
Experience: Beginner
Platform: NinjaTrader
Trading: CME
Posts: 7 since Nov 2020
Thanks Given: 0
Thanks Received: 0


I swear I used this but wasn't getting it to trigger. Actually I was using

if(Position.MarketPosition != MarketPosition.Flat) {
Then I'm in a trade and if == to Flat then I'm not but it wasn't working.
}


I guess I can try just if(MarketPosition == MarketPosition.Flat) don't think I tried it like that as I saw the above in the docs.

Started this thread Reply With Quote
  #4 (permalink)
 Vegas3416 
Austin Tx
 
Experience: Beginner
Platform: NinjaTrader
Trading: CME
Posts: 7 since Nov 2020
Thanks Given: 0
Thanks Received: 0

This worked out. I guess maybe I was calling it wrong before?? No idea.

Does anyone know how to basically hold off before taking a trade.

So what I mean is. Say a specific type of trade triggered. So lets say I enter a short and it has a specific type of tag for it. I save that tag and it goes through the trade and finishes. The tag is still saved but now I want it to wait for at least 4 bars to complete before I want it to reevaluate the indicators its looking at to see if it should re-enter a trade again.

So trade enters short -> trade closes -> tag saved -> waits 4 bars while tag is a specific type. After 4 bars tag is cleared and strategy goes back to reevaluating the setups to determine if it should re-enter again.

Started this thread Reply With Quote
  #5 (permalink)
 Vegas3416 
Austin Tx
 
Experience: Beginner
Platform: NinjaTrader
Trading: CME
Posts: 7 since Nov 2020
Thanks Given: 0
Thanks Received: 0

I figured out the 4 bars situation. Hopefully this helps someone else:

// Only enter if at least 4 bars has passed since our last exit or if we have never traded yet
if ((BarsSinceExitExecution() > 4 || BarsSinceExitExecution() == -1) && CrossAbove(SMA(10), SMA(20), 1))
EnterLong();



Link for NT: https://ninjatrader.com/support/helpGuides/nt8/?standard_deviation_stddev.htm

Started this thread Reply With Quote
  #6 (permalink)
 Bitnut 
Skive, Denmark
 
Experience: Intermediate
Platform: NinjaTrader, MetaTrader
Trading: ES, YM, NQ
Posts: 3 since May 2020
Thanks Given: 0
Thanks Received: 1

Weird that it didn't work before. Anyway, great that it works now

Thanks for the link, I did not know about that function, could be handy.
I think the correct link is this: https://ninjatrader.com/support/helpGuides/nt8/?barssinceexitexecution.htm
The linking is a bit strange because the address doesn't change when you browse the left menu in the help guide.

Reply With Quote




Last Updated on February 25, 2021


© 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