Click here to Login





                                                   How can I view signals rejected by the simulator?

  0

0
Dave Walton
2013-07-13 07:45:38


I've been working on different position size methods. In the OnNewPosition code of my MM script, I check the available cash of the portfolio and reject the new position if the margin used is more than available. I also store information about rejected positions in various ArrayLists. However, I find that no matter how large I increase the position size, my report continues to say 0 rejected positions even though the number of trades reduces as I increase position size. Clearly the simulator is rejecting signals before my MM script code ever executes. How can I view the signals rejected by the simulator?


QuantShare
2013-07-13 15:21:41

  0

You said: My report continues to say 0 rejected positions

How do you get the number of rejected positions and where are they displayed?



Dave Walton
2013-07-13 15:35:25

  0

Under OnNewPosition:
double margin = (Portfolio.GetAvailableCash("long")) + Portfolio.GetAvailableCash("short");
if(margin > risk)
{
Functions.UpdateNumberOfShares(nbShares);
}
else
{
RejectedSymbols.Add(NewPosition.Symbol);
RejectedNbshares.Add(nbShares);
RejectedPrice.Add(NewPosition.Price);
RejectedMarginA.Add(margin);
Functions.RejectPosition();
}

Under OnEndSimulation:
Functions.AddMetric("# Rejected Positions", RejectedSymbols.Count);
for(int i=0; i < RejectedSymbols.Count;i++)
{
string rs = (string)RejectedSymbols[i];
int rn = (int)RejectedNbshares[i];
double rp = Math.Round((double)RejectedPrice[i],2);
double rm = (double)RejectedMarginA[i];

Functions.AddMetric("Reject Order " + i + ": " + rn + " " + rs + " @ $" + rp + " short by:", (rn * rp) - rm);
}



Dave Walton
2013-07-13 16:48:20

  0

BTW, if I simulate a trading system at 1% risk, the report shows 242 trades. If I increase that to 3% risk, the report only shows 129 trades yet my code indicates 0 rejected positions. Clearly rejections are happening before my code executes.


QuantShare
2013-07-13 20:02:00

  0

Are you entering positions using the MM script or using the strategy formula (QS language) ?
Note that "OnNewPosition" event is not executed when a position is initiated from the MM script.

