Click here to Login





                                                   Getting a Long Trailing stop to use Bid data

  0

0
M808
2016-08-26 02:45:37


Hi QS,

I have loaded trade tick, bid tick and ask tick data into QS.

My long entry signal is based on 5 minute bars. However I want my long exit to be a long trailing stop that trails all changes in the bid price accordingly and fills on the bid price accordingly.

I've been having trouble coding this long trailing stop and would really appreciate a code example.

Thanks.



QuantShare
2016-08-26 06:29:09

  0

Do you want to use this for backtesting or live trading?


M808
2016-08-26 15:04:09

  0

Both backtesting and live trading.


QuantShare
2016-08-27 03:40:12

  0

This cannot be done in backtesting mode. In live/demo/paper trading, you should use the money management script.
In the "OnMarketData" event, you have something like this:

if(MarketData.Type == MarketDataType.Bid)
{
MMPosition pos = Portfolio.GetPosition(MarketData.Symbol, "long");
if(pos != null)
{
if(pos.Var1 is _StopOrder)
{
// Update order
_StopOrder order = pos.Var1 as _StopOrder;
order.Price = MarketData.Price;
order.SubmitChanges();
}
else
{
// Create order
_StopOrder order = Orders.StopOrder(MarketData.Price, -1, 100);
pos.Var1 = order;
pos.ClosePosition(order);
}
}
}



M808
2016-08-27 16:23:43

  0

Thanks. Can this be done in backtesting mode with regular (not trailing) stop losses and take profits?


QuantShare
2016-08-28 05:37:09

  0

I am not sure if I understand correctly your question but for a stop or take profit, just add the appropriate stop in the trading system. You do not need a money management script for that.


M808
2016-09-01 02:51:33

  0

Here is what I mean.

Is there a way in backtesting (and live trade mode) to have my long stoploss (not long trailing stoploss) monitor all changes in the Bid price?

For instance, lets assume I enter a long trade based on a signal from a 10 minute bar and have a 5 cent stoploss. Lets assume I am filled at $101 because at the close of the 10 minute bar that caused my entry the ask price was $101 and the Bid price was $100.99. Lets assume a few seconds later the bid price dropped to 100.95 (while the Ask and last price stayed the same).

Is there a way to have this drop in Bid price trigger my stoploss and have my stoploss fill at 100.95 (in both backtesting and live trading)?



QuantShare
2016-09-01 10:23:20

  0

It can be done only in live trading. Backtesting cannot be done based on bid/ask changes. Only tick data triggers events.

Regarding live mode, yes this can be done. You need to modify the script I have sent you above to do that. If you need more info please contact support by email.



Alexander Horn
2016-12-27 03:55:27

  0

Hi QS,

could you please reveal what is held in the MMPosition Var1 to Var3 and _TradingOrder Var1 Properties? From above it seems _TradingOrder Var1 is the ordertype, but the others? And where do you hold the IB Order reference #, and how to access it?

Another suggestion: In Orders.AddShort/LongPosition we can assign a MMPositionSettings directly when creating the order, for example to assign to custom Category. When creating Child or Linked orders there seems to be no way to assign a MMPositionSettings directly, or am I wrong?




QuantShare
2016-12-27 04:48:22

  0

Nothing is held in the Var1 to Var3. These are variables you can use to store data yourself.

To get Order ID in the "_TradingOrder" object, please use "Status.OrderID" / "Status.RequestID"

And yes there is no way to assign an MMPositionSettings directly when adding an OCA or OSO orders.



No more messages
0




Reply:

No html code. URLs turn into links automatically.

Type in the trading objects you want to include: - Add Objects
To add a trading object in your message, type in the object name, select it and then click on "Add Objects"










QuantShare

Trading Items
Entry Trailing Stop V2
Entry Trailing Stop
Decreasing the Trailing Stop Level every Trading Bar
Conditional Trailing Stop Exit 2013-10-18
Stop Mgmt v 1.1

How-to Lessons
How to use QuantShare with Metastock data
How to download and use U.S. stocks earnings data
How to create a volatility-based Stop - Dynamic stop based on the...
How to display Forex economic calendar data in a chart
How to get fundamental data for U.S. Stocks

Related Forum Threads
Trailing stop value with Intraday data
How can I build up an trailing stop limit buy order
Profit loss protection trailing stop line on chart .
Not getting Data for NSE Stocks
Trailing Stop With Condition

Blog Posts
How to Download and Use Fundamental Data
Statistical data analysis of time series
Backtesting trading strategies using intraday data
Day Trading: A trading system that combines intraday and EOD data
6 places to download historical intraday Forex quotes data for fr...









QuantShare
Product
QuantShare
Features
Create an account
Affiliate Program
Support
Contact Us
Trading Forum
How-to Lessons
Manual
Company
About Us
Privacy
Terms of Use

Copyright © 2024 QuantShare.com
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
Google+
Follow us on Google+
RSS Trading Items



Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.