NexusFi: Find Your Edge


Home Menu

 





Disable/Rest Strategy


Discussion in NinjaTrader

Updated
    1. trending_up 2,006 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 5 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
 venichhe 
Brooklyn + New York/USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: NQ, YM, 6E
Posts: 6 since Dec 2017
Thanks Given: 4
Thanks Received: 1

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?


Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
May 26 Deadline Dies at 7.5% as US Strikes Iran During C …
Prediction Markets & Event Contracts
More Than Capable: Hegseths War Warning Validates $114M …
Prediction Markets & Event Contracts
Trump Truth Social Fires Hormuz From 10% to 59% -- Arsen …
Prediction Markets & Event Contracts
White House Drops First Alien Files Today -- Market Says …
Prediction Markets & Event Contracts
The June 15 Resolution Trap: Irans Agreed Text Still Pri …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
NexusFi site changelog and issues/problem reporting
10 thanks
Darmok and Jalad at Tanagra
3 thanks
Big Mike in Ecuador
1 thanks
30 Sessions
1 thanks
  #3 (permalink)
 iantg 
charlotte nc
 
Experience: Advanced
Platform: My Own System
Posts: 409 since Jan 2015
Thanks Given: 91
Thanks Received: 1,154


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

Trade lastTrade = Performance.RealtimeTrades[Performance.RealtimeTrades.Count - 1];
double lastProfit = lastTrade.ProfitCurrency * lastTrade.Quantity;

// 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.


Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #4 (permalink)
 venichhe 
Brooklyn + New York/USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: NQ, YM, 6E
Posts: 6 since Dec 2017
Thanks Given: 4
Thanks Received: 1


iantg View Post
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

Trade lastTrade = Performance.RealtimeTrades[Performance.RealtimeTrades.Count - 1];
double lastProfit = lastTrade.ProfitCurrency * lastTrade.Quantity;

// 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?


Started this thread Reply With Quote
  #5 (permalink)
 iantg 
charlotte nc
 
Experience: Advanced
Platform: My Own System
Posts: 409 since Jan 2015
Thanks Given: 91
Thanks Received: 1,154

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.


Visit my NexusFi Trade Journal Reply With Quote
  #6 (permalink)
 venichhe 
Brooklyn + New York/USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: NQ, YM, 6E
Posts: 6 since Dec 2017
Thanks Given: 4
Thanks Received: 1


iantg View Post
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.

Thank you very much!


Started this thread Reply With Quote




Last Updated on December 13, 2017


© 2026 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 - Downloads - Top
no new posts