Important questions on cBots - Thread

Created at 24 Feb 2021, 14:04
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!
TE

tekASH

Joined 29.01.2014

Important questions on cBots - Thread
24 Feb 2021, 14:04


Hi guys

I need working insight on following issues:

 

1. How to show/tell the system in the code: market being over a particular Moving Average? Like, price/overall market has crossed over a MA at some point and it is still there.

This is useful for entering short when market is below a MA, and buy only when over the MA. What methods can be used?

2. When I tell the system to buy only if price is over a MA, it keeps opening buy positions repeatedly (after previous position is closed) as long as the price is still over that MA :) But I need one entry, only first, cause keeping buying multiple positions is risky. How to fix this? 


@tekASH
Replies

prosteel1
24 Feb 2021, 17:03 ( Updated at: 21 Dec 2023, 09:22 )

RE:

tekASH said:

Hi guys

I need working insight on following issues:

 

1. How to show/tell the system in the code: market being over a particular Moving Average? Like, price/overall market has crossed over a MA at some point and it is still there.

This is useful for entering short when market is below a MA, and buy only when over the MA. What methods can be used?

2. When I tell the system to buy only if price is over a MA, it keeps opening buy positions repeatedly (after previous position is closed) as long as the price is still over that MA :) But I need one entry, only first, cause keeping buying multiple positions is risky. How to fix this? 

Few issues there, lets address the constant opening of buys first: I wrap my trading code in several conditions: Here is my on trade code that allows me to check if I have a current order or something. I have about 6 levels of these checks which all work together to prevent what you mentioned. It takes about 2 years to work out what is required.

The below prevents opening new orders when orders are already placed on the symbol.

int Longpendingorders = 0;
            int Shortpendingorders = 0;
            var LabelLong = "Long";
            var LabelShort = "Short";

            if (PendingOrders.Count(x => x.Label == LabelLong) > 0)
            {
                foreach (var order in PendingOrders)
                {
                    if (order.SymbolName == SymbolName)
                        Longpendingorders = 1;
                }
            }
            if (PendingOrders.Count(x => x.Label == LabelShort) > 0)
            {
                foreach (var order in PendingOrders)
                {
                    if (order.SymbolName == SymbolName)
                        Shortpendingorders = 1;
                }
            }

For your specific question where you want to only trade once when the price is above the MA, I would create a variable to record a metric and prevent trading within a range of that metric. I see this too and is also something I am trying to fix.

I have had success with this by using the Count of the chart, but have also fount that a chart count might be able to be tried more than once if the entry is different from the first entry, but still testing that tbh.

 


@prosteel1

prosteel1
24 Feb 2021, 17:41

RE: RE:

Does 

 have what your looking for? 


@prosteel1

tekASH
25 Feb 2021, 14:46

RE: RE: RE:

prosteel1 said:

Does 

 have what your looking for? 

This Forum is becoming very commercial. People/affiliates utilizing all means to promote their services.

But all I asked for some insight.


@tekASH