NexusFi: Find Your Edge


Home Menu

 





Want to create an indicator and have no idea where to start?


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one forrestang with 58 posts (9 thanks)
    2. looks_two ThatManFromTexas with 16 posts (5 thanks)
    3. looks_3 LostTrader with 6 posts (2 thanks)
    4. looks_4 cory with 5 posts (3 thanks)
      Best Posters
    1. looks_one cory with 0.6 thanks per post
    2. looks_two ThatManFromTexas with 0.3 thanks per post
    3. looks_3 LostTrader with 0.3 thanks per post
    4. looks_4 forrestang with 0.2 thanks per post
    1. trending_up 26,059 views
    2. thumb_up 20 thanks given
    3. group 5 followers
    1. forum 93 posts
    2. attach_file 30 attachments




 
Search this Thread

Want to create an indicator and have no idea where to start?

  #51 (permalink)
 
forrestang's Avatar
 forrestang 
Chicago IL
 
Experience: None
Platform: Ninja, MT4, Matlab
Broker: CQG, AMP, MB, DTN
Trading: E/U, G/U
Posts: 1,329 since Jun 2010
Thanks Given: 354
Thanks Received: 1,047

For example, here is the code snippet to generate one of the buy signals, which at the moment is just an UpArrow. Initially I was thinking you would have to have a parity bit or flag that would trigger to some value upon this arrow being printed. That was the idea behind that variable I have there called "inTrade."

I was thinking I'd add another IF statement outside of that block where the UpArrow is printed to check to see if inTrade==true, and if it is, means we are in a trade so check to see if sell condition is met.

 
Code
//1a_A Trade
			
			if(ERG_Trade().Ltsx[0] == 1 && ERG_Str1().HISTSlope[0] == 1 && ERG_Trade().HIST[0] >= 10 )
			{
				if(ERG_Trade().HISTSlope[1] == 1 && ERG_Trade().HISTSlope[2] == 1 && ERG_Trade().HISTSlope[3] == -1)
				{	
				DrawArrowUp("arrow"+CurrentBar, true, 0, Low[0]-12*TickSize, Color.Green);
				DrawText("text0"+CurrentBar, ""+Open.ToString(), 0, Low[0]-30*TickSize, Color.Black);
				DrawText("text1"+CurrentBar ,"1a_A", 0, Low[0]-38*TickSize, Color.Black);
				inTrade = true;			
				}
				
			}

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
MC PL editor upgrade
MultiCharts
Increase in trading performance by 75%
The Elite Circle
ZombieSqueeze
Platforms and Indicators
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Better Renko Gaps
The Elite Circle
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
36 thanks
Spoo-nalysis ES e-mini futures S&P 500
24 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
20 thanks
GFIs1 1 DAX trade per day journal
16 thanks
  #52 (permalink)
 
lolu's Avatar
 lolu 
Lagos, Nigeria
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader, SierraChart
Trading: Euro Currency & Oil
Frequency: Daily
Duration: Hours
Posts: 2,552 since Jun 2009
Thanks Given: 1,049
Thanks Received: 1,678


forrestang View Post
For example, here is the code snippet to generate one of the buy signals, which at the moment is just an UpArrow. Initially I was thinking you would have to have a parity bit or flag that would trigger to some value upon this arrow being printed. That was the idea behind that variable I have there called "inTrade."

I was thinking I'd add another IF statement outside of that block where the UpArrow is printed to check to see if inTrade==true, and if it is, means we are in a trade so check to see if sell condition is met.

 
Code
//1a_A Trade
			
			if(ERG_Trade().Ltsx[0] == 1 && ERG_Str1().HISTSlope[0] == 1 && ERG_Trade().HIST[0] >= 10 )
			{
				if(ERG_Trade().HISTSlope[1] == 1 && ERG_Trade().HISTSlope[2] == 1 && ERG_Trade().HISTSlope[3] == -1)
				{	
				DrawArrowUp("arrow"+CurrentBar, true, 0, Low[0]-12*TickSize, Color.Green);
				DrawText("text0"+CurrentBar, ""+Open.ToString(), 0, Low[0]-30*TickSize, Color.Black);
				DrawText("text1"+CurrentBar ,"1a_A", 0, Low[0]-38*TickSize, Color.Black);
				inTrade = true;			
				}
				
			}

Please, always remember to update the indicator as contained in post #18.

Lolu

