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 Jura with 1 posts (0 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 ABCTG with 1 posts (1 thanks)
    1. trending_up 2,176 views
    2. thumb_up 2 thanks given
    3. group 2 followers
    1. forum 5 posts
    2. attach_file 0 attachments




 
Search this Thread

Have problem with trailing stop

  #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?
What broker to use for trading palladium futures
Commodities
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Cheap historycal L1 data for stocks
Stocks and ETFs
How to apply profiles
Traders Hideout
ZombieSqueeze
Platforms and Indicators
 
  #3 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629


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 Twitter 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: 690


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


© 2024 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 - Privacy Policy - Downloads - Top
no new posts