Topics
Replies
ryanoia@gmail.com
20 Aug 2018, 07:00
( Updated at: 21 Dec 2023, 09:20 )
Perhaps my query is complicated. Need to simplify the code. Here's the code:
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo.Robots { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class AutoTPforNukedPositions : Robot { [Parameter("No Nuke TP", DefaultValue = "11")] public double NoNukeTP { get; set; } [Parameter("No Nuke Volume", DefaultValue = "20000")] public double NoNukeVolume { get; set; } protected override void OnStart() { // Put your initialization logic here } protected override void OnTick() { foreach (var position in Positions) { if (position.TradeType == TradeType.Buy && position.TakeProfit != position.EntryPrice + NoNukeTP * Symbol.PipSize && position.VolumeInUnits == NoNukeVolume) { var takeprofit = position.EntryPrice + NoNukeTP * Symbol.PipSize; ModifyPositionAsync(position, null, takeprofit); } if (position.TradeType == TradeType.Sell && position.TakeProfit != position.EntryPrice - NoNukeTP * Symbol.PipSize && position.VolumeInUnits == NoNukeVolume) { var takeprofit = position.EntryPrice - NoNukeTP * Symbol.PipSize; ModifyPositionAsync(position, null, takeprofit); } // No Nuke } // Put your core logic here } protected override void OnStop() { // Put your deinitialization logic here } } }
As previously stated, this is the error:
Error Message says
"Order Execution
Nothing to Change"
---------
This bot changes TP of any position (long or short) to 11, but the conditions for this bot to execute are:
- the volume of the position should be 20K; and
- the TP of such position is not equal to 11
However, what happens is, it finds a position with such volume BUT with same TP of 11, AND still it tries to change its TP to 11. However, since the TP was already 11 to begin with, it returns an error - "nothing to change". Then it repeats the process over and over again.
This is what the error looks like:
The question is, why would the bot request to amend the TP of this position when its TP is already 11?
@ryanoia@gmail.com
ryanoia@gmail.com
17 Aug 2018, 10:26
No need to answer that, just found the answer myself. Answer is, not all commands have an async counterpart.
Thanks.
@ryanoia@gmail.com
ryanoia@gmail.com
17 Aug 2018, 10:15
or even notifications.sendemail i.e. notifiactions.sendemailasync
@ryanoia@gmail.com
ryanoia@gmail.com
17 Aug 2018, 10:14
Thanks for the quick response.
Just for clarification, every command (not sure if I labeled this correctly) can be async, like modifyposition, etc.
@ryanoia@gmail.com
ryanoia@gmail.com
17 Aug 2018, 10:00
Thanks.
As a way of contributing to the community, this also worked too:
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo.Robots { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class HolyGrailAllPairs : Robot { [Parameter("Volume", DefaultValue = 1000, MinValue = 1, Step = 1)] public int Volume { get; set; } public enum ConsideredPairs { NZDCAD, NZDJPY, NZDUSD } protected override void OnStart() { foreach (string singlePair in Enum.GetNames(typeof(ConsideredPairs))) { Symbol Symbol = MarketData.GetSymbol(singlePair); ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "order 1", null, 11, null); ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, "order 1", null, 11, null); PlaceStopOrder(TradeType.Buy, Symbol, Volume, Symbol.Ask + 16 * Symbol.PipSize, "myStopOrder", null, 11, null); PlaceStopOrder(TradeType.Sell, Symbol, Volume, Symbol.Bid - 16 * Symbol.PipSize, "myStopOrder", null, 11, null); } } protected override void OnTick() { // Put your core logic here } protected override void OnStop() { // Put your deinitialization logic here } } }
I hope my 2 other queries get answered.
By the way, since we're talking, what is the difference between executemarketorderasync and executemarketorder only? is one better than the other?
My understanding is, if it's executemarketorder, this needs to be processed first before the bot proceeds to execute the next line in command. If it's executemarketorderasync, then everything executes independent of one another. Is my understanding on point?
@ryanoia@gmail.com
ryanoia@gmail.com
16 Aug 2018, 19:51
Open buy and sell and stop orders in all symbols, not just one
This is the code for one pair:
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo.Robots { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class OpenPositions : Robot { [Parameter("Volume", DefaultValue = 1000, MinValue = 1, Step = 1)] public int Volume { get; set; } protected override void OnStart() { ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "order 1", null, 11, null); ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, "order 1", null, 11, null); PlaceStopOrder(TradeType.Buy, Symbol, Volume, Symbol.Ask + 16 * Symbol.PipSize, "myStopOrder", null, 11, null); PlaceStopOrder(TradeType.Sell, Symbol, Volume, Symbol.Bid - 16 * Symbol.PipSize, "myStopOrder", null, 11, null); // Put your initialization logic here } protected override void OnTick() { // Put your core logic here } protected override void OnStop() { // Put your deinitialization logic here } } }
How can I do this for multiple selected pairs?
@ryanoia@gmail.com
ryanoia@gmail.com
16 Aug 2018, 19:31
Open buy and sell and stop orders in all symbols, not just one
In particular, I can do this with one pair:
ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "order 1", null, 11, null);
ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, "order 1", null, 11, null);
PlaceStopOrder(TradeType.Buy, Symbol, Volume, Symbol.Ask + 16 * Symbol.PipSize, "myStopOrder", null, 11, null);
PlaceStopOrder(TradeType.Sell, Symbol, Volume, Symbol.Bid - 16 * Symbol.PipSize, "myStopOrder", null, 11, null);
How do I do that with multiple pairs?
@ryanoia@gmail.com
ryanoia@gmail.com
20 Aug 2018, 07:22
Never mind. Just use "" in place of label.
@ryanoia@gmail.com