NexusFi: Find Your Edge


Home Menu

 





Counter crossing the horizontal line


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one doitagaitforme with 7 posts (0 thanks)
    2. looks_two anachronist with 4 posts (6 thanks)
    3. looks_3 Big Mike with 1 posts (0 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 4,854 views
    2. thumb_up 6 thanks given
    3. group 2 followers
    1. forum 12 posts
    2. attach_file 0 attachments




 
Search this Thread

Counter crossing the horizontal line

  #1 (permalink)
 doitagaitforme 
Rostov-na-Donu/ Russia
 
Experience: Beginner
Platform: Metatrader
Posts: 17 since Jul 2010
Thanks Given: 8
Thanks Received: 4

Hello All. I have a indicator on easylanguage. I want to implement it on ninjasript. In the picture of his project.



 
Code
input: count(3);
var: x(0), oldest(0), recycle(0), size(99);
array: id[99,3](0);  // 0=id, 1=price, 2=count, 3=age

once for x=0 to size begin
    id[x,0]=tl_new(d,t,0,d,t,0);
end;

if barstatus(1)=2 then begin
    oldest=0;
    for x=0 to size begin
        if L<=id[x,1] and H>=id[x,1] then begin
            id[x,2]=id[x,2]+1;
            if id[x,2]=count then begin
                id[x,1]=0;  id[x,2]=0;  id[x,3]=9999999;  tl_setend(id[x,0],d,t,0);  tl_setbegin(id[x,0],d,t,0);  // reset price, count and age
            end;
        end;
        if id[x,1]>0 then tl_setend(id[x,0],d,t,id[x,1]);
        id[x,3]=id[x,3]+1;
        if id[x,3]>oldest then begin
            oldest=id[x,3];  recycle=x;
        end;
    end;
    id[recycle,1]=c;  id[recycle,2]=0;  id[recycle,3]=0;  tl_setend(id[recycle,0],d,t,c);  tl_setbegin(id[recycle,0],d,t,c);
end;
He draws a horizontal line on the closing price of each bar. The horizontal line is displayed until it intersects the price of a certain number of times.

First, I tried to display a horizontal line at each price:
 
Code
for (int i=1; i<777; i++)
			{
				
				DrawHorizontalLine("tag1"+CurrentBar,Close[i], Color.Red);
			}
I could not get.

Please advise how I can do it, and how to work with the horizontal line tag, to appeal to her?

Thank.

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
ZombieSqueeze
Platforms and Indicators
Build trailing stop for micro index(s)
Psychology and Money Management
Online prop firm The Funded Trader (TFT) going under?
Traders Hideout
NexusFi Journal Challenge - April 2024
Feedback and Announcements
Ninja Mobile Trader VPS (ninjamobiletrader.com)
Trading Reviews and Vendors
 
  #3 (permalink)
 doitagaitforme 
Rostov-na-Donu/ Russia
 
Experience: Beginner
Platform: Metatrader
Posts: 17 since Jul 2010
Thanks Given: 8
Thanks Received: 4


At the moment my brain was able to generate the code. It compiles, but does not bring results, draws only one line. Maybe I need another array of lines? I will be happy with any prompts.

 
Code
protected override void OnBarUpdate()
        {

        int[] count=new int[5000];
        DrawHorizontalLine("tag1"+CurrentBar,Close[0], Color.Red);
        for (int i=0; i<5000; i++)
            {
                
                if ((Close[0]<=High[i]) || (Close[0]>=Low[i]))
                {
                    count[CurrentBar]=count[CurrentBar]++;
                    if (count[CurrentBar] == 3)
                    {
                        RemoveDrawObject("tag1"+CurrentBar);
                    }
                }
                
                
                
            }
            
        }

Started this thread Reply With Quote
  #4 (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,541


doitagaitforme View Post
Hello All. I have a indicator on easylanguage. I want to implement it on thinkstsript.

Do you mean NinjaScript for NinjaTrader? Or Thinkscript for ThinkOrSwim?

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
  #5 (permalink)
 doitagaitforme 
Rostov-na-Donu/ Russia
 
Experience: Beginner
Platform: Metatrader
Posts: 17 since Jul 2010
Thanks Given: 8
Thanks Received: 4


Big Mike View Post
Do you mean NinjaScript for NinjaTrader? Or Thinkscript for ThinkOrSwim?

Mike

I'm sorry, did not notice. Ninjascript.

Started this thread Reply With Quote
  #6 (permalink)
 
anachronist's Avatar
 anachronist 
San Jose, CA
 
Experience: Advanced
Platform: NinjaTrader
Trading: all
Posts: 27 since Apr 2012
Thanks Given: 0
Thanks Received: 16


doitagaitforme View Post
At the moment my brain was able to generate the code. It compiles, but does not bring results, draws only one line. Maybe I need another array of lines? I will be happy with any prompts.

It draws one line because you are erasing it with RemoveDrawObject.

DrawHorizontalLine draws a line extended to infinity in both left and right directions. It looks to me like you want to draw a finite line that stops after some number of price intersections.

I'd do something like this. In region "Using declarations" at the top, add
using System.Collections.Generic; // add array list capability

Then create an array list to store your lines:
 
Code
                            
#region Using declarations
using System.Collections.Generic// add array list capability
#endregion

...

private 
struct linedata {
   public 
string id;
   public 
int countstartbar;
   public 
double value;
}
private List<
linedatalines;

protected 
override void Initialize() {
    
lines = new List<linedata>();
    
CalculateOnBarClose true;
}

protected 
override void OnBarUpdate() {
   if (
CurrentBar == 0) return;
   
linedata ld = new linedata();
   
ld.id "ln"+CurrentBar.ToString();
   
ld.startbar CurrentBar-1;
   
ld.value Close[1];
   
ld.count 0;
   
lines.Add(ld);
   foreach(
linedata d in lines) {
      if (
d.value >= Low[0] && d.value <= High[0])
         ++
d.count;
      if (
d.count <= 3)
         
DrawLine(d.idCurrentBar-d.startbard.value0d.valueColor.RedDashStyle.Solid1);
      else
         
lines.RemoveAll(d); // don't need to track this line anymore
   
}

Warning, the above is from my head, untested. But it should give you an idea how to proceed.
-A

Reply With Quote
  #7 (permalink)
 doitagaitforme 
Rostov-na-Donu/ Russia
 
Experience: Beginner
Platform: Metatrader
Posts: 17 since Jul 2010
Thanks Given: 8
Thanks Received: 4

Thank you anachronist, I've seen is just the tip of the iceberg, now I need a thick book.

Started this thread Reply With Quote
  #8 (permalink)
 
anachronist's Avatar
 anachronist 
San Jose, CA
 
Experience: Advanced
Platform: NinjaTrader
Trading: all
Posts: 27 since Apr 2012
Thanks Given: 0
Thanks Received: 16

You don't need a thick book. Whenever I have a C# question, I just Google it, and most often I end up reading pages on Microsoft's online library. The List class is documented here, for example. A List in C# is simply an array of any data type; in the code above I made up a custom struct to hold data about each horizontal line, and created a List array of them. An array implemented as a List has variable length controlled by the Add() and Remove() methods. You can get the number of array elements at any time using the Count() method, and you can access elements in the array as a[0], a[1], etc. just like a conventional array.

-Alex

Reply With Quote
  #9 (permalink)
 doitagaitforme 
Rostov-na-Donu/ Russia
 
Experience: Beginner
Platform: Metatrader
Posts: 17 since Jul 2010
Thanks Given: 8
Thanks Received: 4

anachronist, I tried to compile your code from all the mistakes I do not understand only one: when referring to linedata.value CS0122 is inaccessible due to its protection level, the rest will deal less. Or maybe advise me what is the documentation of: protection level.

Started this thread Reply With Quote
  #10 (permalink)
 
anachronist's Avatar
 anachronist 
San Jose, CA
 
Experience: Advanced
Platform: NinjaTrader
Trading: all
Posts: 27 since Apr 2012
Thanks Given: 0
Thanks Received: 16


Eh, sorry about that. The word "public" must precede the declaration of "double value" in the struct definition. I'll correct it in my reply above. I think everything defaults to "private" in C# unless you explicitly declare it otherwise.

(Private properties in structs make no sense at all, so the default makes no sense, but that's a philosophical topic best discussed in another forum.)
-A

Reply With Quote




Last Updated on May 3, 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