Re: [amibroker] cross price calculations

 

as I mentioned the cross price of the High with a 3 period simple moving average of the High can be written as:
 
P[i] = ( H[i-2] + H[i-1] + P[i] ) / 3
 
which can be simplified to solve the price P where the cross occurs to: P[i] = 0.5 * ( H[i-2] + H[i-1] )
 
Doing the same for a Bollinger band, finding the cross price of BBANDTOP( H, 3, 1 )
 
can be written as:
 
P[i] = ( H[i-2] + H[i-1] + P[i] ) + SQRT( ( ( H[i-2] - ( H[i-2] + H[i-1] + P[i] ) )^2 + ( H[i-1] - ( H[i-2] + H[i-1] + P[i] ) )^2 + ( P[i] - ( H[i-2] + H[i-1] + P[i] ) )^2 ) / 3 )
 
 
now simplify that one to solve the price P where the cross occurs and then work out a generalized algorithm  
 
 
 
Sent: Wednesday, April 27, 2016 10:17 AM
Subject: Re: [amibroker] cross price calculations
 
 

I added an example GIF movie of this code I posted here (top chart) https://sites.google.com/site/amitradingideas/
 
you see the orange dots. When the high crosses this point then the signal occurs. This is the price one could buy instead of MA(H,3). This orange dot is already known at the end of the previous bar. It can help you doing backtests when you only have for instance 5minute data to pinpoint the exact price of entry.
 
Ed
 
Sent: Wednesday, April 27, 2016 9:51 AM
Subject: Re: [amibroker] cross price calculations
 
 

hi Ton,
 
that is strange. No, it should be visible using this link: https://sites.google.com/site/amitradingideas/  the images I set to be visible for everyone.
 
But I show some code here to show what I am after (see below). Assume you are in the hourly timeframe  and you want to use signals when the price crossed MA(H,3). Because you are in the hourly timeframe the best guess you can make for the price you have to pay is at MA(H,3).
 
In real time when data comes in you will see that this is usually not the price at which the cross occurs. Before the bar starts at which a cross occurs you can exactly calculate that when a cross will occur you already know at which price it will occur. This I show in the chart with the orange dots. This is the price where in real time the cross occurs. Like I explained yesterday it is just simple highschool math. It occurs at the price where the price function and the MA function are equal. Or in this simple example:
 
P[i] = ( H[i-2] + H[i-1] + P[i] ) / 3
 
the same can be done for a Bollinger band, although this is more complicated. The equation   P[i] = ( H[i-2] + H[i-1] + P[i] ) / 3  can be simplified into P[i] = 0.5 * ( H[i-2] + H[i-1] ). However, one should be able to reduce this to a generalized equation which includes the period as a variable. For this simple MA setup I probably could figure out a generalized equation (by trial and error, usually my approach ...). However with the Bollinger bands things become more complicated. How does one get a generalized equation similar to what Dimitris has done ?
 
thanks, ed
 
 
 
ma1 = MA( H, 3 );

function calc()
{
    pp = null;

    for( i = 2; i < BarCount; i++ )
    {
        pp[i] = 0.5 * ( H[i - 2] + H[i - 1] );
    }

    return pp;
}

GraphXSpace = 5;
SetChartBkColor( colorBlack );
SetChartOptions( 0, chartShowDates );
SetBarFillColor( IIf( C > O, colorGreen, IIf( C <= O, colorRed, colorLightGrey ) ) );
Plot( C, "Last", IIf( C > O, colorDarkGreen, IIf( C <= O, colorDarkRed, colorLightGrey ) ), 64, null, null, 0, 0, 1 );
Plot( ma1, "", colorwhite, 1, null, null, 0, 1, 1 );

pp = calc();
Plot( pp, "", colorOrange, styleDots | styleNoRescale | styleNoline, null, null, 0, 1, 4 );

Buy = Cross( H, ma1 );
BuyPrice = ma1;

PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), colorDarkGreen, 0, L, -20 );
PlotShapes( IIf( Buy, shapeSmallCircle, shapeNone ), colorWhite, 0, BuyPrice, 0 );
 
