SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Sat Feb 14, 2026 7:05 pm

All times are UTC + 3 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Cross Above/Below
PostPosted: Wed Mar 23, 2011 12:44 am 
Offline

Joined: Tue Mar 15, 2011 7:15 pm
Posts: 80
Hello,

I am certain this is a simple question, but I am struggling with the answer.

I have figured out the highest value of my instrument during the trading day (defined as a 24 hour period) using:
double daysHigh = Bars.HighestHigh(startOfTrdDay,endOfTrdDay);

Now I want to figure out if the current bid price of security (given by Quote.Bid) crosses above some arbitrary threshold such as (daysHigh - x%).

What is the best way to test the criteria? Thank you.


Top
 Profile  
 
 Post subject: Re: Cross Above/Below
PostPosted: Wed Mar 23, 2011 11:58 am 
Offline

Joined: Wed Oct 08, 2003 1:06 pm
Posts: 833
Hi,

In OnQuote handler you can write something like
Code:
double prevBid = -1;
double level = 0;

public override void OnQuote(Quote quote)
{
    if (prevBid != -1)
        if (prevBid <= level && quote.Bid > level)
           DoSomething();

    prevBid = quote.Bid;
}


"level" here is this threshold (that can be calculated in OnBar handler for example)

Regards,
Sergey.


Top
 Profile  
 
 Post subject: Re: Cross Above/Below
PostPosted: Wed Mar 23, 2011 4:50 pm 
Offline

Joined: Tue Mar 15, 2011 7:15 pm
Posts: 80
Very simple....thank you.


Top
 Profile  
 
 Post subject: Re: Cross Above/Below
PostPosted: Thu Mar 24, 2011 5:53 pm 
Offline

Joined: Tue Mar 15, 2011 7:15 pm
Posts: 80
Baraz,

In addition to the code you provided below, is there a way to do this using indicators?

I want to check if the current bid crosses below the lowest price of the day, which I define as the lowest price trading within a certain band of time:

Double daysLow= Bars.LowestLow(startOfTrdDay,endOfTrdDay);

I also have a barSeries that compiles 1-minute bars:
BarSeries barSeries_1Min = GetBars(BarType.Time,60);

What I would like to do is determine if, at any time during my defined trading day, the current bid price (given by Quote.Bid) crosses below (daysLow)....it must descend from above and cross below the daysLow threshold. I do not want the trigger breached if the threshold is crossed from above.

The code you provided would effectively do this, but I am trying to better understand SQ's indicators and methods. Can what I am trying to do be done using the Cross indicator? Or the CrossAbove/CrossBelow methods of other indicators?

Thank you.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 3 hours


Who is online

Users browsing this forum: No registered users and 20 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group