Visit my NexusFi Trade Journal Reply With Quote
  #53 (permalink)
 
forrestang's Avatar
 forrestang 
Chicago IL
 
Experience: None
Platform: Ninja, MT4, Matlab
Broker: CQG, AMP, MB, DTN
Trading: E/U, G/U
Posts: 1,329 since Jun 2010
Thanks Given: 354
Thanks Received: 1,047



forrestang View Post

That was the idea behind that variable I have there called "inTrade."

I was thinking I'd add another IF statement outside of that block where the UpArrow is printed to check to see if inTrade==true, and if it is, means we are in a trade so check to see if sell condition is met.

Got it!

I did what I suggested above. Problem is that I have to do this for every individual trade scenario I have, and there are over 200 of them.

Here is the code snippet. I added that flag I spoke of above, so that it only triggers AFTER the entry condition is satisfied.

 
Code
if(ERG_Trade().Ltsx[0] == 1 && ERG_Str1().HISTSlope[0] == 1 && ERG_Trade().HIST[0] >= 10 )
			{
				if(ERG_Trade().HISTSlope[1] == 1 && ERG_Trade().HISTSlope[2] == 1 && ERG_Trade().HISTSlope[3] == -1)
				{	
				DrawArrowUp("arrow"+CurrentBar, true, 0, Low[0]-12*TickSize, Color.Green);
				DrawText("text0"+CurrentBar, ""+Open.ToString(), 0, Low[0]-30*TickSize, Color.Black);
				DrawText("text1"+CurrentBar ,"1a_A", 0, Low[0]-38*TickSize, Color.Black);
				inTrade_1a_A = 1;			
				}
				
				if(inTrade_1a_A == 1 && ERG_Trade().HISTSlope[1] == -1)
				{	
				DrawArrowDown("arrow"+CurrentBar, true, 0, High[0]+12*TickSize, Color.Black);
				DrawText("text2"+CurrentBar, ""+Open.ToString(), 0, High[0]+30*TickSize, Color.Black);
				inTrade_1a_A = 0;			
				}
			}

Attached Thumbnails
Click image for larger version

Name:	Prime2011-06-01_094546.jpg
Views:	252
Size:	60.4 KB
ID:	39770  
Started this thread Reply With Quote
  #54 (permalink)
 
forrestang's Avatar
 forrestang 
Chicago IL
 
Experience: None
Platform: Ninja, MT4, Matlab
Broker: CQG, AMP, MB, DTN
Trading: E/U, G/U
Posts: 1,329 since Jun 2010
Thanks Given: 354
Thanks Received: 1,047


lolu View Post
Please, always remember to update the indicator as contained in post #18.

Lolu

I think it should be? I'm pretty sure I posted it earlier this morning?

Started this thread Reply With Quote
  #55 (permalink)
 
cory's Avatar
 cory 
virginia
 
Experience: Intermediate
Platform: ninja
Trading: NQ
Posts: 6,098 since Jun 2009
Thanks Given: 877
Thanks Received: 8,090


forrestang View Post
Got the logic done and it's doing what I want.

Is there a simple way to add a closing arrow to this? Does NT have some function built in so that once my green/red arrow prints to show my entry, I can plot an exit AFTER that entry arrow?

Asking as eventually I'll want to kick this out to a strategy.

if you convert it into a strategy, it draws arrows for entry and exit for you. You can very this by applying sample strategy ma cross, enable = true and you will see arrows on your chart.
 
Code
		protected override void OnBarUpdate()
		{
			if (CrossAbove(SMA(Fast), SMA(Slow), 1))
			    EnterLong();
			else if (CrossBelow(SMA(Fast), SMA(Slow), 1))
			    EnterShort();
		}

Reply With Quote
Thanked by:
  #56 (permalink)
 
forrestang's Avatar
 forrestang 
Chicago IL
 
Experience: None
Platform: Ninja, MT4, Matlab
Broker: CQG, AMP, MB, DTN
Trading: E/U, G/U
Posts: 1,329 since Jun 2010
Thanks Given: 354
Thanks Received: 1,047


cory View Post
if you convert it into a strategy, it draws arrows for entry and exit for you. You can very this by applying sample strategy ma cross, enable = true and you will see arrows on your chart.

Excellent!

Since I have it setup when to draw an arrow up, and attached to it already is the exit.... so basically all I would need to do is replace the logic for drawing the arrows and the text I have with the "EnterLong()/EnterShort()" short commands?