Sent: Wednesday, April 27, 2016 9:04 AM
Subject: Re: [amibroker] cross price calculations
 
 



Hi Ed,

When clicking the URL in your email, I am getting a blank screen with a "Snapshot" header. On the left the projects. Which one ? "Real Time Data Fit" or "Polynomial Curve Fit" ? The first is hanging. The second just shows a price range without bands … Something going wrong ?

Regards, Ton
 
----- Original Message -----
Sent: Tuesday, April 26, 2016 5:51 PM
Subject: Re: [amibroker] cross price calculations
 
 

Ton
 
this one I removed, it was actually the other image I pointed at.
 
 
you see that once the signal comes the price is moving higher and therefor also the entry price, since the entry price is at the Bollinger band. This is because the Bollinger band is using the High and Low. In some cases the entry price moves a lot in my favour, sometimes not. In the hourly timeframe it is allowed to move 8 ticks on average for the system still to work.
 
But instead of adding a slippage I can actually exactly calculate when the signal will start as per Dimitris post. You can calculate the cross at the end of the previous bar so one can exactly calculate the entry price. This is what I am trying to do
 
regards, Ed
 
 
Sent: Tuesday, April 26, 2016 5:05 PM
Subject: Re: [amibroker] cross price calculations
 
 



I have two problems Ed. Firstly I do not see the Bollinger in your video. Did you already plot the bands ?

Secondly I do not understand your problem. If you have the average and the stdev than you should have the Bollingers. And the crossing of the price with the bands should be a simple thing to do. Am I missing something ?

Regards, Ton.

----- Original Message -----
Sent: Tuesday, April 26, 2016 3:02 PM
Subject: Re: [amibroker] cross price calculations
 
 

hi Ton,
 
what I am trying to do is related to what Dimitris is doing but my problem is simple and certainly solvable.
 
all I want is to calculate the exact price at which a Bollinger band is crossed, it is basically high school mathematics
 
see the signals in the top chart here https://sites.google.com/site/amitradingideas/
 
it is oil ,1 hour bars. The Bollinger bands use 3 bars and are calculated using the High. For the entry price I use the Bollinger band price, In reality you will almost never get this price. So I want to calculate at which price the price is the same as the Bollinger bands. This is the price in reality I will buy or short.
 
a simpler problem would be for instance to calculate at which price the MA(C,3) will be crossed. The price should be equal to the MA ( in highschool we had to calculate the cross point of 2 functions). So simply put
 
P[i] = (C[i-2] + C[i-1] + PP[i] ) / 3
 
or: P[i] = 0.5*( C[i-2] + C[i-1] )
 
price P will be the exact price where the MA(C,3) is crossed. For a Bollinger band it becomes a bit more complicated and I have difficulties translating this into a general algorithm, like Dimitris has done.
 
I will get back to this tomorrow to explain it a bit in greater detail.
 
But for this Bollinger band system I show in the chart I can calculate the exact price where the buy/short signals will be generated. Then I can more precisely calculate if the system will work or not
 
regards, ed
 
Sent: Tuesday, April 26, 2016 2:24 PM
Subject: Re: [amibroker] cross price calculations
 
 

Hi Edwards,

Assume you're talking about https://groups.yahoo.com/neo/groups/amibroker/conversations/topics/45738

Please check following : It is obvious that there are extended periods for which the DEMAcross is impossible.

Question is how to build the bands without having the average ?

Regards, Ton.

----- Original Message -----
Sent: Tuesday, April 26, 2016 10:14 AM
Subject: [amibroker] cross price calculations
 
 

hi,
 
Dimitris posted algorithms to calculate MA cross prices in the files section back in 2003 (file Cross Predictions.txt).
 
Anyone made an algorithm to calculate the cross price of a Bollinger Band?  I should be able to do it but would be nice if somebody did this already,
 
thanks
 
 

__._,_.___

Posted by: "Edward Pottasch" <empottasch@skynet.be>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (9)

Upgrade your account with the latest Yahoo Mail app
Get organized with the fast and easy-to-use Yahoo Mail app. Upgrade today!

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/


.

__,_._,___


EmoticonEmoticon