Open a new trade when the first one is in profit
16 Feb 2018, 17:23
Hello
I am new to programming, and I have a few issues. I created a small bot that should open just one trade when another trade is in profit by a few pips. My bot does open but it doesn't stop at just one trade, and I don't know how to count just one trade.
Technically the bot should look for Buy and Sell trades from one pair and then just open a similar trade (just one) if the original trade is 5 pips in profit. If the new trade stops in profit/loss then it should start again.
I only want one simple boot that will work for one pair. I can modify and create new ones for every pair if I need later. I tried a lot of combinations, and the only issue I have is that it doesn't stop after it finds the trade with my label.
As you can see in the codes, I only have one type of trade, but it will be nice if it could search for Buy and Sell at the same time and open a similat trade to the one it finds.
This one works, but counts all the open positions and then it stops.
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class testAUDUSD : Robot
{
protected override void OnStart()
{
}
protected override void OnBar()
{
if (Positions.Count < 2)
{
var positions = Positions.FindAll("AUDUSD_S", Symbol, TradeType.Sell);
foreach (var position in positions)
{
if (position.Pips > 5)
{
ExecuteMarketOrder(TradeType.Sell, Symbol, 2000, "AUDUSD_S", 20, 20);
}
}
}
}
}
}
This one finds the exact trade by label, but again, it doesn't stop after one trade.
protected override void OnStart()
{
}
protected override void OnTick()
{
var shortPosition = Positions.Find("AUDUSD_S", Symbol, TradeType.Sell);
{
if (shortPosition.Pips > 5)
{
ExecuteMarketOrder(TradeType.Sell, Symbol, 2000, "AUDUSD_S", 20, 20);
}
