Topics

Forum Topics not found

Replies

cAlgo_Fanatic
29 May 2013, 15:00

"When the long position exit is triggered with the condition (Buyexit) the short position also closes...I couldn't work out how to refer to the trades by the labels".
Do you mean that all positions long and short will close under the specified label?

If so, the code should be:

            if (Buyexit)
                foreach (var position in Account.Positions)
                {
                    if (position.Label == Label) // will close all positions of the account under this Label
                    {
                        Print("Profit Exit");
                        Trade.Close(position);
                    }
                }

Where Label may be an input parameter or constant field.


Note:
In the code snippets you provided making the distinction between postition and _position, the second code snippet is incorrect. It is assumed that _position is a field. A field holding a Position object is usually used when the program has only one position open at a time. This field is set at OnPositionOpened and is reset (null) at OnPositionClosed. 
In case you want to handle more than one positions with your robot you would use a List like in this List example.
In case you want to handle all positions of the account you would use the Account.Positions list like in the above code snippet.
Therefore, if you use a foreach statement to loop through all positions in the account you refer to the variable declared in the foreach statement, in this case "position" and you may give this variable whichever name you like, i.e. foreach(var pos in Account.Positions){...}. Then within the body of the foreach statement (inside the curly brackets) you will refer to this variable: 

 

            foreach(var pos in Account.Positions)
            {
                if (pos.Label == Label)
                {
                    //...
                }
            }




@cAlgo_Fanatic

cAlgo_Fanatic
27 May 2013, 17:38

You can use:

MarketSeries.OpenTime.LastValue


See MarketSeries.OpenTime


@cAlgo_Fanatic

cAlgo_Fanatic
27 May 2013, 17:35

Adjust the ScalePrecission on the indicator attribure and let us know if this is what you need.

[Indicator(IsOverlay = false, ScalePrecision = 5)]




@cAlgo_Fanatic

cAlgo_Fanatic
27 May 2013, 17:31 ( Updated at: 21 Dec 2023, 09:20 )

You can see the Daily Change in the MarketWatch window of cTrader.

 


@cAlgo_Fanatic

cAlgo_Fanatic
27 May 2013, 13:00

We will consider this. Thank you for the suggestion.


@cAlgo_Fanatic