Also, maybe the "nbShares" variable is depending on the "risk" value (I don't know how you calculate these variables). In that case, increasing the rsik could explain why you get fewer trades (Each trade will get a bigger number of shares).

Last question, where are you initializing the "RejectedSymbols" variable? And how?




Dave Walton
2013-07-13 22:42:23

  0

I am entering positions using a strategy formula. What I think is happening (please confirm) is that positions are rejected by the simulator because I there is not sufficient margin to enter based on the default strategy of Total Equity/ number of positions. The OnNewPositon never executes because there is no position to pass to my code. Is that correct? Ideally what I'd like to do is have a way to set the number of shares to 1 share coming into the MM script and let the script set the correct number of shares. Then My code would pick up the rejects. Is there a way to do this?

Here is the whole script:

OnStartSimulation:
Functions.SetNumericInput("$Risk per Trade", 1000, "Risk per Trade in Dollars");

OnClosePosition:
empty

OnNewPosition:
double risk = (double)Variables.GetVariable("$Risk per Trade");

int nbShares = 0;



if (NewPosition.StopSettings.StopLossOption == 1) // percentage stop used
{
nbShares = (int)Math.Floor(risk / (NewPosition.Price * (NewPosition.StopSettings.StopLoss / 100)));
}
else if (NewPosition.StopSettings.TrailingStopOption == 1) // percentage stop used
{
nbShares = (int)Math.Floor(risk / (NewPosition.Price * (NewPosition.StopSettings.TrailingStop / 100)));
}
else if (NewPosition.StopSettings.StopLossOption == 2) // point stop used
{
nbShares = (int)Math.Floor(risk / NewPosition.StopSettings.StopLoss);
}
else if (NewPosition.StopSettings.TrailingStopOption == 2) // point stop used
{
nbShares = (int)Math.Floor(risk / NewPosition.StopSettings.TrailingStop);
}
else
{
nbShares = (int)Math.Floor(risk / NewPosition.Price);
}

double margin = (Portfolio.GetAvailableCash("long")) + Portfolio.GetAvailableCash("short");
if(margin > risk)
{
Functions.UpdateNumberOfShares(nbShares);
}
else
{
RejectedSymbols.Add(NewPosition.Symbol);
RejectedNbshares.Add(nbShares);
RejectedPrice.Add(NewPosition.Price);
RejectedMarginA.Add(margin);
Functions.RejectPosition();
}

OnEndPeriod:
empty

OnEndSimulation:
Functions.AddMetric("# Rejected Positions", RejectedSymbols.Count);
for(int i=0; i < RejectedSymbols.Count;i++)
{
string rs = (string)RejectedSymbols[i];
int rn = (int)RejectedNbshares[i];
double rp = Math.Round((double)RejectedPrice[i],2);
double rm = (double)RejectedMarginA[i];

Functions.AddMetric("Reject Order " + i + ": " + rn + " " + rs + " @ $" + rp + " short by:", (rn * rp) - rm);
}

Global:
ArrayList RejectedSymbols = new ArrayList(); // array that holds symbol information for rejected positions
ArrayList RejectedNbshares = new ArrayList(); // array that holds number of shares information for rejected positions
ArrayList RejectedPrice = new ArrayList(); // array that holds symbol price information for rejected positions
ArrayList RejectedMarginA = new ArrayList(); // array that holds portfolio margin available at time of rejected positions



QuantShare
2013-07-14 04:25:19

  0

The "OnNewPositon" event should be executed for any valid order initiated by the strategy formula.
I think the ignore list stays empty because the following code always return TRUE:
if(margin > risk)

What is the number of positions allowed for your trading system?
Try increasing it to a very high value (1000 for example). In that case you will get a very low number of shares for each new position.




Dave Walton
2013-07-14 22:42:50

  0

OK I will try that. Just so I understand... But what happens if Total equity / 1000 is not enough to buy 1 share of one of the stocks (like goog)? I assume the simulator would reject a buy signal in that case as not a valid order, right? It seems better to change to allow 10x the number of intended max allowed positions.

But, if I want to limit my number of open positions to 4 simultaneous ultimately-- if I reject any new positions when there are 4 open, will the same positions be chosen as otherwise the simulator would have used, i.e. the top 4 ranked symbols?



QuantShare
2013-07-15 03:07:12

  0

If is just an example, you can put 100 positions if you want.

I do not understand your second question. Please clarify.




Dave Walton
2013-07-16 04:18:38

  0

OK, I made it work. I set my # of positions to 10x my actual intent and increased my percent invested to 1000%. I also had to subtract the values of pending orders from portfolio equity. I then rejected the positions I intended to in my script. I will share it soon.


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
Trading Strategy based on the Number of Buy Signals
How far are the close prices from the support line
The Best trading rules for the ADX technical indicator
Trading Indicator: True between the first and last signal
Number of Times an Event Occurred in the First N-Minutes of a Tra...

How-to Lessons
How to generate buy/sell signals from a trading system
How to dynamically update the settings of an indicator
How to debug a trading system using the money management tool
How to plot the relative performance of several stocks/indices
How to automate the data downloading process

Related Forum Threads
How to view the raw data files?
How do I simulate if then statements for the simulator?
How can I avoid UAE prompts when launching from the QS Task Manag...
How can i download additional data not within the standard time p...
How do I find the close price for an entry matching a custom DB

Blog Posts
Buy the best/top rated stocks or how to create powerful rank base...
How to download the history of dividend payments for stocks in th...
How to Use the Percentage Scale
How to use the new Market Regimes Feature in QuantShare Trading S...
How to measure market strength with the composite tool









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.