Put the SL and TP after taking position
Created at 24 Nov 2024, 11:55
FA
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
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