Can I modify the order which created by cTrader?

Created at 20 Jan 2013, 19:24
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!
HE

henry

Joined 20.04.2012

Can I modify the order which created by cTrader?
20 Jan 2013, 19:24


Hi,

When I trade in cTrader, I can see the order in  cAigo window, it updates realtime., I can modify this orader in manual also.

The question is how can I modity the order in programming. I tried, the system shows it can't find this order at all, the position is null.

Can I modify the order which created by cTrader?


Best regurads.

Henry

 

 


@henry
Replies

admin
21 Jan 2013, 10:56

Currently, you can loop through the positions in the account and check for the conditions of that specific position. Please look at this example.

Your condition may be that the position's entry time is less than 10 seconds, or you may identify it by the symbol code or volume or a combination of all those. 

foreach (var position in Account.Positions)
{
    // Position was opened less than 10 seconds ago
    if (position.EntryTime < DateTime.Now.AddSeconds(-10))
    {
        Trade.ModifyPosition(position, stopLoss, takeProfit);
    }
}

@admin

henry
24 Jan 2013, 04:00

I have tried it.  The result is,

If the position is created by cAigo, it workes.

If the position is created bt cTrader(same acct.), it does not work.

So, I  tried another one from your sample. The result is th same.

using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.Indicators;


namespace cAlgo.Robots
{
    [Robot]
    public class Mytest : Robot
    {privatePosition position;protectedoverridevoidOnStart(){
 //   Trade.CreateBuyMarketOrder(Symbol,10000);  // this step use cTrader instead.}protectedoverridevoidOnTick(){if(position !=null){Print("The current position's profit is: {0}", position.GrossProfit);Print("The current position's gross profit is: {0}", position.GrossProfit);Print("The current position's Commissions are: {0}", position.Commissions);Print("The current position's TakeProfit is: {0}", position.TakeProfit);Print("The current position's stoploss is: {0}", position.StopLoss);Print("The current position's entryprice is: {0}", position.EntryPrice);Print("The current position's id is: {0}", position.Id);Print("The current position's netprofit is: {0}", position.NetProfit);
      //  Print("The current position's profit is: {0}", position.Profit);Print("The current position's swap is: {0}", position.Swap);Print("The current position's symbolcode is: {0}", position.SymbolCode);Print("The current position's Tradetype is: {0}", position.TradeType);Print("The current position's volume is: {0}", position.Volume);}}protectedoverridevoidOnPositionOpened(Position openedPosition){
   position = openedPosition;}}

 


@henry

henry
24 Jan 2013, 04:16

RE:

Sorry, the format is not good above. The samples is from

/api/position

 

The diffrence is the position is  NOT created  by robot. It was created by manual.


@henry

admin
24 Jan 2013, 12:35

Please use the code in this sample and let us know if it does not function properly. If it does then it is probably something else in the code that is not functioning as intended.
The code in your previous post does not modify any orders. You need this statement in order to modify orders Trade.ModifyPosition. See ModifyPosition in the API reference.


@admin

henry
24 Jan 2013, 17:14

Excellent Job! Thank you very much. It workes now.

You are right, the position has 10 seconds delay. 


@henry