Simple advice needed to do calculation with open, close prices +

Created at 02 Oct 2015, 16:56
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
GD

GDPR-24_203122

Joined 02.10.2015 Blocked

Simple advice needed to do calculation with open, close prices +
02 Oct 2015, 16:56


Hi! Can someone help?

I can't figure out a code that takes the high-, low-, open- and close -prices of a bar, each time a bar closes...


After the bar closes it subtracts: 
1: open price from the high and 
2: the close price from the high.
if 1 < 2, it creates a sell position, with adjustable lot size, (prefer 0,01 lot), and adjustable time period (1h,5h etc).

I need these infos to develop it further.

Thanks for your kindness!


Replies

moneybiz
02 Oct 2015, 19:17

        protected override void OnBar()
        {
            // The new bar's index is 0, the closed bar's index is 1.
            var prevBarOpenPrice = MarketSeries.Open.Last(1);
            var prevBarClosePrice = MarketSeries.Close.Last(1);
            var prevBarHighPrice = MarketSeries.High.Last(1);
            var prevBarLowPrice = MarketSeries.Low.Last(1);

            if (prevBarHighPrice - prevBarOpenPrice < prevBarHighPrice - prevBarClosePrice)
            {
                // Open Sell.
            }
        }

 

Add the lines above to your bot.


@moneybiz

GDPR-24_203122
03 Oct 2015, 21:36

Thanks a lot! *thumbsup* 

"Keep it simple"