Topics
06 Feb 2020, 03:42
 1
 1017
 1
06 Feb 2020, 03:38
 2
 904
 1
06 Feb 2020, 03:36
 0
 1051
 1
06 Feb 2020, 03:31
 1
 856
 1
01 Nov 2016, 09:44
 1954
 1
04 Jun 2016, 10:27
 4769
 7
13 May 2016, 19:58
 2984
 1
Replies

jeremy.vostik
06 Jun 2016, 15:44

PID is a Little tricky I believe. In case of multiple positions. It is certainly way out of my coding skill reach to do that.

I was thinking something like

 

get the currentSymbol.

var positionB = PositionsFind(lable, currentSymbol, TradeType.Buy)

var positionS = PositionsFind(lable, currentSymbol, TradeType.Sell)

 

foreach (Position p in Positions)
                if(position.Symbol == currentSymbol)

{

ClosePosition(p);

}

 

 

 

Something along that line. But I don't know how to do it :(


@jeremy.vostik

jeremy.vostik
06 Jun 2016, 11:47

How exactly do I check it?

The Problem is, that I Need to store that number for later use somehow. Just like index -1; index -2 for example.

I Need the (first) Position entry Price. saved. so that when i open other positions I can still Access that pricelevel.

Wouldn't opening new positions override that number?

 

Maybe I can do something like

ExecuteMarketOrder(.....yadayada)

double firstEntryPrice = Position.OpenPrice

 

and for every new Position I create a new double.

Problem there is, what if I have an already manuall opened Position and I run the cBot after that? How do I "call" that open positions OpenPrice?

I would Need to find that open Position first and than extract that Price to a double.

 

Correct me if I am wrong or if I overcomplicate things :D

 


@jeremy.vostik

jeremy.vostik
04 Jun 2016, 19:31

Hi, your code does not work. It closes my trades in Profit after just 0.4 pips.

What's wrong?


@jeremy.vostik

jeremy.vostik
04 Jun 2016, 19:23

Okay, but how do I call it exactly?

Sorry I am stupid.

 

This is how I have it.

ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, label, StopLoss, TakeProfit);

How do I implement the new "Returned" volume in that?

 

 


@jeremy.vostik

jeremy.vostik
04 Jun 2016, 16:55

Just tried posting it into the private void CalculateVolume() section.

Only 2 Errors now.

} expected

and

Type or Nnamespace Definition, or end-of-file expected.


@jeremy.vostik

jeremy.vostik
04 Jun 2016, 16:51

RE: RE:

tmc. said:

tmc. said:

Hi, you might want to try my method. It doesn't include commissions though.

private long Volume(int riskPercent, int stopLossPips)
{
    double risked = Account.Balance * riskPercent / 100;
    double volume = risked / stopLossPips / Symbol.PipValue;
    return Symbol.NormalizeVolume(volume, RoundingMode.ToNearest);
}

Can you please tem me where I paste this code? OnStart? OnBar?

Writing it anywhere gibes me 23 Errors.

 

 


@jeremy.vostik

jeremy.vostik
04 Jun 2016, 13:43

Looks like it is working. Thank you VERY VERY much. Now on to my next Problem :o)


@jeremy.vostik

jeremy.vostik
04 Jun 2016, 11:19

Now I tried

var longPositionsCount = Positions.Count;

 

It works, but it Counts ALL trades, even closed ones.

So after 5 Trades, my cBot stops.


@jeremy.vostik

jeremy.vostik
04 Jun 2016, 10:29

//EDIT2:

of course I have

Parameter("Long Trades", DefaultValue = 2, MinValue = 0)]
public int MaxLongTrades { get; set; }

 

It was a typo in the opening post.


@jeremy.vostik

jeremy.vostik
04 Jun 2016, 10:28

//EDIT:

The above gives an Operand error.

 

I also tried with

var shortPositionsCount = Positions.Count(p => p.TradeType == TradeType.Sell);
var longPositionsCount = Positions.Count(p => p.TradeType == TradeType.Buy);

 

This compiles, but in backtesting no orders are entred. at all.


@jeremy.vostik