NexusFi: Find Your Edge


Home Menu

 





Have problem with trailing stop


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one kissdish with 3 posts (1 thanks)
    2. looks_two Quick Summary with 1 posts (0 thanks)
    3. looks_3 ABCTG with 1 posts (1 thanks)
    4. looks_4 Jura with 1 posts (0 thanks)
    1. trending_up 3,176 views
    2. thumb_up 2 thanks given
    3. group 2 followers
    1. forum 5 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
kissdish
nanjing china
 
Posts: 3 since Jul 2015
Thanks Given: 0
Thanks Received: 1

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.


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Iran Airspace Collapses 18 Points to 15.5% While Hormuz …
Prediction Markets & Event Contracts
El Clasico Draws $9.2M in Prediction Market Action -- Bi …
Prediction Markets & Event Contracts
Iran Airspace Contract Surges to 33.5% as Project Freedo …
Prediction Markets & Event Contracts
Iran Lebanon Problem Kills Switzerland Talks, Brent at $ …
Prediction Markets & Event Contracts
Hungary Called for Magyar at 97pct, Ending 16-Year Orban …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Big Mike in Ecuador
197 thanks
Sober Journey With S&P
27 thanks
30 Sessions
20 thanks
Volume Indicators
8 thanks
BERN ALGOS algo trading journal
8 thanks
  #3 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,448 since Apr 2013
Thanks Given: 494
Thanks Received: 1,642


kissdish,

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.

Regards,
ABCTG


Follow me on X Reply With Quote
Thanked by:
  #4 (permalink)
kissdish
nanjing china
 
Posts: 3 since Jul 2015
Thanks Given: 0
Thanks Received: 1

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?


Reply With Quote
  #5 (permalink)
 
Jura's Avatar
 Jura   is a Vendor
 
Posts: 775 since Apr 2010
Thanks Given: 2,352
Thanks Received: 691


kissdish View Post
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.

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.


kissdish View Post
does anyone know that if i want to write a custom trailing stop, what function or command is the standard method, setstoploss?

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.


Reply With Quote
  #6 (permalink)
kissdish
nanjing china
 
Posts: 3 since Jul 2015
Thanks Given: 0
Thanks Received: 1

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


Reply With Quote
Thanked by:




Last Updated on August 14, 2015


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts