Click here to Login





                                                   Script or Custom Function? past _X_ closes less than current close

  1

0
Josh McCormick
2020-09-07 13:26:48


I want to do something incredibly easy, but after so many attempts, my brain has turned to mush. Here's a simplified version of the problem:

There are any number of examples which show how many of the past _X_ closes are greater than a fixed number.
Or how many of the past _X_ closes are greater than the closing value that was five bars before (or after) it.

What I am looking for is something a little bit different:

For each and every bar, I want to count (and graph) how many of the past 50 bars had a close which is lower than *the current bar*.

I'd use something like SumIf, but I can't find a suitable comparison which tells it to compare the closing period against the current bar:

a=SumIf (close > ???????,1,50);

I tried both of these, but they don't return anything useful:

a=SumIf (close > close[count()],1,50);
a=SumIf (close > value (close,count()),1,50);

Any thoughts? Or am I trying to do something with QS Script that I should be writing a custom (CSharp) function for?

Thanks again,
Josh McCormick



QuantShare
2020-09-08 10:37:57

  1

Best Answer
SumIf will iterate through the "array" parameter and calculate the "condition" parameter once, so it will not work in this case.

This is the kind of functions that currently needs to be developed in CSharp.

Loop through each bar (A) then for each bar loop through each past N bars (B) and compare that bar close (A) with the bar close (B).





Josh McCormick
2020-09-08 12:03:32

  0

Thanks! You've rescused me from a mountain of troubleshooting.


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
NYSE Index Closes
5x5 SMA & RSI Forex Strategy
How far are the close prices from the support line
Advanced Quotes and Custom Databases Function
Stocks with an EPS Several Times Higher than the Industry Average...

How-to Lessons
How to add custom position-based metrics to your trading system
How to create a custom trading indicator
How to create a custom trendline
How to run a screen or a watchlist from a script
How to use a custom drawing tool

Related Forum Threads
Can a Money Management script access a custom function?
How do I get the date of the current bar in a custom function?
Composite Tool Script Editor - Write to TXT
How do I find the close price for an entry matching a custom DB
Unable to use Symbols.GetSymbols() in a custom downloader URL scr...

Blog Posts
How to create and backtest thousands of trading rules in less tha...
How to Create a Custom Real-Time Table using QS Trading Software
Trading System Analysis: Backtesting report and custom measures
Create custom metrics for the statistical data analysis tool
Speed Up Optimizations by Saving Ranking Data into a Custom Datab...









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 © 2024 QuantShare.com
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
Google+
Follow us on Google+
RSS Trading Items



Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.