Is there a command for exiting the signals, or do you just enter "EnterShort()" to exit a long trade for example?

Also, when I do create a strategy for this, if I have over 200 individual setups that I want to collect statistics for individually, do I have to individually toggle them on/off in the script and then test? Or will that be taken care of in the "signalName" parameter in the EnterLong()? Or is "signalName" just for visual reference on the chart?

NinjaTrader Version 7

Started this thread Reply With Quote
  #57 (permalink)
 
forrestang's Avatar
 forrestang 
Chicago IL
 
Experience: None
Platform: Ninja, MT4, Matlab
Broker: CQG, AMP, MB, DTN
Trading: E/U, G/U
Posts: 1,329 since Jun 2010
Thanks Given: 354
Thanks Received: 1,047


forrestang View Post

Is there a command for exiting the signals, or do you just enter "EnterShort()" to exit a long trade for example?

Ah, found the ExitLong() command and connecting it to the entry via 'signalName' parameter.

Started this thread Reply With Quote
  #58 (permalink)
 
ThatManFromTexas's Avatar
 ThatManFromTexas 
Houston,Tx
 
Experience: Advanced
Platform: NinjaTrader
Broker: Mirus Futures/Zen-Fire
Trading: TF
Posts: 2,265 since Feb 2010
Thanks Given: 1,206
Thanks Received: 4,353


forrestang View Post
For example, here is the code snippet to generate one of the buy signals, which at the moment is just an UpArrow. Initially I was thinking you would have to have a parity bit or flag that would trigger to some value upon this arrow being printed. That was the idea behind that variable I have there called "inTrade."

I was thinking I'd add another IF statement outside of that block where the UpArrow is printed to check to see if inTrade==true, and if it is, means we are in a trade so check to see if sell condition is met.

 
Code
//1a_A Trade
			
			if(ERG_Trade().Ltsx[0] == 1 && ERG_Str1().HISTSlope[0] == 1 && ERG_Trade().HIST[0] >= 10 )
			{
				if(ERG_Trade().HISTSlope[1] == 1 && ERG_Trade().HISTSlope[2] == 1 && ERG_Trade().HISTSlope[3] == -1)
				{	
				DrawArrowUp("arrow"+CurrentBar, true, 0, Low[0]-12*TickSize, Color.Green);
				DrawText("text0"+CurrentBar, ""+Open.ToString(), 0, Low[0]-30*TickSize, Color.Black);
				DrawText("text1"+CurrentBar ,"1a_A", 0, Low[0]-38*TickSize, Color.Black);
				inTrade = true;			
				}
				
			}



MarketPosition

Definition
Gets the current market position.



Property Value

MarketPosition.Flat

MarketPosition.Long

MarketPosition.Short



Syntax

Position.MarketPosition


Examples


 
Code
protected override void OnBarUpdate()
{ 
    // If not flat print our open PnL
    if (Position.MarketPosition != MarketPosition.Flat) 
         Print("Open PnL: " + Position.GetProfitLoss(Close[0], PerformanceUnit.Points));
}

I'm just a simple man trading a simple plan.

My daddy always said, "Every day above ground is a good day!"
Reply With Quote
Thanked by:
  #59 (permalink)
 
ThatManFromTexas's Avatar
 ThatManFromTexas 
Houston,Tx
 
Experience: Advanced
Platform: NinjaTrader
Broker: Mirus Futures/Zen-Fire
Trading: TF
Posts: 2,265 since Feb 2010
Thanks Given: 1,206
Thanks Received: 4,353


forrestang View Post
Ah, found the ExitLong() command and connecting it to the entry via 'signalName' parameter.

You can also tie your strategy to an "ATM" strategy and let it handle the Stops and Targets for you.

SampleATMstrategy.zip

I'm just a simple man trading a simple plan.

My daddy always said, "Every day above ground is a good day!"
Reply With Quote
  #60 (permalink)
 
forrestang's Avatar
 forrestang 
Chicago IL
 
Experience: None
Platform: Ninja, MT4, Matlab
Broker: CQG, AMP, MB, DTN
Trading: E/U, G/U
Posts: 1,329 since Jun 2010
Thanks Given: 354
Thanks Received: 1,047


Ah shucks!

My exit logic is off. Printing some erroneous arrows along with leaving some of them out.

Started this thread Reply With Quote




Last Updated on January 20, 2012


© 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