Open or close a position on each 100 pip candle
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
Replies
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
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
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