NexusFi: Find Your Edge


Home Menu

 





how to setup condition which change another condition in strategy?


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one Tomass with 2 posts (0 thanks)
    2. looks_two rleplae with 2 posts (1 thanks)
    3. looks_3 msfinedu with 1 posts (0 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 2,231 views
    2. thumb_up 1 thanks given
    3. group 4 followers
    1. forum 5 posts
    2. attach_file 1 attachments




 
Search this Thread
  #1 (permalink)
 Tomass 
Prague Czech republic
 
Experience: Beginner
Platform: Ninjatrader
Trading: Futures
Posts: 4 since Sep 2015
Thanks Given: 1
Thanks Received: 0

Hello guys, I am struggling finish my automatic strategy. Strategy is nearly done, just missing one last step. Hope it will be more clear from picture

I have a strategy which works with 3 indicators.
One shows me high/low till 15:30
Second shows me high/low of a day.
third shows me EMA slope (green, grey, red)

Situation 1:if ema slope is green-> if open> "high till 15:30 "= buy signal

Situation 2:if ema slope turns red -> since that time if open > high of a day = buy signal.

If EMA slope is green whole day, my entries are based on "high till 15:30" whole day.. But if Ema slope turns red (at least once, no matter if it turns back to green again) - since that moment entries only: if open > "current high of day" = buy signal(no high till 15:30 anymore...

my problem is that I do not know how to code that change. Basically - if indicator EMA slope turns red, I need to replace order (if open> "high till 15:30 "= buy signal) by order (if open > "current high of day"= buy signal).

Hope it makes some sence what I am trying to code. Will be glad for any advice.

Concrete codes for my strategy:

1. "If open> high till 15:30 -> buy"(that is what I want until some indicator change does not appear)

if (Open[0] >= HiLoOfTimeRange_WithTargetNT7(8, 0, 15, 30, 0, 0).TheHigh[0]
&& EMA (100)[0] > EMA(200)[0]
&& Open[0] > EMA(100)[0]
&& ToTime(Time[0]) >= ToTime(15, 30, 0)
&& ToTime(Time[0]) <= ToTime(21, 30, 0))
{
EnterLong(DefaultQuantity, "high breakout");
}

2. "indicator change". If that condition appears, it will trigger a change.

if (EMA (100)[0] > EMA(200)[0]
&& (EMA(100)[0] == emaslopes2(5, 15, 30, 100).EMAslopedown[0]
|| EMA(100)[0] == emaslopes2(5, 15, 30, 100).EMAdown[0])
&& ToTime(Time[0]) >= ToTime(15, 30, 0)
&& ToTime(Time[0]) <= ToTime(21, 30, 0))


3. new conditions: "if open> high of a day ->buy"

if (Open[0] >= BTH_OHLbyDay(0).CurrentHigh[1]
&& EMA (100)[0] > EMA(200)[0]
&& Open[0] > EMA(100)[0]
&& ToTime(Time[0]) >= ToTime(15, 30, 0)
&& ToTime(Time[0]) <= ToTime(21, 30, 0))
{
EnterLong(DefaultQuantity, "superlong");
}

I just do not know how to make it work all together. I was thinking about using Count if somehow, but I am not sure. Will be glad for any idea or advice. I tried ninjatrader support, but no luck.


Attached Thumbnails
Click image for larger version

Name:	Snímek obrazovky (52).png
Views:	230
Size:	98.1 KB
ID:	216399  
Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Iran Airspace Contract Surges to 33.5% as Project Freedo …
Prediction Markets & Event Contracts
Khamenei Vetoes Uranium Transfer as Peace Odds Surge to …
Prediction Markets & Event Contracts
Fabrication or Framework? Irans Denied MOU Explains the …
Prediction Markets & Event Contracts
CME Lists U.S. Election Event Contracts as 2028 Democrat …
Prediction Markets & Event Contracts
Warsh Confirmed 54-45 on PPI Day -- 97% Say He Holds in …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
24 thanks
2026 Jlab journal
10 thanks
Lady Vols Primer: Trading Volatility Journal
7 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Trying to learn Volume and price action correlation
5 thanks
  #3 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 2,947 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,860


You can use boolean flag's.

your additional condition would then set or reset the flag.


Follow me on X Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #4 (permalink)
 Tomass 
Prague Czech republic
 
Experience: Beginner
Platform: Ninjatrader
Trading: Futures
Posts: 4 since Sep 2015
Thanks Given: 1
Thanks Received: 0


rleplae View Post
You can use boolean flag's.

your additional condition would then set or reset the flag.

Thank you for your advice, I will definitely do some research. To be honest, I am not very good with Ninjascript and never heard about boolean flags before. Do you know any code, or example how it works and how to use it in coding? I will try my research anyway hopefully will find some info. Thank you for your advice once again anyway!


Started this thread Reply With Quote
  #5 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 2,947 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,860


Tomass View Post
Thank you for your advice, I will definitely do some research. To be honest, I am not very good with Ninjascript and never heard about boolean flags before. Do you know any code, or example how it works and how to use it in coding? I will try my research anyway hopefully will find some info. Thank you for your advice once again anyway!

From an educational point of view, you may want to look at the following :



At the start of the strategy you will see various booleans that drive particular behavior..


Follow me on X Visit my NexusFi Trade Journal Reply With Quote
  #6 (permalink)
 msfinedu 
Chennai, India
 
Experience: Intermediate
Platform: IB
Trading: ES
Posts: 1 since Apr 2012
Thanks Given: 2
Thanks Received: 0

Like rleplae suggests reading that thread will definitely hep you learn many things and you should.

Basically if you are going to get to code, you need to have a basic idea of syntax and programming or every small obstacle will tire you. If you haven't gone through NinjaTrader Version 7 please go through to begin with.

In your case in the variable section declare the following:

bool cond1 = false;
bool cond2 = false;
bool cond3 = false;

In your barupdate method, inside each if condition just set the above flags to true

Outof all the ifs you can create the following or whatever combination to go long

if (cond1 && cond2 && cond3)

This is just to get you to the next step while you learn a bit of programming. All the best

MS


Reply With Quote




Last Updated on September 14, 2016


© 2026 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 - Downloads - Top
no new posts