Topics
10 May 2019, 10:03
 2745
 11
27 Nov 2018, 07:18
 3277
 6
Replies

alexander.n.fedorov
05 Sep 2018, 18:00

Panagiotis, so I do the following:

"

     protected override void OnTick()
        {

            var positions = Positions.FindAll(instance);
            if (positions.Count() == 0)
            {
                 if ((Symbol.Ask > dcl.Top.LastValue && bbMa.Result.IsRising()) && rsi.Result.LastValue > 50)
                {
                    ExecuteMarketOrder(TradeType.Buy, Symbol, volume, instance);
                }
                 if ((Symbol.Bid < dcl.Bottom.LastValue && bbMa.Result.IsFalling()) && rsi.Result.LastValue < 50)
                {
                    ExecuteMarketOrder(TradeType.Sell, Symbol, volume, instance);
                }
            }

            if (positions.Count() > 0)
            {

                if (IsNewCandle() == true)
                {

                    foreach (var position in positions)
                    {
                        if (position.Pips > atr.Result.LastValue * positionATR)
                        {
                            breakEven(position);
                            ExecuteMarketOrder(position.TradeType, Symbol, position.VolumeInUnits, instance);
                        }
                    }

                }

 

.....

 private bool IsNewCandle()
        {

       if (MarketSeries.Close.Last(1) != _lastClose)
            {

                //Bar changed
                _lastClose = MarketSeries.Close.Last(1);
                return true;
            }
            else return false;
        }

 

Correct?

 


@alexander.n.fedorov

alexander.n.fedorov
05 Sep 2018, 14:07

Dear Panagiotis,

I am sorry  but it is still unclear how to open a new position on a new candle if I am OnTick

 

Regards,

 

Alexander


@alexander.n.fedorov

alexander.n.fedorov
30 Aug 2018, 17:19

Thank you, Panagiotis

 

Regards, 

Alexander


@alexander.n.fedorov

alexander.n.fedorov
30 Jul 2018, 17:52

Thank you!

 


@alexander.n.fedorov

alexander.n.fedorov
24 Jul 2018, 13:01 ( Updated at: 21 Dec 2023, 09:20 )

Never mind backslashes, they in a picture by mistake

But in the other case it woks just fine


                foreach (var position in positions)
                {

                    if (position.TradeType == TradeType.Buy && MarketSeries.Low.Last(1) < bb.Main.Last(1))
                    {
                        if (bb.Main.HasCrossedBelow(TMA.Result, 1) )
                        {
                            ClosePosition(position);
                        }
                    }

                    if (position.TradeType == TradeType.Sell && MarketSeries.High.Last(1) > bb.Main.Last(1))
                    {
                        if (bb.Main.HasCrossedAbove(TMA.Result, 1) )
                        {
                            ClosePosition(position);
                        }

                    }
                }


@alexander.n.fedorov

alexander.n.fedorov
24 Jul 2018, 12:48

But as you can see on the picture the blue line is crossing the TMA (triangular ma) and nothing happens.

Maybe the syntax is not right?

Regards,

Sasha

 


@alexander.n.fedorov

alexander.n.fedorov
09 Jul 2018, 13:53

Thanks, Panagiotis
It is much more elegant

Eventually I will send you a bot which I called "Protector" as it protects the whole portfolio from overprofiting(! that is true), and spending too much margin.

But, as always, your solution is much more elegant

Regards

 

Alexander

 

 

 


@alexander.n.fedorov

alexander.n.fedorov
06 Jul 2018, 18:02

It does the job, but not exactly what I wanted

Can you think of more elegant solution?


@alexander.n.fedorov

alexander.n.fedorov
06 Jul 2018, 17:38

I think I shoul do smth like this

"

           foreach (var position in Positions)
            {
                var label = position.Label;
                profit = 0;
                foreach (var posit in Positions)
                {
                    if (posit.Label == label)
                    {
                        profit=profit+posit.NetProfit;
                    }
                }
                if (profit > 0)
                {
                    foreach (var posit2 in Positions)
                    {
                        if(posit2.Label==label)
                        ClosePosition(posit2);
                    }
                }
            }

"

Not the most elegant solution, but I think it will do the job

 


@alexander.n.fedorov

alexander.n.fedorov
06 Jul 2018, 17:22

I just do not know how to find the label.


@alexander.n.fedorov

alexander.n.fedorov
06 Jul 2018, 17:16

But once it is possible to count the robots through distinct position label, may be it is posssible to attribute the label to var robot in robots?

 


@alexander.n.fedorov

alexander.n.fedorov
06 Jul 2018, 16:46

Thank you very much, Panagiotis, best regards


@alexander.n.fedorov

alexander.n.fedorov
06 Jul 2018, 16:44

In any case, it is , let it be not complete, but some serious solution for the problem.

 


@alexander.n.fedorov

alexander.n.fedorov
06 Jul 2018, 16:40

From the practical point of view, if there no positions with the robot, means there is no margin used

That is fine.

But what if I want to stop the robots, even if they did not open a position?

 


@alexander.n.fedorov

alexander.n.fedorov
06 Jul 2018, 16:38

Would have been fine, but what if a robot did not open a position yet?

 


@alexander.n.fedorov

alexander.n.fedorov
06 Jul 2018, 12:38

Thank you

 


@alexander.n.fedorov

alexander.n.fedorov
06 Jul 2018, 10:21

I will have to study Disctinct and Select functions, but that is not a big deal.

Thatk you .

You are always professional

Regards'

 

 


@alexander.n.fedorov

alexander.n.fedorov
06 Jul 2018, 10:12

Dear Panagiotis,

 

I probably could set up a public list or Bots, so every bot on start will be added to the list, or more presisely it's label

Then I could check every member of the list, by doing that I will get a bot

Then for every bot I can calculate the profit and margin, and if neeed, close it

 

The other way would be to take the all bots with the same symbol and calculate the profit on all of them

 


@alexander.n.fedorov

alexander.n.fedorov
06 Jul 2018, 09:59

collection of Symbols

I am running a portfolio wit a complex robot (same for each pair)
the bigger the portfolio the more likely is the positive result

The problem is margin
 

So when margin becomes an issue, I would like to close either the profitable Bots(which may have up to 8 martingale trades on each side  and eat a lot of margin)

or  close the enire Symbol (which may be in different timeframe with the same Bot)

sometimes I am doing it with hand, but I wanted to right a Bot that will take care of it

Regards

Alexander


@alexander.n.fedorov

alexander.n.fedorov
04 Jun 2018, 15:03

Entry price

Thank you, Panagiotis


@alexander.n.fedorov