Topics
Replies
admin
26 Oct 2012, 10:30
Hello,
We need to see the whole logic so that we can further investigate.
It seems that the variables position and pendingorder may not be initialized and remain null.
Are position and pendingorder global?
If so, are you setting the value of position and pendingorder:
protected override void OnPositionOpened(Position openedPosition)
{
position = openedPosition;
}
@admin
admin
25 Oct 2012, 14:27
Yes, but be careful with the method parameter names:
It should be:
protected override void OnPositionOpened (Position openedPosition)
{
if (openedPosition.Volume%InitialVolume == 0)
{
//...
}
//...
}
@admin
admin
23 Oct 2012, 12:15
Error is an Enum type and you can use it to identify which was the error.
For example you can use this statement:
switch (error.Code)
{
case ErrorCode.BadVolume: Print("Bad Volume");
break;
case ErrorCode.TechnicalError:Print("Technical Error");
break;
case ErrorCode.NoMoney: Print("No Money");
break;
case ErrorCode.Disconnected: Print("Disconnected");
break;
case ErrorCode.MarketClosed: Print("Market Closed");
break;
}
If the error is technical then there is a problem with ModifyPosition.
We will add more event handlers very soon, including one to handle the position having been modified. Stay tuned!
@admin
admin
23 Oct 2012, 12:02
Thank you for your suggestions. The server time will include the seconds in one of our future releases. The server time cannot be modified but we will take into consideration adding the local time into the platforms.
For the time being you may code the local time if you like, using Datetime.Now.
@admin
admin
23 Oct 2012, 09:53
Thank you for your suggestions. We will consider them for future development.
In the future please post suggestions in the suggestions Feature requests section of the forum /forum/suggestions
@admin
admin
22 Oct 2012, 15:48
Hello again,
Do you need to differentiate if the closed position volume is a multiple of InitialVolume or a multiple of Volume?
If so, then:
// closedPosition.Volume is a multiple of InitialVolume
if (closedPosition.Volume % InitialVolume == 0) // the remainder of closedPosition.Volume divided by InitialVolume equals zero
{
if (closedPosition.GrossProfit > 0)
{
ExecuteOrder(InitialVolume, closedPosition.TradeType);
}
else
{
ExecuteOrder((int) closedPosition.Volume*2, closedPosition.TradeType);
}
}
else // closedPosition.Volume is a multiple of Volume
{
if (closedPosition.GrossProfit > 0)
{
ExecuteOrder(Volume, closedPosition.TradeType);
}
else
{
ExecuteOrder((int)closedPosition.Volume * 2, closedPosition.TradeType);
}
}
The above code will work if InitialVolume = 10000 and Volume == 1000
If you modify these two variables, i.e. InitialVolume = 2000 and Volume == 1000 then the logic will fail.
If you want to have the flexibility of adjusting the volume parameter to any value then I suggest using two different robots.
@admin
admin
22 Oct 2012, 14:39
Hello again,
I think there was a misunderstanding here or maybe I used the wrong words. What I meant was that this feature is in our list for future development and that it will be available but it will not be available in the next update. I hope this clarifies the above statement.
As far as the platform, we are working very hard to improve it and we are taking user feedback into serious consideration. There have been quite a few updates recently and a few exciting features are comming in the next update. We are constantly making it better and I'm sure that you will not have to wait long before this is your favourite platform. Stay tuned!
@admin
admin
22 Oct 2012, 11:53
Hello tradematrix,
Glad to hear that the take profit and stop loss implementation was successful previously.
Now, about this issue. Is it possible to explain what you need the robot to do OnPositionClosed? Because from what I see your question is about the logic of your algorithm not about the syntax or any errors you are receiving. So, in order to be able to help you I need to know what you want to accomplish which is not clear from the code above.
By the way, if this is related with a solution in another previously posted thread please continue on that thread or post the solution here.
Best Regards
@admin
admin
19 Oct 2012, 13:20
You can define as many parameters as you like but you have to make sure to reference them by their unique name.
The stop loss and take profit are not passed in to the ExecuteOrder function. Only volume and trade type.
ExecuteOrder(InitialVolume, TradeType.Sell);
ExecuteOrder(Volume, TradeType.Sell);
Trade.ModifyPosition is the method that modifies stop loss and take profit. Therefore OnPositionOpened is what needs to be modified.
You probably need to have an if statement to check the volume of the position.
protected override void OnPositionOpened(Position openedPosition) { if (openedPosition.Volume == InitialVolume) { if (openedPosition.TradeType == TradeType.Buy) Trade.ModifyPosition(openedPosition, Symbol.Ask - StopLoss*Symbol.PipSize, Symbol.Ask + TakeProfit*Symbol.PipSize); else if (openedPosition.TradeType == TradeType.Sell) Trade.ModifyPosition(openedPosition, Symbol.Bid + StopLoss*Symbol.PipSize, Symbol.Bid - TakeProfit*Symbol.PipSize); } else { if (openedPosition.TradeType == TradeType.Buy) Trade.ModifyPosition(openedPosition, Symbol.Ask - stoplossInPips * Symbol.PipSize, Symbol.Ask + takeprofitInPips * Symbol.PipSize); else if (openedPosition.TradeType == TradeType.Sell) Trade.ModifyPosition(openedPosition, Symbol.Bid + stoplossInPips * Symbol.PipSize, Symbol.Bid - takeprofitInPips * Symbol.PipSize); } position = openedPosition; }
@admin
admin
19 Oct 2012, 12:12
In the sample robots (e.g. SampleBuyTrailing, SampleBreakoutRobot) StopLoss is defined as an int (integer) and refers to the number of pips and is used then in an equation that translates the number of pips to the amount equivalent to those pips.
Please take a look at the sample robots that ship with cAlgo as well as sample examples and documentation for more help on setting StopLoss:
/forum/calgo-reference-samples/69
/docs/reference/calgo/api/internals/itrade/modifyposition
If the above does not help, please post the code where you set the StopLoss.
@admin
admin
26 Oct 2012, 11:15
At the moment you may modify the pending order like so:
Trade.ModifyPendingOrder(pendingorder, stopLoss, takeProfit, expirationTime);
We are working on overloading the method in order to allow the modification of the targe price.
@admin