Click here to Login

                                                   NewPosition.IsLong working correctly?


2010-10-07 22:34:34

Not sure if I am coding this incorrectly, if I do not understand the NewPosition.IsLong command, or if it is a bug, thought I would post it just to be safe.

Again, I am just trading one symbol with my current code. I wanted to execute both long and short trades and be 100% invested. Thus I originally planned to use the code listed below (I retyped this from memory so hopefully it is free from errors):


if (NewPosition.IsLong == True)
Portfolio.UpdateCategorySettings("long", 100, 1, null);

if (NewPosition.IsLong == False)
Portfolio.UpdateCategorySettings("short", 100, 1, null);

This code worked when going long, I would have 100% of my equity invested in all long trades however it failed to work for any short trade executed. (I had to allow for 2 positions and this originally split my equity 50/50 between long and short trades. With this code my long trades would use 100% of my equity but my short trades would only use 50%)

I checked my outputs with the following code:



The output would return the boolean value of True anytime a new position, regardless of whether it was a short or long position. It is my understanding that NewPosition.IsLong would return a value of True if the new position is a long position and False if it was a Short position. Is this correct?

I successfully changed my script to where I do now have it working as I wish, with 100% invested on both long and short trades. I just thought it was weird the results I had with the above script.

2010-10-08 06:05:32


Best Answer
You are right "NewPosition.IsLong" always returns True.
I have already fixed it. The new version will be available today or tomorrow.

Thanks for reporting this.

No more messages


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"


Trading Items
Analyst comments
Global Market Rotation Strategy V1.1
Metatrader Historical Data Downloader
Advanced Quotes and Custom Databases Function
Convert Seconds to Trading Bars

How-to Lessons
How to speed up watchlist and screener plug-ins when working with...
How to copy and paste drawing tools
How to hide a trading indicator from a particular time frame
How to install the previous version of QuantShare
How to create a correlation matrix of several securities

Related Forum Threads
conditional color not working
Intraday data download is not working
Access intraday data while working on daily chart
Anyone have a working cointegration test, like Johansen?
comp function not working ok in 2.0.2?

Blog Posts
Working with the formula editor
QuantShare Trading Software: New Features in the 3.6.0 Version
6 New Ways to Download Free Intraday Data for the U.S. Stock Mark...
Using Average True Range to Measure Intraday Volatility
QuantShare Programming Language Tutorial

Create an account
Affiliate Program
Contact Us
Trading Forum
How-to Lessons
About Us
Terms of Use

Copyright 2021
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
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.