Click here to Login

Trading Software Trading objects Features How-to Blog Search


                                                   cycles indicator

  0

0
Dan
2011-01-30 15:18:50


Hello,

I am wishing to create an indicator that calculates the number of bars between two clicks on the chart.
I'd be gratefull to realize what formula to do this calculation by fetching mouse clicks on the chart
Please shed light :)



QuantShare
2011-01-31 04:55:37

  0

You can draw a line or a trendline (drawing tools), right click on it, select "Distances" then check "X Distance"


Dan
2011-02-03 10:25:06

  0

I am interested in writing a code wich calculates the number of bars between two clicks on chart and storing the value in a variable so i can design my indicator


QuantShare
2011-02-04 05:50:00

  0

You can do this by creating a custom drawing tool.

What is the function of the indicator you want to create?



Dan
2011-02-08 21:21:19

  0

Gurus,
Thank you on helping me realizing I'm up to create a "Custom Drawing Tool" rather than an "Indicator".
This drawing tool will calculate the average of distances taken from pairs of clicks on the chart,
so for every pair of clicks the distance of vector "X" is calculated and added to the "average" variable

Now, I can calculate only the 1st clicking distance with:

PointPosition p1 = Functions.ClickPositions[0];
PointPosition p2 = Functions.ClickPositions[1];

double distance = Math.Abs(p1.X - p2.X);

What is the code to add these distances to my "average" variable?



QuantShare
2011-02-09 04:54:34

  0

Best Answer
Here is an example:

bool isNewPair = false;
if(Functions.ClickPositions.Length == 0)
{
Global.SetVariable("count_distance", (double)0);
Global.SetVariable("average_distance", (double)0);
Global.SetVariable("last_click", 0);
return;
}
else if(Math.IEEERemainder(Functions.ClickPositions.Length, 2) == 0)
{
isNewPair = true;
}

string textDis = "";
if(isNewPair)
{
int lastClickIndex = Functions.ClickPositions.Length - 1;
PointPosition p1 = Functions.ClickPositions[lastClickIndex - 1];
PointPosition p2 = Functions.ClickPositions[lastClickIndex];
double distance = Math.Abs(p1.X - p2.X);
double avgDistance = 0;

if((int)Global.GetVariable("last_click") != lastClickIndex)
{
double count = 0;
if(Global.ContainsVariable("average_distance"))
{
count = (double)Global.GetVariable("count_distance");
avgDistance = (double)Global.GetVariable("average_distance");

avgDistance = avgDistance * count; // Calculate total distances
}

count = count + 1;
avgDistance = avgDistance + distance;
avgDistance = avgDistance / count;

Global.SetVariable("count_distance", count);
Global.SetVariable("average_distance", avgDistance);
Global.SetVariable("last_click", lastClickIndex);
}
else
{
avgDistance = (double)Global.GetVariable("average_distance");
}

textDis = "Last Distance: " + distance + " - Average: " + Math.Round(avgDistance, 2);
}
else
{
textDis = "Click on Chart";
}

TextObj text = Functions.PaneObject.DrawText("Distance", textDis, 0, 0.95);
text.UseFractionCoordinate = true;



No more messages
0




Reply:

No html code. URLs turn into links automatically.

Type in the trading objects you want to include: - Add Objects
To add a trading object in your message, type in the object name, select it and then click on "Add Objects"










QuantShare

Trading Items
Anchored Indicator
Bull Bear Ratio - Stock Market Indicator
Adaptive Trading Indicator based on the Return of Past Trades
Number of Stocks Making a new 52-Week High - Market Indicator
Dividend Frequency Indicator

How-to Lessons
How to create a moving average of an indicator
How to hide a trading indicator from a particular time frame
How to create a custom trading indicator
How to add a trading indicator to a chart
How to detect whether price movements are predictable or not

Related Forum Threads
kst indicator
Stock or industry relative strenght : Indicator or composite ?
Custom Indicator
Indicator - forward bar value
to write and execute an Indicator

Blog Posts
Create a stock index or a trading indicator using the composite t...
How to create a trading indicator that uses stock news
How to create a ratio indicator using QS Trading Software
How to create the advance/decline market breadth indicator
How to create a market timing system - Part 3









QuantShare
Product
QuantShare
Features
Create an account
Affiliate Program
Support
Contact Us
Trading Forum
How-to Lessons
Manual
Company
About Us
Privacy
Terms of Use

Copyright © 2012 QuantShare.com
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
Google+
Follow us on Google+
RSS Trading Items