Open or close a position on each 100 pip candle

Created at 15 Jun 2021, 02:26
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!
falkyw's avatar

falkyw

Joined 21.12.2020

Open or close a position on each 100 pip candle
15 Jun 2021, 02:26


Hi guys, I'm new here and I'm trying to create my first robot :D

can someone tell me

How to open a position every Buy candlestick with 100 pips positive with stop loss of -250 pips
and close the same position when a sell candlestick appears after reaching -250 pips?
I'm sending an image as a demo

Could someone show me what the codes would be and how I do it?

Thank you, friends


@falkyw
Replies

amusleh
16 Jun 2021, 11:53 ( Updated at: 16 Jun 2021, 11:55 )

Hi,

You can open a buy/sell market order by using ExecuteMarketOrder method, and you can pass the stop loss/take profit in Pips.

The order will be executed based on symbol bid/ask price, check the code examples of Position.

You can use OnBar method on a Renko chart to execute your orders per bar, or use the OnTick method to count the Pips by your self.


@amusleh

falkyw
17 Jun 2021, 11:49

RE: Gratitude

amusleh said:

Hi,

You can open a buy/sell market order by using ExecuteMarketOrder method, and you can pass the stop loss/take profit in Pips.

The order will be executed based on symbol bid/ask price, check the code examples of Position.

You can use OnBar method on a Renko chart to execute your orders per bar, or use the OnTick method to count the Pips by your self.

Thank you for answering  Amusleh
Can I execute a new order after the closing of 3 candles on the renko chart of pips? (without third party indicators)
What would be the coding for this?


@falkyw

amusleh
18 Jun 2021, 20:19

RE: RE: Gratitude

falkyw said:

amusleh said:

Hi,

You can open a buy/sell market order by using ExecuteMarketOrder method, and you can pass the stop loss/take profit in Pips.

The order will be executed based on symbol bid/ask price, check the code examples of Position.

You can use OnBar method on a Renko chart to execute your orders per bar, or use the OnTick method to count the Pips by your self.

Thank you for answering  Amusleh
Can I execute a new order after the closing of 3 candles on the renko chart of pips? (without third party indicators)
What would be the coding for this?

Hi,

Yes, you can do it, you just have to count the number of bars and if three bars were passed close the position, ex:

using cAlgo.API;
using System;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewcBot : Robot
    {
        protected override void OnBar()
        {
            var index = Bars.Count - 1;

            foreach (var position in Positions)
            {
                // if position symbol is not same as our chart symbol we skip over it
                if (!position.SymbolName.Equals(SymbolName, StringComparison.OrdinalIgnoreCase)) continue;

                // We get the bar Index of position entry time
                var positionEntryBarIndex = Bars.OpenTimes.GetIndexByTime(position.EntryTime);
                // If 3 or more bars passed since position entry time then we close it
                if (index - positionEntryBarIndex >= 3)
                {
                    ClosePosition(position);
                }
            }
        }
    }
}

 


@amusleh

falkyw
21 Jun 2021, 13:52 ( Updated at: 22 Jun 2021, 04:05 )

RE: RE: RE: Gratitude

But, I intended to open a new buy or sell position after closing 3 candles.

Specifically on the renko chart.This mod would be for closing the position, right?


@falkyw

amusleh
22 Jun 2021, 17:38

RE: RE: RE: RE: Gratitude

falkyw said:

But, I intended to open a new buy or sell position after closing 3 candles.

Specifically on the renko chart.This mod would be for closing the position, right?

The above code is for closing a position after three bars, not for opening a new one.

Please read the API references and you will be able to do it, or post a job request.


@amusleh

falkyw
23 Jun 2021, 14:53

RE: RE: RE: RE: RE: Gratitude

Thanks
But I needed the code to open an order after the closing of 3 candles on the Renko chart.
But I don't think that would be possible, I will have to modify my robot strategy.
Still thank you very much for your help.

 


@falkyw