cAlgo_Fanatic
27 May 2013, 12:53

    private FibGrid7Chart FibGrid7ChartIndicator;

    protected override void Initialize()
    {
        FibGrid7ChartIndicator = Indicators.GetIndicator<FibGrid7Chart>(55, 21);
        // ...                        
    }
    public override void Calculate(int index)
    {
        if (!IsRealTime) return;

        bool condition = _simpleMovingAverage7.Result[index] <= FibGrid7ChartIndicator.UpperBand3[index]
                        || _simpleMovingAverage7.Result[index] <= FibGrid7ChartIndicator.LowerBand3[index];

        for (int i = index - 10; i <= index; i++)
        {
            Result[i] = _simpleMovingAverage1.Result[index];
            //...
            Result6[i] = _simpleMovingAverage6.Result[index];

            if (condition)
                Result7[i] = _simpleMovingAverage7.Result[index];

        }
        // ...

 


@cAlgo_Fanatic

cAlgo_Fanatic
27 May 2013, 12:22

Correct, you would need to differentiate between the trigger for one and the other, therefore two different boolean variables for isTriggered.

Like:

                    if (distance >= trigger*Symbol.PipSize)
                    {

                        if (!_isTrigerred1 && trigger == Trigger1)
                        {
                            _isTrigerred1 = true;
                            Print("Trailing Stop Loss triggered...");
                        }
                        else if (!_isTrigerred2 && trigger == Trigger2)
                        {
                            _isTrigerred2 = true;
                            Print("Trailing Stop Loss triggered...");
                        }


isTriggered1 and isTriggered2 would be fields (declared in the outer scope) initialized to false.


@cAlgo_Fanatic

cAlgo_Fanatic
27 May 2013, 12:01

Well, the syntax for the property is correct, even though a little redundant. It will just return the value of Mode.

You could write a property like this instead:

        protected bool LongOnly
        {
            get { return Mode == 0; }
        }

 

 

 


@cAlgo_Fanatic

cAlgo_Fanatic
27 May 2013, 11:19

This bug was fixed. Let us know if there are any other issues.


@cAlgo_Fanatic

cAlgo_Fanatic
24 May 2013, 14:21

Yes, there will be in the future.

The program is ready and you don't need to do any programming just download and build it in cAlgo.

Moving Average with Shift

To add a downloaded indicator to your cTrader platform, follow the steps below:

 

  1. Download or move the Indicator to My Documents > cAlgo > Sources > Indicators.
  2. Open the cAlgo platform. If you don't already have it, you can download cAlgo from your broker's website (or download here if you're just using the demo from Spotware.com)
  3. Click on the Indicators tab from the Robots/Indicators menu on the left.
  4. Find the Indicator you want to use.
  5. Click the Build icon Build. If the build is successful, the icon appearance will change to Successful build

 

The Indicator will now be available in your cTrader platform.

 


@cAlgo_Fanatic

cAlgo_Fanatic
24 May 2013, 12:52

Parabolic SAR is already included. We will add more indicators in the platform in the future.


@cAlgo_Fanatic

cAlgo_Fanatic
24 May 2013, 12:17

You can use an integer (int) Value 0 for Long and 1 for Short for example and set the Min/Max Values.

        [Parameter("0-Buy, 1-Sell", DefaultValue = 0, MinValue = 0, MaxValue = 1)]
        public int Mode { get; set; }



 


@cAlgo_Fanatic

cAlgo_Fanatic
23 May 2013, 14:43

If the Notification is in the OnPositionClosed() event the balance is updated correctly. If you add the Notification after the Trade.Close() then the email will probably be sent before the position is closed. 


@cAlgo_Fanatic

cAlgo_Fanatic
23 May 2013, 12:46

Trailing Stops will be released in approximately one month. For the time being there is a Sample Trailing Stop Robot included in cAlgo which you can use to trail positions by their ID.

Stop Loss is already entered in pips not fixed price.

We will consider the last request. You can however disable Gross and Net EUR columns (profit) by right clicking in the columns in tradewatch and selecting the ones you want to see.


@cAlgo_Fanatic

cAlgo_Fanatic
23 May 2013, 09:23

In cAlgo click on New in the Robots list. A new code file will be created in the text editor with some initial code.  You need to copy and paste the code provided in the second post in the OnTick method where it says:

        protected override void OnTick()
        {
            // Put your core logic here
        }

Paste the code within the curly brackets {}.

Please see these help pages to get started:

http://help.spotware.com/calgo

http://help.spotware.com/calgo/cbots/create-edit

http://help.spotware.com/calgo/videos


@cAlgo_Fanatic

cAlgo_Fanatic
22 May 2013, 17:45

Thank you for the suggestion. It may be included in the future.


@cAlgo_Fanatic

cAlgo_Fanatic
22 May 2013, 17:43

To combine the above code, place the first in the OnTick event of the second.


@cAlgo_Fanatic

cAlgo_Fanatic
22 May 2013, 17:41

RE:
tasr1r1 said:

thanks... but i must admit im learning the coding from scratch and cant figure out the error

 

would be great if somebody dont mind to give full coding for the above as start

You can post the error message and we will help you out with the code.


@cAlgo_Fanatic

cAlgo_Fanatic
22 May 2013, 17:21

Notifications cannot be disabled currently. It may be implemented in the future.


@cAlgo_Fanatic

cAlgo_Fanatic
22 May 2013, 15:38

ChartObjects are not supported on the backtesting chart for the time being. It will be implemented in the future.


@cAlgo_Fanatic