Dear Fellow Traders,
i am a medium level programmer but a very good experience trader in charting and price action analysis. Last few months i have been trying to use mql4 to automate my process. i was successful in creating a marker that show me when my edge is present.
right now i want take that to next level in quantconnect.
My problem here is how to tell the built in c++ what a candle bar is, like i did in my mql4 program.
body = Open - Close;
bull = Open > Close;
bear = Open < Close;
how can i access these arrays and use them interchangeably to build my strategy.
how can i know the total bars that backtesting would cover in the quantconnect
please, i need your help
Below is an example of what i would build here.
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
int limit = MathMax (rates_total - prev_calculated, 2);
for (int i=0; i<limit; i++)
if (Close[i+14]-Open[i+14]<0 //bear
&& Close[i+13]-Open[i+13]>0 //bull
&& Close[i+12]-Open[i+12]>0 //bull
&& Close[i+11]-Open[i+11]>0 //bull
&& Close[i+10]-Open[i+10]>0 //bull
&& Close[i+9]-Open[i+9]>0 //bull
&& Close[i+8]-Open[i+8]<0 //bear 1st push
&& Close[i+7]-Open[i+7]>0 //bull 2nd push
&& Close[i+6]-Open[i+6]>0 //bull 2nd push
&& Close[i+5]-Open[i+5]>0 //bull 2nd push
&& Close[i+4]-Open[i+4]>0 //bull 2nd push
&& Close[i+3]-Open[i+3]<0 //bear 2nd push
&& Close[i+2]-Open[i+2]>0 //bull 3rd push
&& Close[i+1]-Open[i+1]<0 //bear 3rd push
&& Close[i]-Open[i]<0 //bear 3rd push
&& Close[i+1]<Close[i+9] // we shouln't get a signal beyond the 3+(above the last bar of the 3+)
//&& Close[i]<Open[i+3]
//&& Close[i+1]<Close[i+9]
&& Close[i]>Open[i+1]
)
{
//Alert ("Bullish fakey");
up[i]= Low[i];
}
else if (Close[i+15]-Open[i+15]<0 //bear
&& Close[i+14]-Open[i+14]>0 //bull
&& Close[i+13]-Open[i+13]>0 //bull
&& Close[i+12]-Open[i+12]>0 //bull
&& Close[i+11]-Open[i+11]>0 //bull
&& Close[i+10]-Open[i+10]>0 //bull
&& Close[i+9]-Open[i+9]<0 //bear 1st push
&& Close[i+8]-Open[i+8]>0 //bull 2nd push
&& Close[i+7]-Open[i+7]>0 //bull 2nd push
&& Close[i+6]-Open[i+6]>0 //bull 2nd push
&& Close[i+5]-Open[i+5]>0 //bull 2nd push
&& Close[i+4]-Open[i+4]<0 //bear 2nd push
&& Close[i+3]-Open[i+3]>0 //bull 3rd push
&& Close[i+2]-Open[i+2]<0 //bear 3rd push
&& Close[i+1]-Open[i+1]>0 //bull 3rd push
&& Close[i]-Open[i]>0 //bull 3rd push
&& Close[i+1]<Close[i+10] // we must get the signal inside 3+(not beyond the last bar)
&& Close[i+1]>Open[i+2]
)
{
//Alert ("Bullish fakey");
up[i]= Low[i];
}
else if (Close[i+14]-Open[i+14]>0 //bull
&& Close[i+13]-Open[i+13]<0 //bear
&& Close[i+12]-Open[i+12]<0 //bear
&& Close[i+11]-Open[i+11]<0 //bear THE BEAR 3+
&& Close[i+10]-Open[i+10]<0 //bear
&& Close[i+9]-Open[i+9]<0 //bear
&& Close[i+8]-Open[i+8]>0 //bull 1ST PUSH
&& Close[i+7]-Open[i+7]<0 //bear
&& Close[i+6]-Open[i+6]<0 //bear 2nd Bear breakout
&& Close[i+5]-Open[i+5]<0 //bear
&& Close[i+4]-Open[i+4]<0 //bear
&& Close[i+3]-Open[i+3]>0 //bull 2nd push
&& Close[i+2]-Open[i+2]<0 //bear Single bar as the 3rd push
&& Close[i+1]-Open[i+1]>0 //bull 3rd push
&& Close[i]-Open[i]>0 //bull
//&& Close[i+1]>Open[1+3]
//&& Close[i+1]>Close[i+9]
&& Close[i+1]>Close[i+9] // we shouln't get a signal beyond the 3+(above the last bar of the 3+)
&& Close[i]<Open[i+1]
)
{
//Alert ("Bearish fakey");
down[i]= High[i];
}
else if (Close[i+15]-Open[i+15]>0 //bull
&& Close[i+14]-Open[i+14]<0 //bear
&& Close[i+13]-Open[i+13]<0 //bear
&& Close[i+12]-Open[i+12]<0 //bear THE BEAR 3+
&& Close[i+11]-Open[i+11]<0 //bear
&& Close[i+10]-Open[i+10]<0 //bear
&& Close[i+9]-Open[i+9]>0 //bull 1ST PUSH
&& Close[i+8]-Open[i+8]<0 //bear
&& Close[i+7]-Open[i+7]<0 //bear 2nd Bear breakout
&& Close[i+6]-Open[i+6]<0 //bear
&& Close[i+5]-Open[i+5]<0 //bear
&& Close[i+4]-Open[i+4]>0 //bull 2nd push
&& Close[i+3]-Open[i+3]<0 //bear Single bar as the 3rd push
&& Close[i+2]-Open[i+2]>0 //bull 3rd push
&& Close[i+1]-Open[i+1]<0 //bear 3rd push
&& Close[i]-Open[i]<0 //bear 3rd push
&& Close[i+1]>Close[i+10] // we must get the signal inside 3+(not beyond the last bar)
&& Close[i+1]<Open[i+2]
)
{
//Alert ("Bearish fakey");
down[i]= High[i];
}
//--- return value of prev_calculated for next call
return(rates_total);
}
Gurumeher Sawhney
Glad you're joining the QuantConnect community! The first thing I would like to point out is that the algorithm is being coded in C#, not C++. While they are quite similar it is helpful to know the differences and which language is actually being used.
In terms of accessing the data necessary for the algorithm, it might be useful to read up on the documentation and algorithm examples. Below are links to to sample code in C# and to information about handling data through event handlers:
As seen by the above information, the data is first initialized in Initialize() and then fed into OnData(). The amount of trading bars that will enter the algorithm will be dependent on the Resolution, which can be Tick, Second, Minute, Hourly or Daily. In OnData the data comes in keyed by the requested symbols, and the relative OHLC information will be in the format of TradeBar or QuoteBar depending on the asset. This information can be analyzed and saved through RollingWindows, which is an array of data that allows for reverse list access semantics
It seems from the code above that this is a trend based strategy. It might be helpful to look at indicators that QuantConnect supports as well. The link below shows the library of indicators available for use and it is important to note that custom ones can be made if need be.
Hopefully this provides enough guidance. It would be beneficial to tailor the existing strategy to an architecture more flexible with QuantConnect to take full advantage of what is offered.
Samir Musa
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!