For the TP, my bot is managing multiple position at the same time, I have to change the TP when the position is opened. So the only option I was thinking about is to store in LocalStorage the TargetPrice for every position and then calculate manually the TP and modify it. Is it my only way?
About the Stop Limit order entry, you say that the spread is irrelevant but on some US30 position yesterday I was not filled and I was thinking of the spread.
Let s say that the spread is 3 and I set a Long Stop Limit with a TargetPrice at 100 and a range at 2, is it possible to be filled?
The spread is irrelevant to the stop limit price. If you set a buy order at 100 and the range at 2, then what you are asking is the slippage not to exceed 2. Therefore the worst executed price will be 102 and only the volume that can fulfill this requirement will be filled. The spread is irrelevant, the bid price can be at 99 or 50.
Regarding TP, it can only be set in relative pips at the moment. If you need to set an exact price, you would have to modify the opened position.
Many people think that stop limit orders somehow improve execution and magically eliminate slippage. They don't. They only thing a stop limit order does is that it does not execute the part of the order that falls beyond the slippage you can tolerate. This is what happens in your case. The stop limit order did what you instructed it to do. It did not execute the order because it could not meet your slippage criteria. If you want your orders to be executed, just use market orders.
What's the spread on your US30 when you place the order?
On a few brokers, the spread is larger than the 2-point SL you set.
If you're doing this in a bot or indicator, you need to check the spread before placing your order. It's not a guarantee since the spread could hypothetically change at any given moment, but it's a good safety check
sebastien.t
02 Oct 2024, 08:31
( Updated at: 02 Oct 2024, 09:23 )
RE: Get the EntryPrice of a PlaceStopLimitOrder
Thank you for you answer. I want to get it from the Position itself when it is successful. I want to store it in Local storage before the execution to be able to monitor the slippage.
My broker is ICMarkets and here is the simple code, I just put an order. It could be anything a Market order or a stop order, i have always the Failure message.
My broker is ICMarkets and here is the simple code, I just put an order. It could be anything a Market order or a stop order, i have always the Failure message.
RE: RE: RE: Placing Stop Order - FAILED with error "TechnicalError"
My broker is ICMarkets and here is the simple code, I just put an order. It could be anything a Market order or a stop order, i have always the Failure message.
I think there is also a huge issue on the lot calculation on the FOREX. I tried the function on GBPUSD
For an account of $1.000.000 and 10 pips Stop Loss, the function Symbol.VolumeForProportionalRisk proposed me to buy 2.500.00 lots which is by far too much…
But when I trued to reverse it with the function Symbol.AmountRisked, it says that I risk $2.500 which is the right number because my risk is 0.25% of the balance.
But obviously, it is not the risk that I have for 2.500.000 lots with a 10pips Stop Loss.
I can't even put a trade with that figures…
Is it also a but? When do you expect to fix it?
Thank you
protected override void OnStart()
{
Print("Symbol "+ Symbol.Name);
Print("Pip size "+Symbol.PipSize);
Print("Account Balance " + Account.Balance);
Print("Volume to risk for SL 10pips " + Symbol.VolumeForProportionalRisk( ProportionalAmountType.Balance, RiskPerTrade, 10));
Print("Amount risked for Volume 2 500 000 with SL 10pips " + Symbol.AmountRisked(Symbol.VolumeForProportionalRisk( ProportionalAmountType.Balance, RiskPerTrade, 10), 10));
I tried to use your workaround but it doesn't really work for 2 reasons :
1/ if I want to backtest the bot that I use on Live market I can't change a lot of code and so I have to keep using the same functions. It seems that even if the history date are loaded (I can see see it if I check the date with Bars[0]), I can't recall that data with the MarketData.GetBars
2/ To run the Backtest I have to choose 1 timeframe (let s say H1) but in my bot I need check the historical data of the H4 and the Daily. And so even if I start the backtest to beofre my “real” backtesting date to load the data, it loads only the data for H1 and not for H4/Daily.
Here is my code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo.Robots
{
[Robot(AccessRights = AccessRights.None)]
public class EasyHistoLoad : Robot
{
[Parameter("Backtest On/Off", Group = "BackTest", DefaultValue = false)]
public bool BackTest { get; set; }
[Parameter("Backtest Date", Group = "BackTest", DefaultValue = "2024/03/01 01:00:00")]
public string BackTestDate { get; set; }
protected override void OnStart()
{
// To learn more about cTrader Automate visit our Help Center:
The idea of my code/bot is to check some data in the past for the H4 to know if I am bullish or bearish and the to deep dive in the 1 minute chart.
Basically I have to go 60 bars on the timeframe and then go to the m1. Let s say I want to backtest from the 1st february, I check the H4 10 days before (60*4/24), that should be around mid of January and then I check some data on that date on the m1.
So most of the time I need to LoadMoreHistory on the m1.
while (_OfTimeFrameBars.OpenTimes[0] > time_to_test){ var numberOfLoadedBars = _OfTimeFrameBars.LoadMoreHistory();
LoadMoreHistory does not work in backtesting therefore your code enters an infinite loop.
Best regards,
Panagiotis
Hi Seb,
The workaround I use is to start the backtesting at earlier dates so that all the necessary information is loaded, while skipping all trading operations until a custom defined date. So I have a set of parameters like this
which replace the backtesting start date and I move my backtesting start date as far in the past as I want.
Best regards,
Panagiotis
Hi Seb,
I did not understand what the problem is here, sorry
You should retrieve the data on start, before the if condition. That's the whole point of the workaround
protected override void OnStart() { // To learn more about cTrader Automate visit our Help Center: // https://help.ctrader.com/ctrader-automate // Print(Bars.Count()); DateTime time_to_test = Bars[Bars.Count() - 5].OpenTime.AddDays(-15); Bars _OfTimeFrameBars = MarketData.GetBars(TimeFrame.Minute, SymbolName); Print("Bars[0].OpenTime " + Bars[0].OpenTime + " _OfTimeFrameBars.OpenTimes[0] " + _OfTimeFrameBars.OpenTimes[0] + " time_to_test " + time_to_test); // Print(time_to_test); // Get m1 Bars if (BackTest && Bars.Last().OpenTime > DateTime.Parse(BackTestDate)) { var LastOpenTimeLoaded = _OfTimeFrameBars.OpenTimes[0]; if (_OfTimeFrameBars.OpenTimes[0] > time_to_test) { Print("_OfTimeFrameBars is not using Bars history already loaded"); } } }
I tried to use your workaround but it doesn't really work for 2 reasons :
1/ if I want to backtest the bot that I use on Live market I can't change a lot of code and so I have to keep using the same functions. It seems that even if the history date are loaded (I can see see it if I check the date with Bars[0]), I can't recall that data with the MarketData.GetBars
2/ To run the Backtest I have to choose 1 timeframe (let s say H1) but in my bot I need check the historical data of the H4 and the Daily. And so even if I start the backtest to beofre my “real” backtesting date to load the data, it loads only the data for H1 and not for H4/Daily.
Here is my code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo.Robots
{
[Robot(AccessRights = AccessRights.None)]
public class EasyHistoLoad : Robot
{
[Parameter("Backtest On/Off", Group = "BackTest", DefaultValue = false)]
public bool BackTest { get; set; }
[Parameter("Backtest Date", Group = "BackTest", DefaultValue = "2024/03/01 01:00:00")]
public string BackTestDate { get; set; }
protected override void OnStart()
{
// To learn more about cTrader Automate visit our Help Center:
The idea of my code/bot is to check some data in the past for the H4 to know if I am bullish or bearish and the to deep dive in the 1 minute chart.
Basically I have to go 60 bars on the timeframe and then go to the m1. Let s say I want to backtest from the 1st february, I check the H4 10 days before (60*4/24), that should be around mid of January and then I check some data on that date on the m1.
So most of the time I need to LoadMoreHistory on the m1.
while (_OfTimeFrameBars.OpenTimes[0] > time_to_test){ var numberOfLoadedBars = _OfTimeFrameBars.LoadMoreHistory();
LoadMoreHistory does not work in backtesting therefore your code enters an infinite loop.
Best regards,
Panagiotis
Hi Seb,
The workaround I use is to start the backtesting at earlier dates so that all the necessary information is loaded, while skipping all trading operations until a custom defined date. So I have a set of parameters like this
which replace the backtesting start date and I move my backtesting start date as far in the past as I want.
sebastien.t
04 Oct 2024, 08:45
RE: Stop Limit Order and Spread
Hi there,
thank you for your answer.
For the TP, my bot is managing multiple position at the same time, I have to change the TP when the position is opened. So the only option I was thinking about is to store in LocalStorage the TargetPrice for every position and then calculate manually the TP and modify it. Is it my only way?
About the Stop Limit order entry, you say that the spread is irrelevant but on some US30 position yesterday I was not filled and I was thinking of the spread.
Let s say that the spread is 3 and I set a Long Stop Limit with a TargetPrice at 100 and a range at 2, is it possible to be filled?
Thank you
PanagiotisCharalampous said:
@sebastien.t