Put the SL and TP after taking position

Created at 24 Nov 2024, 11:55
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!
FA

fabiennavarrete

Joined 27.10.2024

Put the SL and TP after taking position
24 Nov 2024, 11:55


Hello everyone, I am desperately looking for a solution to put the SL and the TP after the position.
The ideal would be for the SL to be registered randomly between 4 and 10 seconds after the position. For the TP another time slot such as between 11 and 20 seconds for example.
All this in order to imitate as much as possible the human action of a position and a "natural" placement of the SL and the TP.
I tried with ChatGPT but it doesn't work.
If you have a solution, I'm interested. Thanks in advance


@fabiennavarrete
Replies

firemyst
25 Nov 2024, 13:21 ( Updated at: 25 Nov 2024, 14:02 )

Here's the basic logic you'll need to try coding yourself:

Use the Timer object (code samples in the link) :

https://help.ctrader.com/ctrader-algo/references/Timer/Timer/#timertick

Set the interval to 1 second.

Then in the timerTick method, count the number of seconds (essentially each time the event method is called)

When it equals 4, run code to set your SL;

When it equals 10, run code to set your TP.

After both have been set, stop the timer.

 


@firemyst