NexusFi: Find Your Edge


Home Menu

 





how to extract nearest support price from arraylist?


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one zacharydw00 with 5 posts (3 thanks)
    2. looks_two Trader.Jon with 3 posts (0 thanks)
    3. looks_3 Laserdan with 2 posts (2 thanks)
    4. looks_4 Big Mike with 2 posts (2 thanks)
    1. trending_up 5,666 views
    2. thumb_up 7 thanks given
    3. group 6 followers
    1. forum 15 posts
    2. attach_file 1 attachments




 
Search this Thread

how to extract nearest support price from arraylist?

  #11 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,399 since Jun 2009
Thanks Given: 33,175
Thanks Received: 101,539


zacharydw00 View Post
Does anyone have code that can do this, or something similar?

I have the prices of support/resistance (S/R) lines stored in an ArrayList. When price is moving up, I want to find the nearest S/R line, in said ArrayList, that is currently below the Close price, once price gets 1 point above the nearest S/R line. And, the opposite when price is moving down.
See attached image for illustration.
Thanks guys.

A very long time ago I wrote a strategy to trade Murrey Math lines, and I wrote some functions to get all the levels. I'm willing to share the strategy, but only for elite members (which this thread is not). Can be easily adapted to Pivots.

Here is the thread:


Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
Build trailing stop for micro index(s)
Psychology and Money Management
Online prop firm The Funded Trader (TFT) going under?
Traders Hideout
Are there any eval firms that allow you to sink to your …
Traders Hideout
Ninja Mobile Trader VPS (ninjamobiletrader.com)
Trading Reviews and Vendors
Better Renko Gaps
The Elite Circle
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
59 thanks
Funded Trader platforms
37 thanks
NexusFi site changelog and issues/problem reporting
24 thanks
GFIs1 1 DAX trade per day journal
22 thanks
The Program
19 thanks
  #12 (permalink)
 
zacharydw00's Avatar
 zacharydw00 
Idaho
 
Experience: Intermediate
Platform: NinjaTrader,ToS
Broker: Amp Futures, ToS
Trading: ES, E7, CL, GC
Posts: 149 since Aug 2009
Thanks Given: 87
Thanks Received: 180

Here's the code I ended up with. (including all the debugging Print statements & a Plot statement)
price is typically going to be Close[0]
srOffset is how far price need to be away from any S/R lines. IE. if there is an S/R at 90 & 100, the trend is up, and you want price to confirm above 110 before using S/R @ 100 then set srOffset = 10, when price gets to 100, 90 will be returned.
Trend = true for up trend, false for down trend.
srList hold the list of S/R line values.
 
Code
        private double FindSRline(double price, double srOffset, bool Trend, ArrayList srList)
        {
            srNearest = 0;
            if (Trend)        // UP Trend
            {                        //Print (Time[0].ToString()+" \tCurrentBar =  "+CurrentBar+"\tTrend  = UP  \tsrListCnt  = "+(srList.Count));
                for (i=0; i < srList.Count; i++)                            // Search from Lowest price in srList
                {                    //Print ("srList["+i+"]+1  = "+Math.Round((double)srList[i]+srOffset,2).ToString("0000.00")+"   \tprice  = "+price.ToString("0000.00"));
                    if (price >= (double)srList[i]+srOffset)                // Find Close above SRline+offset
                    {     srNearest = (double)srList[i];        }
                    else 
                    {                //Print ("break; srNearest = srList["+(i)+"]  = "+srNearest.ToString("0000.00"));
                         break;                                             // Stop if price is below SRline+offset
                    }
                }
//                if (srNearest > 0)     Values[srListMax].Set(srNearest);                    // Plot srNearest for TESTING
            }
            else        // DOWN Trend
            {                        //Print (Time[0].ToString()+" \tCurrentBar =  "+CurrentBar+"\tTrend  = DOWN  \tsrListCnt  = "+(srList.Count));
                for (i=srList.Count-1; i >= 0; i--)                            // Search from Highest price in srList
                {                    //Print ("srList["+i+"]+1  = "+Math.Round((double)srList[i]+srOffset,2).ToString("0000.00")+"   \tprice  = "+price.ToString("0000.00"));
                    if (price <= (double)srList[i]-srOffset)                // Find Close below SRline-offset
                    {     srNearest = (double)srList[i];        }
                    else 
                    {                //Print ("break; srNearest = srList["+(i)+"]  = "+srNearest.ToString("0000.00"));
                         break;                                             // Stop if price is above SRline-offset
                    }
                }
//                if (srNearest > 0)     Values[srPlot].Set(srNearest);                    // Plot srNearest for TESTING
            }
//Print ("srNearest = srList["+i+"]  = "+srNearest.ToString("0000.00"));
                
            return srNearest ;
        }
Thanks for the suggestions guys.

Milk-a-What?
Started this thread Reply With Quote
Thanked by:
  #13 (permalink)
 
Trader.Jon's Avatar
 Trader.Jon 
Near the BEuTiFULL Horse Shoe
 
Experience: Beginner
Platform: NinjaTrader
Broker: MBTrading Dukascopy ZenFire
Trading: $EURUSD when it is trending
Posts: 473 since Jul 2009
Thanks Given: 401
Thanks Received: 184


Would you please expand a little on srlist, how you formulate that?

I am curious on how you determine trend for this.

Thanks for this code, it definitely will be studied for use!

Jon

Reply With Quote
  #14 (permalink)
 
zacharydw00's Avatar
 zacharydw00 
Idaho
 
Experience: Intermediate
Platform: NinjaTrader,ToS
Broker: Amp Futures, ToS
Trading: ES, E7, CL, GC
Posts: 149 since Aug 2009
Thanks Given: 87
Thanks Received: 180


Trader.Jon View Post
1) Would you please expand a little on srlist, how you formulate that?
2) I am curious on how you determine trend for this.
Thanks for this code, it definitely will be studied for use!
Jon

1) srList is an "array" (specifically an ArrayList, Google it) that stores all the s/r (Support/Resistance) price values. It's up to you to determine these values and store them in an ArrayList. As a side note. Static values would be horizontal s/r lines. If you want to use dynamic s/r lines, such as a 200, 100, & 50 SMA for s/r, then you would have to update the srList array on every bar.

2} Trend could be determined by the slope of an MA, LinRegSlope ind., DM ind., or whatever your favorite sloping indicator is. If the slope is up then Trend would equal true.

Good Luck.

Milk-a-What?
Started this thread Reply With Quote
Thanked by:
  #15 (permalink)
dar17
Maharashtra,INDIA
 
Posts: 3 since Aug 2010
Thanks Given: 8
Thanks Received: 1


Laserdan View Post
This way you don't need to worry about which way price is moving. The current bar close is always sandwiched between the two SR lines (one above and one below).

Hello senior members,
can we code the above function into amibroker ?.
i.e=
my value=300;
h1=310,h2=320,h3=325,h4=312,h5=318......
out of h1,h2,h3 i want to find out which value is nearest to my value i.e 300
Thank you

Reply With Quote
  #16 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,399 since Jun 2009
Thanks Given: 33,175
Thanks Received: 101,539


dar17 View Post
Hello senior members,
can we code the above function into amibroker ?.
i.e=
my value=300;
h1=310,h2=320,h3=325,h4=312,h5=318......
out of h1,h2,h3 i want to find out which value is nearest to my value i.e 300
Thank you

You need to ask in the Amibroker section of the forum:
AmiBroker - Big Mike's Trading Forum

Unfortunately, not many participants there. Please ask your Amibroker friends to come join us and start sharing. You should also share what you have.

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote




Last Updated on January 1, 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