Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- discounts are available after registering.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
I want to write a custom trailing stop, the code snippets like this
if MarketPosition <> 0 then
begin
tStopLoss = VerifyStopLoss(value4, AvgValue, OrderSlot, BuyOrSell, LogLevel);
if tStopLoss <> 0 then
begin
value4 = tStopLoss;
end;
if BuyOrSell <> 0 then
begin
sell next bar at value4 stop;
end
else
begin
buytocover next bar at value4 stop;
end;
end;
the VerifyStopLoss function will caculate the new stop price and i know it work correctly, now the problem is that no any stop order will be submitted while the sa model is turned on, i dont know why.
Can you help answer these questions from other members on NexusFi?
it's hard for anyone to guess what could be the problem without being able to check the values from the function. You should add print commands to your code and check the values yourself to see if they are correct. This will help you to track the issue down.
thank you for your reply, i have checked the function and ensure it will return correct value, now i wondered is there anything wrong i use the sell and buytocover command, as no any stop order be submitted. does anyone know that if i want to write a custom trailing stop, what function or command is the standard method, setstoploss?
Do you have an open position when this script is applied to the chart? That's all I can guess based on the information you've provided.
The code snippet that you showed already is a custom stop; you only need to make it trailing. If you implement SetDollarTrailing() then it won't be custom anymore.
thanks for your replay, i have solved this problem, the reason is the marketpostion will always return 0 while the SA is turned on, it's incorrect, maybe some bug with the broker's plug-in, i change a broker or use marketpostion_at_broker and the code run well. thank you all