Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
I have searched for the life cycle of NinjaScript for NT7 but I wasn't able to find it. I have a strategy that I don't want to over trade, so I will be enabling my strategy and it will activate an ATMStrategy. For now what I have
private bool tradeAgain = true;
protected override void OnBarUpdate()
{
if(tradeAgain)
{
// programming logic
}
tradeAgain = false;
}
After the trade, whether its profit or loss, I want to be able to make the variable tradeAgain = true.
I am wondering if I disable the strategy, and then enable it again, will variable tradeAgain be true or false?
Can you help answer these questions from other members on NexusFi?
If you want to trade or not trade based on if your last trade was a profit or not you will need something like this.
// In order to run this, you have to call the method below to check and make sure there is at least one trade in the
// collection otherwise it will just error out.
if (Performance.RealtimeTrades.Count > 1)
{
// get variables to hold information about the last trade
// Run condition to check if the last trade was profitable or not
if(lastProfit > 0)
{
// last trade was a winner do something
}
if (lastProfit <0)
{
// last trade was a loser do something
}
}
In terms of disabling or enabling your strategy, you can do something inside of the code blocks I have provided. There are a number of easy way to tell it to trade or not trade.
Thanks. Will this be for each script or will it take into account all the trades? I need it to run separately on each script. And if lastprofit > 0, simple return will suffice?
The way the code works it is only looking at the last trade.
The variable lastTrade is indexed to -1 which means it will always look at the last trade. You can add a new variable called twotradesago and index it to -2, and do threetradesago with -3, etc. Each of these would be a different trade variable and you would have to extract the p&l stats the same way.
VariableName.ProfitCurrency for example. But I think if all you are looking for is the last trade then go with the -1 index and you have it.